Exemplo n.º 1
0
        private void InsertSorted(Collection <Node> nodes, HardwareNode node)
        {
            int i = 0;

            while (i < nodes.Count && nodes[i] is HardwareNode &&
                   ((HardwareNode)nodes[i]).Hardware.HardwareType <
                   node.Hardware.HardwareType)
            {
                i++;
            }
            nodes.Insert(i, node);
        }
Exemplo n.º 2
0
        private void SubHardwareAdded(IHardware hardware, Node node)
        {
            HardwareNode hardwareNode =
                new HardwareNode(hardware, settings, unitManager);

            hardwareNode.PlotSelectionChanged += PlotSelectionChanged;

            InsertSorted(node.Nodes, hardwareNode);

            foreach (IHardware subHardware in hardware.SubHardware)
            {
                SubHardwareAdded(subHardware, hardwareNode);
            }
        }
Exemplo n.º 3
0
        private void HardwareRemoved(IHardware hardware)
        {
            List <HardwareNode> nodesToRemove = new List <HardwareNode>();

            foreach (Node node in root.Nodes)
            {
                HardwareNode hardwareNode = node as HardwareNode;
                if (hardwareNode != null && hardwareNode.Hardware == hardware)
                {
                    nodesToRemove.Add(hardwareNode);
                }
            }
            foreach (HardwareNode hardwareNode in nodesToRemove)
            {
                root.Nodes.Remove(hardwareNode);
                hardwareNode.PlotSelectionChanged -= PlotSelectionChanged;
            }
            PlotSelectionChanged(this, null);
        }
Exemplo n.º 4
0
        private void treeView_Click(object sender, EventArgs e)
        {
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            NodeControlInfo info = treeView.GetNodeControlInfoAt(
                new Point(m.X, m.Y)
                );

            treeView.SelectedNode = info.Node;
            if (info.Node != null)
            {
                SensorNode node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    treeContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        MenuItem item = new MenuItem("Параметры...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ShowParameterForm(node.Sensor);
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Переименовать");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("Скрыть");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = false;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("Показать");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = true;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Цвет...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ColorDialog dialog = new ColorDialog();
                            dialog.Color = node.PenColor.GetValueOrDefault();
                            if (dialog.ShowDialog() == DialogResult.OK)
                            {
                                node.PenColor = dialog.Color;
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    {
                        MenuItem item = new MenuItem("Сбросить цвет");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.PenColor = null;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Показать в трее");
                        item.Checked = systemTray.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                systemTray.Remove(node.Sensor);
                            }
                            else
                            {
                                systemTray.Add(node.Sensor, true);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (gadget != null)
                    {
                        MenuItem item = new MenuItem("Показать в гаджете");
                        item.Checked = gadget.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                gadget.Remove(node.Sensor);
                            }
                            else
                            {
                                gadget.Add(node.Sensor);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.Sensor.Control != null)
                    {
                        treeContextMenu.MenuItems.Add(new MenuItem("-"));
                        IControl control     = node.Sensor.Control;
                        MenuItem controlItem = new MenuItem("Контроль");
                        MenuItem defaultItem = new MenuItem("По умолчанию");
                        defaultItem.Checked = control.ControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate(object obj, EventArgs args) {
                            control.SetDefault();
                        };
                        MenuItem manualItem = new MenuItem("Ручной режим");
                        controlItem.MenuItems.Add(manualItem);
                        manualItem.Checked = control.ControlMode == ControlMode.Software;
                        for (int i = 0; i <= 100; i += 5)
                        {
                            if (i <= control.MaxSoftwareValue &&
                                i >= control.MinSoftwareValue)
                            {
                                MenuItem item = new MenuItem(i + " %");
                                item.RadioCheck = true;
                                manualItem.MenuItems.Add(item);
                                item.Checked = control.ControlMode == ControlMode.Software &&
                                               Math.Round(control.SoftwareValue) == i;
                                int softwareValue = i;
                                item.Click += delegate(object obj, EventArgs args) {
                                    control.SetSoftware(softwareValue);
                                };
                            }
                        }
                        treeContextMenu.MenuItems.Add(controlItem);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }

                HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
                if (hardwareNode != null && hardwareNode.Hardware != null)
                {
                    treeContextMenu.MenuItems.Clear();

                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Переименовать");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }