/// <summary> /// 鼠标单击事件,3种情况 /// 1:右键菜单取消 /// 2:添加新传感器 /// 3:打开右键菜单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PicMask_MouseClick(object sender, MouseEventArgs e) { if (IsEditing) { if (SelectSensor != null) { SelectSensor = null; } else if (e.Button == MouseButtons.Left && MostNearSensor == null) { DectectPointInfo new_sensor = new DectectPointInfo(); new_sensor.Location = new Tuple <int, int>(e.X, e.Y); new_sensor.Position = new Tuple <double, double>((double)e.X / this.Width, (double)e.Y / this.Height); new_sensor.Weight = 0; SensorList.Add(new_sensor); ReSet(); } else if (e.Button == MouseButtons.Right) { if (MostNearSensor != null) { RightClickcontextMenuStrip.Show(MousePosition.X, MousePosition.Y); } } } }
/// <summary> /// 右键菜单打开时, /// 1:选择传感器标记 /// 2:显示该标记所绑定的传感器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RightClickcontextMenuStrip_Opening(object sender, CancelEventArgs e) { SelectSensor = MostNearSensor; MostNearSensor = null; if (SelectSensor.SignalName == null) { ToolStripComboBox comboBoxSelectSignals = (ToolStripComboBox)RightClickcontextMenuStrip.Items[2]; comboBoxSelectSignals.Text = "选择传感信号"; } else { ToolStripComboBox comboBoxSelectSignals = (ToolStripComboBox)RightClickcontextMenuStrip.Items[2]; comboBoxSelectSignals.Text = SelectSensor.SignalName; } }
public bool LoadSensorInfo(string logname) { logfilename = logname; SensorList.Clear(); if (File.Exists(string.Format("{0}\\{1}.log", LogPath, logfilename))) { using (StreamReader sr = new StreamReader(string.Format("{0}\\{1}.log", LogPath, logfilename), Encoding.UTF8)) { String line; double x; double y; Random ra = new Random(); while ((line = sr.ReadLine()) != null) { var onesensor = new DectectPointInfo(); x = double.Parse(line.Substring(1, 6)); y = double.Parse(line.Substring(8, 6)); onesensor.Position = new Tuple <double, double>(x, y); onesensor.Location = new Tuple <int, int>(Convert.ToInt32(x * this.Width), Convert.ToInt32(y * this.Height)); //onesensor.Weight = ra.NextDouble(); onesensor.Weight = 0d; // 查询该点是否绑定检测信号 if (line.Length > 16) { onesensor.SignalName = line.Substring(15, line.Length - 15); // 获取之前绑定的信号名称 // 检测该信号名称是否已经加载,若无则清空该监测点绑定的信号名称 var onelistsignal = CardSettingManager.Settings.Find(onesetting => onesetting.SignalName == onesensor.SignalName); if (onelistsignal == null) { onesensor.SignalName = null; } } else { onesensor.SignalName = null; } SensorList.Add(onesensor); } } ReSet(); return(true); } ReSet(); return(false); }
/// <summary> /// 删除传感器标记 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { SensorList.Remove(SelectSensor); SelectSensor = null; ReSet(); }
/// <summary> /// 鼠标移动事件 /// 鼠标是否移动到传感器标记附近 /// 若在编辑状态下则触发拖动 /// 否则显示传感器信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PicMask_MouseMove(object sender, MouseEventArgs e) { if (!isDragging) { int dis = Math.Max(this.Width, this.Height); DectectPointInfo selectsensor = null; foreach (var x in SensorList) { int tmpdis = getdistance(new Tuple <int, int>(e.X, e.Y), x.Location); if (tmpdis < dis) { dis = tmpdis; selectsensor = x; } } if (dis < 8) { MostNearSensor = selectsensor; } else { MostNearSensor = null; } } if (IsEditing) { if (isDragging) { MostNearSensor.Location = new Tuple <int, int>(e.X, e.Y); ReSet(); } else { if (MostNearSensor != null) { this.Cursor = Cursors.SizeAll; } else { this.Cursor = editcursor; } } } else { this.Cursor = this.Parent.Cursor; if (MostNearSensor != null) { if (MostNearSensor.SignalName == null) { Tiplabel.Text = string.Format("{0}\n权重{1:0.0000}", "未选择传感器", MostNearSensor.Weight); } else { Tiplabel.Text = string.Format("{0}\n权重{1:0.0000}", MostNearSensor.SignalName, MostNearSensor.Weight); } Tiplabel.Location = e.Location; Tiplabel.Visible = true; } else { Tiplabel.Visible = false; } } }