예제 #1
0
파일: MainForm.cs 프로젝트: DrRen/HMonZ
        private void nodeCheckBox_IsVisibleValueNeeded(object sender,
                                                       NodeControlValueEventArgs e)
        {
            SensorNode node = e.Node.Tag as SensorNode;

            e.Value = (node != null) && plotMenuItem.Checked;
        }
예제 #2
0
파일: HardwareNode.cs 프로젝트: DrRen/HMonZ
 private void SensorRemoved(ISensor sensor)
 {
     foreach (TypeNode typeNode in typeNodes)
     {
         if (typeNode.SensorType == sensor.SensorType)
         {
             SensorNode sensorNode = null;
             foreach (Node node in typeNode.Nodes)
             {
                 SensorNode n = node as SensorNode;
                 if (n != null && n.Sensor == sensor)
                 {
                     sensorNode = n;
                 }
             }
             if (sensorNode != null)
             {
                 sensorNode.PlotSelectionChanged -= SensorPlotSelectionChanged;
                 typeNode.Nodes.Remove(sensorNode);
                 UpdateNode(typeNode);
             }
         }
     }
     if (PlotSelectionChanged != null)
     {
         PlotSelectionChanged(this, null);
     }
 }
예제 #3
0
파일: MainForm.cs 프로젝트: DrRen/HMonZ
        private void treeView_NodeMouseDoubleClick(object sender,
                                                   TreeNodeAdvMouseEventArgs e)
        {
            SensorNode node = e.Node.Tag as SensorNode;

            if (node != null && node.Sensor != null &&
                node.Sensor.Parameters.Length > 0)
            {
                ShowParameterForm(node.Sensor);
            }
        }
예제 #4
0
파일: HardwareNode.cs 프로젝트: DrRen/HMonZ
        private void InsertSorted(Node node, ISensor sensor)
        {
            int i = 0;

            while (i < node.Nodes.Count &&
                   ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index)
            {
                i++;
            }
            SensorNode sensorNode = new SensorNode(sensor, settings, unitManager);

            sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged;
            node.Nodes.Insert(i, sensorNode);
        }
예제 #5
0
파일: SensorNode.cs 프로젝트: DrRen/HMonZ
        public override bool Equals(System.Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            SensorNode s = obj as SensorNode;

            if (s == null)
            {
                return(false);
            }

            return(sensor == s.sensor);
        }
예제 #6
0
파일: MainForm.cs 프로젝트: DrRen/HMonZ
        private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e)
        {
            Node node = e.Node.Tag as Node;

            if (node != null)
            {
                Color color;
                if (node.IsVisible)
                {
                    SensorNode sensorNode = node as SensorNode;
                    if (plotMenuItem.Checked && sensorNode != null &&
                        sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
                    {
                        e.TextColor = color;
                    }
                }
                else
                {
                    e.TextColor = Color.DarkGray;
                }
            }
        }
예제 #7
0
파일: MainForm.cs 프로젝트: DrRen/HMonZ
        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));
                }
            }
        }
예제 #8
0
파일: MainForm.cs 프로젝트: DrRen/HMonZ
        private void PlotSelectionChanged(object sender, EventArgs e)
        {
            List <ISensor> selected             = new List <ISensor>();
            IDictionary <ISensor, Color> colors = new Dictionary <ISensor, Color>();
            int colorIndex = 0;

            foreach (TreeNodeAdv node in treeView.AllNodes)
            {
                SensorNode sensorNode = node.Tag as SensorNode;
                if (sensorNode != null)
                {
                    if (sensorNode.Plot)
                    {
                        if (!sensorNode.PenColor.HasValue)
                        {
                            colors.Add(sensorNode.Sensor,
                                       plotColorPalette[colorIndex % plotColorPalette.Length]);
                        }
                        selected.Add(sensorNode.Sensor);
                    }
                    colorIndex++;
                }
            }

            // if a sensor is assigned a color that's already being used by another
            // sensor, try to assign it a new color. This is done only after the
            // previous loop sets an unchanging default color for all sensors, so that
            // colors jump around as little as possible as sensors get added/removed
            // from the plot
            var usedColors = new List <Color>();

            foreach (var curSelectedSensor in selected)
            {
                if (!colors.ContainsKey(curSelectedSensor))
                {
                    continue;
                }
                var curColor = colors[curSelectedSensor];
                if (usedColors.Contains(curColor))
                {
                    foreach (var potentialNewColor in plotColorPalette)
                    {
                        if (!colors.Values.Contains(potentialNewColor))
                        {
                            colors[curSelectedSensor] = potentialNewColor;
                            usedColors.Add(potentialNewColor);
                            break;
                        }
                    }
                }
                else
                {
                    usedColors.Add(curColor);
                }
            }

            foreach (TreeNodeAdv node in treeView.AllNodes)
            {
                SensorNode sensorNode = node.Tag as SensorNode;
                if (sensorNode != null && sensorNode.Plot && sensorNode.PenColor.HasValue)
                {
                    colors.Add(sensorNode.Sensor, sensorNode.PenColor.Value);
                }
            }

            sensorPlotColors = colors;
            plotPanel.SetSensors(selected, colors);
        }