Exemplo n.º 1
0
        /// <summary>
        /// Обновление дерева на основе текущих устройств проекта.
        /// </summary>
        /// <param name="deviceManager">Менеджер устройств проекта.</param>
        /// <param name="checkedDev">Выбранные устройства.</param>
        private void Refresh(Device.DeviceManager deviceManager,
                             string checkedDev)
        {
            devicesTreeViewAdv.BeginUpdate();

            devicesTreeViewAdv.Model = null;
            devicesTreeViewAdv.Refresh();
            var treeModel = new TreeModel();

            string mainNodeName = "Устройства проекта";
            var    root         = new Node(mainNodeName);

            treeModel.Nodes.Add(root);

            // Подтипы, которые отдельно записываем в устройства
            var devicesSubTypesEnum = new string[]
            {
                "AI_VIRT",
                "AO_VIRT",
                "DI_VIRT",
                "DO_VIRT"
            };

            object[] devicesArray = GenerateArrayObjectsForFill(
                devicesSubTypesEnum);
            FillMainDevicesInNode(root, devicesArray);

            Dictionary <string, int> countDev = MakeDevicesCounterDictionary(
                root.Nodes);

            foreach (Device.IODevice dev in deviceManager.Devices)
            {
                string deviceDescription = GenerateDeviceDescription(dev);
                string devSubType        = dev.GetDeviceSubTypeStr(dev.DeviceType,
                                                                   dev.DeviceSubType);
                if (devicesSubTypesEnum.Contains(devSubType))
                {
                    FillSubTypeNode(dev, root, deviceDescription, countDev);
                }
                else
                {
                    FillTypeNode(dev, root, deviceDescription, countDev,
                                 checkedDev);
                }
            }

            UpdateDevicesCountInHeaders(devicesArray, root, countDev);
            SortTreeView(treeModel);

            devicesTreeViewAdv.Model = treeModel;

            List <TreeNodeAdv> nodes    = devicesTreeViewAdv.AllNodes.ToList();
            TreeNodeAdv        treeNode = nodes[0];

            OnHideOperationTree.Execute(treeNode);

            devicesTreeViewAdv.ExpandAll();
            devicesTreeViewAdv.Refresh();
            devicesTreeViewAdv.EndUpdate();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Обновление дерева после привязки устройства к каналу при
 /// двойном клике
 /// </summary>
 public void RefreshTreeAfterBinding()
 {
     if (noAssigmentBtn.Checked)
     {
         devicesTreeViewAdv.BeginUpdate();
         List <TreeNodeAdv> treeNodes = devicesTreeViewAdv.AllNodes
                                        .ToList();
         TreeNodeAdv treeNode = treeNodes[0];
         RefreshOperationTree.Execute(treeNode);
         treeNodes.Clear();
         treeNodes = devicesTreeViewAdv.AllNodes.ToList();
         treeNode  = treeNodes[0];
         OnHideOperationTree.Execute(treeNode);
         devicesTreeViewAdv.EndUpdate();
         devicesTreeViewAdv.Refresh();
     }
     else
     {
         devicesTreeViewAdv.Refresh();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Обновление дерева на основе текущих устройств проекта.
        /// </summary>
        /// <param name="techManager">Менеджер техустройств проекта.</param>
        /// <param name="checkedMode">Выбранные операции.</param>
        private void Refresh(TechObject.TechObjectManager techManager,
                             Editor.ITreeViewItem checkedMode, bool showOneNode,
                             Editor.ITreeViewItem item)
        {
            modesTreeViewAdv.BeginUpdate();

            modesTreeViewAdv.Model = null;
            modesTreeViewAdv.Refresh();
            var treeModel = new TreeModel();

            var root = new Node(techManager.DisplayText[0]);

            root.Tag = techManager;
            treeModel.Nodes.Add(root);

            int techObjectNumber = 0;
            int modeNumber       = 0;
            var mainTechObject   = item as TechObject.TechObject;

            FillTreeObjects(techManager.Items, root, mainTechObject,
                            showOneNode, ref techObjectNumber, ref modeNumber,
                            checkedMode);

            SetUpTreeVisibility(root, checkedMode);

            modesTreeViewAdv.Model = treeModel;

            List <TreeNodeAdv> nodes    = modesTreeViewAdv.AllNodes.ToList();
            TreeNodeAdv        treeNode = nodes[0];

            OnHideOperationTree.Execute(treeNode);

            modesTreeViewAdv.ExpandAll();
            modesTreeViewAdv.Refresh();
            modesTreeViewAdv.EndUpdate();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Обновление дерева на основе текущих устройств проекта.
        /// </summary>
        ///
        /// <param name="techManager">Менеджер техустройств проекта.</param>
        /// <param name="checkedMode">Выбранные операиции.</param>
        private void Refresh(TechObject.TechObjectManager techManager,
                             ITreeViewItem checkedMode, bool showOneNode, ITreeViewItem item)
        {
            modesTreeViewAdv.BeginUpdate();

            modesTreeViewAdv.Model = null;
            modesTreeViewAdv.Refresh();
            TreeModel treeModel = new TreeModel();

            Node root = new Node(techManager.DisplayText[0]);

            root.Tag = techManager.GetType().FullName;
            treeModel.Nodes.Add(root);

            int toNum   = 0;
            int modeNum = 0;

            TechObject.TechObject mainTO = item as TechObject.TechObject;
            var restriction = checkedMode as TechObject.Restriction;

            //Заполняем узлы дерева устройствами.
            foreach (TechObject.TechObject to in techManager.Objects)
            {
                toNum++;

                Node parentNode = new Node(to.DisplayText[0]);
                parentNode.Tag = to.GetType().FullName;
                root.Nodes.Add(parentNode);

                List <TechObject.Mode> modes = to.ModesManager.Modes;

                foreach (TechObject.Mode mode in modes)
                {
                    modeNum++;

                    Node childNode = new Node(mode.DisplayText[0]);
                    childNode.Tag = mode.GetType().FullName;
                    parentNode.Nodes.Add(childNode);

                    if (restriction != null)
                    {
                        var restrictionManager = restriction.Parent;
                        var selectedMode       = restrictionManager.Parent as
                                                 TechObject.Mode;
                        var modeManager = selectedMode.Parent;
                        var selectedTO  = modeManager.Parent as
                                          TechObject.TechObject;
                        if (to.DisplayText[0] == selectedTO.DisplayText[0] &&
                            mode.Name == selectedMode.Name)
                        {
                            childNode.IsHidden = true;
                        }
                    }

                    string checkedStr;
                    if (checkedMode != null)
                    {
                        checkedStr = checkedMode.EditText[1];
                        if (restriction != null)
                        {
                            if (restriction.RestrictDictionary != null)
                            {
                                if (restriction.RestrictDictionary
                                    .ContainsKey(toNum))
                                {
                                    if (restriction.RestrictDictionary[toNum]
                                        .Contains(modeNum))
                                    {
                                        childNode.CheckState = CheckState
                                                               .Checked;
                                    }
                                    else
                                    {
                                        childNode.CheckState = CheckState
                                                               .Unchecked;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        checkedStr           = "";
                        childNode.CheckState = CheckState.Unchecked;
                    }
                }

                if (showOneNode == true)
                {
                    if (to != mainTO)
                    {
                        parentNode.IsHidden = true;
                        foreach (Node child in parentNode.Nodes)
                        {
                            child.IsHidden = true;
                        }
                    }
                }
                else
                {
                    if (to == mainTO)
                    {
                        parentNode.IsHidden = true;
                        foreach (Node child in parentNode.Nodes)
                        {
                            child.IsHidden = true;
                        }
                    }
                }
            }

            modesTreeViewAdv.Model = treeModel;
            //Обновляем названия строк (добавляем количество объектов).

            List <TreeNodeAdv> nodes    = modesTreeViewAdv.AllNodes.ToList();
            TreeNodeAdv        treeNode = nodes[0];

            OnHideOperationTree.Execute(treeNode);

            modesTreeViewAdv.ExpandAll();
            modesTreeViewAdv.Refresh();
            modesTreeViewAdv.EndUpdate();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Обновление дерева на основе текущих устройств проекта.
        /// </summary>
        ///
        /// <param name="deviceManager">Менеджер устройств проекта.</param>
        /// <param name="checkedDev">Выбранные устройства.</param>
        private void Refresh(Device.DeviceManager deviceManager,
                             string checkedDev)
        {
            devicesTreeViewAdv.BeginUpdate();

            devicesTreeViewAdv.Model = null;
            devicesTreeViewAdv.Refresh();
            TreeModel treeModel = new TreeModel();

            Node root = new Node("Устройства проекта");

            treeModel.Nodes.Add(root);

            foreach (Device.DeviceType devType in Enum.GetValues(typeof(Device.DeviceType)))
            {
                Node r = new Node(devType.ToString());
                r.Tag = devType;
                root.Nodes.Add(r);
            }

            int[] countDev = new int[Enum.GetValues(typeof(Device.DeviceType)).Length];


            //Заполняем узлы дерева устройствами.
            foreach (Device.IODevice dev in deviceManager.Devices)
            {
                Node parent  = null;
                Node devNode = null;
                foreach (Node node in root.Nodes)
                {
                    if ((Device.DeviceType)node.Tag == dev.DeviceType)
                    {
                        parent = node;
                        break;
                    }
                }

                //Не найден тип устройства.
                if (parent == null)
                {
                    break;
                }

                // Если есть символы переноса строки
                string result = "";
                if (dev.Description.Contains('\n'))
                {
                    string[] devDescr = dev.Description.Split('\n');
                    foreach (string str in devDescr)
                    {
                        result += str + " ";
                    }
                }
                else
                {
                    result = dev.Description;
                }

                if (dev.ObjectName != "")
                {
                    string objectName = dev.ObjectName + dev.ObjectNumber;
                    Node   devParent  = null;

                    foreach (Node node in parent.Nodes)
                    {
                        if ((node.Tag is String) &&
                            (string)node.Tag == objectName)
                        {
                            devParent = node;
                            break;
                        }
                    }

                    if (devParent == null)
                    {
                        devParent     = new Node(objectName);
                        devParent.Tag = objectName;
                        parent.Nodes.Add(devParent);
                    }

                    devNode     = new Node(dev.DeviceType + dev.DeviceNumber.ToString() + "\t  " + result);
                    devNode.Tag = dev;
                    devParent.Nodes.Add(devNode);
                }
                else
                {
                    devNode     = new Node(dev.name + "\t  " + result);
                    devNode.Tag = dev;
                    parent.Nodes.Add(devNode);
                }

                //Check.
                checkedDev = ' ' + checkedDev + ' ';
                if (checkedDev != "  " && checkedDev.Contains(' ' + dev.Name + ' '))
                {
                    devNode.CheckState = CheckState.Checked;
                }
                else
                {
                    devNode.CheckState = CheckState.Unchecked;
                }

                bool isDevVisible = false;
                if (prevShowChannels)
                {
                    Node newNodeCh = null;

                    //Показываем каналы.
                    foreach (Device.IODevice.IOChannel ch in dev.Channels)
                    {
                        if (!ch.IsEmpty())
                        {
                            newNodeCh = new Node(ch.Name + " " + ch.Comment +
                                                 $" (A{ch.FullModule}:" + ch.PhysicalClamp + ")");
                            newNodeCh.Tag = ch;
                            devNode.Nodes.Add(newNodeCh);

                            if (noAssigmentBtn.Checked)
                            {
                                newNodeCh.IsHidden = true;
                            }
                            else
                            {
                                isDevVisible = true;
                            }
                        }
                        else
                        {
                            newNodeCh     = new Node(ch.Name + " " + ch.Comment);
                            newNodeCh.Tag = ch;
                            devNode.Nodes.Add(newNodeCh);

                            isDevVisible = true;
                        }
                    }
                }

                //Пропускаем устройства ненужных типов.
                if (devTypesLastSelected != null &&
                    !devTypesLastSelected.Contains(dev.DeviceType))
                {
                    devNode.IsHidden = true;
                }
                else
                {
                    if (devSubTypesLastSelected != null &&
                        !devSubTypesLastSelected.Contains(dev.DeviceSubType))
                    {
                        devNode.IsHidden = true;
                    }
                    else
                    {
                        if (prevShowChannels && !isDevVisible)
                        {
                            devNode.IsHidden = true;
                        }
                        else
                        {
                            countDev[(int)dev.DeviceType]++;
                        }
                    }
                }
            }

            //Обновляем названия строк (добавляем количество устройств).
            int idx   = 0;
            int total = 0;

            foreach (Device.DeviceType devType in Enum.GetValues(typeof(Device.DeviceType)))
            {
                foreach (Node node in root.Nodes)
                {
                    if ((Device.DeviceType)node.Tag == devType)
                    {
                        total    += countDev[idx];
                        node.Text = devType.ToString() + " (" + countDev[idx++] + ")  ";
                        break;
                    }
                }
            }

            root.Text = "Устройства проекта (" + total + ")";

            // Сортировка узлов
            List <Node> rootNodes = treeModel.Nodes.ToList();
            // [0] - узловой с названием проекта
            List <Node> nodeNodes = rootNodes[0].Nodes.ToList();

            // Сортируем узлы внутри каждого устройства Device
            foreach (Node node in nodeNodes)
            {
                TreeSort(node.Nodes.ToList(), node);
            }

            devicesTreeViewAdv.Model = treeModel;

            List <TreeNodeAdv> nodes    = devicesTreeViewAdv.AllNodes.ToList();
            TreeNodeAdv        treeNode = nodes[0];

            OnHideOperationTree.Execute(treeNode);

            devicesTreeViewAdv.ExpandAll();
            devicesTreeViewAdv.Refresh();
            devicesTreeViewAdv.EndUpdate();
        }