C#开发AGV地图编辑软件

C#自己开发AGV地图编辑软件:

1、自由添加和删除站点、停车位、小车、运行路径。

2、编辑得地图以XML文件保存。

3、导入编辑好地图的XML文件。

4、程序都是源码,可以直接在此基础上进行二次开发。

下载链接:https://download.csdn.net/download/panjinliang066333/88855372

部分代码展示:

#region 限制闪屏protected override CreateParams CreateParams{get{const int WS_MINIMIZEBOX = 0x00020000;  // Winuser.h中定义   CreateParams cp = base.CreateParams;cp.Style = cp.Style | WS_MINIMIZEBOX;   // 允许最小化操作return cp;}}#endregionNodeType newType = NodeType.MousePick;MapPanel mapPanelDocker;FloydHelper floydCurrent;#region AGV配置信息int AGVCount = 0;object[] lockObj;//线程间锁MapVehicle[] myAgvModel;//---占据的单元Dictionary<string, string> LockUnit = new Dictionary<string, string>();#endregion#region 画布属性private int maxScale = 0; //X轴最大刻度private static int AxisOffset = 32;//X轴的Y坐标偏移量private Font font = new Font("宋体", 9F, FontStyle.Regular); //刻度值显示字体bool showRule = true;bool showNetLine = true;public static int MonitorDPI = 12;//单位内像素点 public static float scaling = 1.0F; //缩放比例#endregion#region 变量#region 其他窗体frm_ModelProperty frm_Property;#endregion#endregion#region 其他窗体LoadingForm loadForm;#endregion#region 窗体初始化#region 初始化public frm_AGVMain(){InitializeComponent();loadForm = new LoadingForm();loadForm.ShowLoadingDealy(3);mapPanelDocker = new MapPanel();mapPanelDocker.Size = this.pnlMap.Size;mapPanelDocker.Location = new Point(0, 0);mapPanelDocker.BorderStyle = BorderStyle.FixedSingle;mapPanelDocker.MouseClick += mapPanel1_MouseClick;mapPanelDocker.MouseMove += mapPanelDocker_MouseMove;mapPanelDocker.MouseLeave += mapPanelDocker_MouseLeave;this.pnlMap.Controls.Add(mapPanelDocker);mapPanelDocker.LinePropertySelect += MapPanelDocker_LinePropertySelect;mapPanelDocker.MapNodePropertySelect += MapPanelDocker_CirclePropertySelect;mapPanelDocker.BezierLinePropertySelect += MapPanelDocker_BezierLinePropertySelect;mapPanelDocker.BlockPropertySelect += mapPanelDocker_BlockPropertySelect;mapPanelDocker.IsLine = newType == NodeType.DirectLineCap; ;mapPanelDocker.IsBezierLine = newType == NodeType.BezierLineCap;InitialControlsOptions();InitialTreeViewLayout();}#endregion#region 初始化加载控件属性private void InitialControlsOptions(){newType = NodeType.MousePick;this.btn_鼠标.Enabled = false;foreach (Control item in this.panel8.Controls){if (item.GetType() == typeof(Button)){Button btn = (Button)item;if (btn.Name.Contains("_")){btn.Click += btnAll_Click;}}}}#endregion#region 鼠标箭头/站点、停车点......点击private void btnAll_Click(object sender, EventArgs e){foreach (Control item in this.panel8.Controls){if (item.GetType() == typeof(Button)){Button btnTemp = (Button)item;if (btnTemp.Name.Contains("_")){btnTemp.Enabled = true;}}}Button btn = (Button)sender;string strTemp = btn.Name.Split('_')[1];switch (strTemp){case "鼠标":default:newType = NodeType.MousePick;this.btn_鼠标.Enabled = false;break;case "站点":newType = NodeType.StationNode;this.btn_站点.Enabled = false;break;case "停车点":newType = NodeType.ParkingStationNode;this.btn_停车点.Enabled = false;break;case "直线箭头":newType = NodeType.DirectLineCap;this.btn_直线箭头.Enabled = false;break;case "曲线箭头":newType = NodeType.BezierLineCap;this.btn_曲线箭头.Enabled = false;break;case "块":newType = NodeType.Block;break;case "车":newType = NodeType.Vehicle;break;}mapPanelDocker.IsLine = newType == NodeType.DirectLineCap;mapPanelDocker.IsBezierLine = newType == NodeType.BezierLineCap;}#endregion#region 树状展开添加Layoutprivate void InitialTreeViewLayout(){this.treeviewLayout.Nodes.Clear();TreeNode tn_origine = new TreeNode();tn_origine.Text = "Layout VLayout-01";tn_origine.ToolTipText = tn_origine.Text;this.treeviewLayout.Nodes.Add(tn_origine);AGV_Point[] allPoints = ReadXmlFile.ReadAllPoint(GlobalSystemConfig.Instance.AgvConfigPath);if (allPoints != null){#region 添加所有的点TreeNode tn_sub = new TreeNode();tn_sub.Text = "Points";tn_sub.ToolTipText = tn_sub.Text;tn_origine.Nodes.Add(tn_sub);for (int i = 0; i < allPoints.Length; i++){TreeNode tn_child = new TreeNode();tn_child.Text = "Point   " + allPoints[i]._Name;tn_child.ToolTipText = tn_child.Text;tn_sub.Nodes.Add(tn_child);//二级菜单}#endregion}AGV_Line[] allLines = ReadXmlFile.ReadAllLine(GlobalSystemConfig.Instance.AgvConfigPath);if (allLines != null){#region 添加所有的路径TreeNode tn_sub = new TreeNode();tn_sub.Text = "Paths";tn_sub.ToolTipText = tn_sub.Text;tn_origine.Nodes.Add(tn_sub);for (int i = 0; i < allLines.Length; i++){TreeNode tn_child = new TreeNode();tn_child.Text = "Path   " + allLines[i].LineName;tn_child.ToolTipText = tn_child.Text;tn_sub.Nodes.Add(tn_child);//二级菜单}#endregion}AGV_Block[] allBlocks = ReadXmlFile.ReadAllBlock(GlobalSystemConfig.Instance.AgvConfigPath);if (allBlocks != null){#region 添加所有的块TreeNode tn_sub = new TreeNode();tn_sub.Text = "Blocks";tn_sub.ToolTipText = tn_sub.Text;tn_origine.Nodes.Add(tn_sub);for (int i = 0; i < allBlocks.Length; i++){TreeNode tn_child = new TreeNode();tn_child.Text = "Block   " + allBlocks[i].BlockName;tn_child.ToolTipText = tn_child.Text;tn_child.ContextMenuStrip = this.menuBlock;tn_sub.Nodes.Add(tn_child);//二级菜单string[] strArr = allBlocks[i].menbers.Split(',');for (int j = 0; j < strArr.Length; j++){AGV_Line lineTemp = null;for (int k = 0; k < allLines.Length; k++){if (allLines[k].LineName == strArr[j]){lineTemp = allLines[k];break;}}if (lineTemp != null){TreeNode tn_childchild = new TreeNode();tn_childchild.Text = "Path   " + lineTemp.LineName;tn_childchild.ToolTipText = tn_childchild.Text;tn_child.Nodes.Add(tn_childchild);//三级菜单}}}#endregion}this.treeViewVehicle.Nodes.Clear();tn_origine = new TreeNode();tn_origine.Text = "Layout Vehicles";tn_origine.ToolTipText = tn_origine.Text;this.treeViewVehicle.Nodes.Add(tn_origine);mapPanelDocker.OpenMap(GlobalSystemConfig.Instance.AgvConfigPath);this.treeviewLayout.ExpandAll();this.treeViewVehicle.ExpandAll();}#region 添加子节点时public void TreeView1_DrawNode(object sender, DrawTreeNodeEventArgs e){Font rootFont = new Font("微软雅黑", 9F, FontStyle.Bold);Font childFont = new Font("微软雅黑", 9F);Brush foreBrush = new SolidBrush(Color.FromArgb(81, 81, 81));Brush recBrush = new SolidBrush(Color.FromArgb(82, 218, 163));Brush recSelectedBrush = new SolidBrush(Color.FromArgb(248, 248, 255));Pen recPen = new Pen(new SolidBrush(Color.FromArgb(226, 226, 226)));Pen recHoverPen = new Pen(new SolidBrush(Color.FromArgb(82, 218, 163)));Pen linePen = new Pen(Color.Gray);linePen.DashStyle = DashStyle.Dot;Image icon;if (e.Node.Level == 0)//根节点{#region 绘制根节点icon = Resources.布局图;if (e.Node.Text.Contains("Vehicles")){icon = Resources.ziyuan;}e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(227, 251, 244)), e.Bounds);e.Graphics.DrawImage(icon, e.Node.Bounds.X - 20, e.Node.Bounds.Y + 5);e.Graphics.DrawString(e.Node.Text, rootFont, foreBrush, e.Node.Bounds.Left + 10, e.Node.Bounds.Top + 5);#endregion}else if (e.Node.Level == 1){#region 一级子节点if (!e.Bounds.IsEmpty){Point start = new Point(e.Node.Bounds.X, e.Node.Bounds.Y + 15);Point middle = new Point(e.Node.Bounds.X - 30, e.Node.Bounds.Y + 15);Point topEnd = new Point(e.Node.Bounds.X - 30, e.Node.Bounds.Y);Point bottomEnd = new Point(e.Node.Bounds.X - 30, e.Node.Bounds.Y + 30);e.Graphics.DrawLine(linePen, start, middle);e.Graphics.DrawLine(linePen, middle, topEnd);if (null != e.Node.NextNode){e.Graphics.DrawLine(linePen, middle, bottomEnd);}#region 重绘图标if (!e.Node.IsExpanded){icon = Resources.plus;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 25, e.Node.Bounds.Y + 8);icon = Resources.wenjianjia__2_;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 10, e.Node.Bounds.Y + 8);}else{icon = Resources.jianhao_1;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 25, e.Node.Bounds.Y + 8);icon = Resources.wenjianjia__2_;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 10, e.Node.Bounds.Y + 8);}#endregionRectangle box = new Rectangle(e.Bounds.Left + 60, e.Bounds.Top + 4, this.Width - 60 - 25, e.Bounds.Height - 8);if (e.Node.IsSelected)//二级节点被选中{e.Graphics.FillRectangle(recBrush, box);}e.Graphics.DrawString(e.Node.Text, childFont, foreBrush, e.Node.Bounds.Left + 15, e.Node.Bounds.Top + 6);}#endregion}else{#region 二级子节点if (!e.Bounds.IsEmpty){Point start = new Point(e.Node.Bounds.X + 5, e.Node.Bounds.Y + 15);Point middle = new Point(e.Node.Bounds.X - 20, e.Node.Bounds.Y + 15);Point topEnd = new Point(e.Node.Bounds.X - 20, e.Node.Bounds.Y);Point bottomEnd = new Point(e.Node.Bounds.X - 20, e.Node.Bounds.Y + 30);e.Graphics.DrawLine(linePen, middle, topEnd);//|e.Graphics.DrawLine(linePen, start, middle);//--if (null != e.Node.NextNode){e.Graphics.DrawLine(linePen, middle, bottomEnd);}Rectangle box = new Rectangle(e.Bounds.Left + 65, e.Bounds.Top + 4, this.Width - 55 - 25, e.Bounds.Height - 8);if (e.Node.Text.StartsWith("Point")){icon = Resources.icon_test;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 15, e.Node.Bounds.Y + 8);}else if (e.Node.Text.StartsWith("Path")){icon = Resources.quxian;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 15, e.Node.Bounds.Y + 8);}else if (e.Node.Text.StartsWith("Block")){icon = Resources.icon_block;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 15, e.Node.Bounds.Y + 8);}else if (e.Node.Text.StartsWith("Vehicle")){icon = Resources.ziyuan;e.Graphics.DrawImage(icon, e.Node.Bounds.X - 15, e.Node.Bounds.Y + 8);}if (e.Node.IsSelected)//二级节点被选中{e.Graphics.FillRectangle(recBrush, box);e.Graphics.DrawString(e.Node.Text, childFont, recSelectedBrush, e.Node.Bounds.Left + 10, e.Node.Bounds.Top + 6);}else{if ((e.State & TreeNodeStates.Hot) != 0)//鼠标指针在二级节点上{e.Graphics.DrawRectangle(recHoverPen, box);}else{e.Graphics.DrawRectangle(recPen, box);}e.Graphics.DrawString(e.Node.Text, childFont, foreBrush, e.Node.Bounds.Left + 10, e.Node.Bounds.Top + 6);}}#endregion}}#endregion#endregion#region 画标尺和网格/// <summary>/// 画标尺和网格/// </summary>/// <param name="showRule"></param>/// <param name="showNetLine"></param>/// <returns></returns>private Bitmap PaintRulesAndLine(bool showRule, bool showNetLine){Bitmap bit = new Bitmap(this.Width * 4, this.Height * 4);Graphics g = Graphics.FromImage(bit);int widthInmm = bit.Width;int heightInmm = bit.Height;Pen p = new Pen(Color.Black, 1.5F);if (showRule){#region 绘制X轴标尺for (int i = 0; i <= widthInmm / MonitorDPI * scaling; i++)//标尺总数{float x = MonitorDPI * scaling * i + AxisOffset;PointF start = new PointF(x, AxisOffset);PointF end = new PointF(x, AxisOffset - 3);if (i % 5 == 0){end = new PointF(x, AxisOffset - 6);}if (i % 10 == 0){end = new PointF(x, AxisOffset - 13);PointF pStrPoint = i == 0 ? new PointF(x - 3, AxisOffset - 25) : new PointF(x - 10, AxisOffset - 25);g.DrawString((i * 100).ToString(), font, Brushes.Black, pStrPoint);}g.DrawLine(Pens.Black, start, end);}#endregionBrush bBlack = Brushes.Black;#region 绘制y轴标尺for (int i = 0; i <= heightInmm / MonitorDPI * scaling; i++){float y = MonitorDPI * scaling * i + AxisOffset;PointF start = new PointF(AxisOffset, y);PointF end = new PointF(AxisOffset - 3, y);if (i % 5 == 0){end = new PointF(AxisOffset - 6, y);}if (i % 10 == 0){end = new PointF(AxisOffset - 12, y);PointF pStrPoint = i == 0 ? new PointF(AxisOffset - 20, y - 5) : new PointF(AxisOffset - 32, y - 12);g.DrawString((i * 100).ToString(), font, bBlack, pStrPoint);}g.DrawLine(Pens.Black, start, end);}#endregion}if (showNetLine){#region 绘制网格p = new Pen(Color.Gray, 1);p.DashStyle = DashStyle.Dot;for (int i = 0; i <= widthInmm / MonitorDPI; i++)//x方向网格{g.DrawLine(p, AxisOffset, ((float)(MonitorDPI * i * scaling) + AxisOffset), widthInmm, ((float)(MonitorDPI * i * scaling) + AxisOffset));}for (int i = 0; i <= widthInmm / MonitorDPI; i++)//y方向网格{g.DrawLine(p, ((float)(MonitorDPI * i * scaling) + AxisOffset), AxisOffset, ((float)(MonitorDPI * i * scaling) + AxisOffset), heightInmm);}#endregion}p = new Pen(Color.Black, 1);g.DrawLine(p, new PointF(AxisOffset, AxisOffset), new PointF(widthInmm, AxisOffset));g.DrawLine(p, new PointF(AxisOffset, AxisOffset), new PointF(AxisOffset, heightInmm));return bit;}#endregion#region 获得垂直的文本格式private string GetVString(string inStr){string retStr = "";for (int i = 0; i < inStr.Length; i++){retStr += inStr[i] + Environment.NewLine;}return retStr;}#endregion#endregion#region 窗体加载时private void frm_AGVMain_Load(object sender, EventArgs e){timer1.Start();}#endregion#region 绑定对应的属性窗口private void MapPanelDocker_CirclePropertySelect(MapNodeProperty mapStation){propertyGridControl.SelectedObject = mapStation;}private void MapPanelDocker_LinePropertySelect(MapLineProperty mapLine){propertyGridControl.SelectedObject = mapLine;}private void MapPanelDocker_BezierLinePropertySelect(MapBezierProperty mapBezierLine){propertyGridControl.SelectedObject = mapBezierLine;}private void mapPanelDocker_BlockPropertySelect(MapBlockProperty mapBlock){propertyGridControl.SelectedObject = mapBlock;}#endregion#region 获取临近标尺内的网格点public static Point GetNearRulePoint(Point p){Point retP = p;int x = p.X;int y = p.Y;int intTempx = (int)((x - AxisOffset) / MonitorDPI / scaling);//在第几个网格int intTempy = (int)((y - AxisOffset) / MonitorDPI / scaling);//在第几个网格int singleRuleNetWidth = (int)(MonitorDPI * scaling);int locationX = AxisOffset + (int)((intTempx + 1) * MonitorDPI * scaling);int locationX1 = AxisOffset + (int)((intTempx) * MonitorDPI * scaling);int locationY = AxisOffset + (int)((intTempy + 1) * MonitorDPI * scaling);int locationY1 = AxisOffset + (int)((intTempy) * MonitorDPI * scaling);if (retP.X >= locationX1 + singleRuleNetWidth / 2){retP.X = locationX;}else{retP.X = locationX1;}if (retP.Y >= locationY1 + singleRuleNetWidth / 2){retP.Y = locationY;}else{retP.Y = locationY1;}return retP;}#endregion#region 转换成模型坐标/// <summary>/// 转成模型坐标/// </summary>/// <param name="pSourceLocation"></param>/// <returns></returns>private Point GetInFactLocation(Point pSourceLocation){int x = pSourceLocation.X;int y = pSourceLocation.Y;if (x >= AxisOffset && y >= AxisOffset){x = (int)((x - AxisOffset) / MonitorDPI / scaling * 100);y = (int)((y - AxisOffset) / MonitorDPI / scaling * 100);}Point pTemp = new Point(x, y);return pTemp;}#endregion#region 点击添加MapNodeprivate void mapPanel1_MouseClick(object sender, MouseEventArgs e){if (e.Button != MouseButtons.Left) return;if (newType == NodeType.StationNode){#region 如果是站点MapNode mapCircle = new MapNode();mapPanelDocker.Controls.Add(mapCircle);mapCircle.Name = "Point-" + GetMaxPointName();mapCircle.NameText = mapCircle.Name;mapCircle.OnNameChange += mapPanelDocker.mapCircle_OnNameChange;mapCircle.Left = e.X;mapCircle.Top = e.Y;mapCircle.Size = new Size(20, 20);mapCircle._type = "站点";mapCircle.Click += mapPanelDocker.MapCircle_Click;mapCircle.Focus();Label label1 = new Label();label1.BorderStyle = BorderStyle.None;label1.Name = mapCircle.Name;label1.BackColor = Color.Transparent;label1.Location = new Point((mapCircle).Location.X - 15, (mapCircle).Location.Y - 12);label1.ForeColor = mapPanelDocker.BackColor == Color.Black ? Color.White : Color.Black;label1.Text = mapCircle.Name;label1.AutoSize = true;label1.Visible = true;label1.BringToFront();mapPanelDocker.Controls.Add(label1);#endregion}else if (newType == NodeType.ParkingStationNode){#region 停车点MapNode mapCircle = new MapNode();mapPanelDocker.Controls.Add(mapCircle);mapCircle.Name = "Point-" + GetMaxPointName();mapCircle.NameText = mapCircle.Name;mapCircle.OnNameChange += mapPanelDocker.mapCircle_OnNameChange;mapCircle.Left = e.X;mapCircle.Top = e.Y;mapCircle.Size = new Size(20, 20);mapCircle._type = "停车点";mapCircle.Click += mapPanelDocker.MapCircle_Click;mapCircle.Focus();Label label1 = new Label();label1.BorderStyle = BorderStyle.None;label1.Name = mapCircle.Name;label1.BackColor = Color.Transparent;label1.Location = new Point((mapCircle).Location.X - 15, (mapCircle).Location.Y - 12);label1.ForeColor = mapPanelDocker.BackColor == Color.Black ? Color.White : Color.Black;label1.Text = mapCircle.Name;label1.AutoSize = true;label1.Visible = true;label1.BringToFront();mapPanelDocker.Controls.Add(label1);#endregion}else{propertyGridControl.SelectedObject = new MapPanelProperty((MapPanel)sender);}}#endregion#region 获得一个临时的最大的站点名称/// <summary>/// 获得一个临时的最大的站点数字编号/// </summary>/// <returns></returns>private string GetMaxPointName(){List<string> pointListTemp = new List<string>();foreach (Control item in this.mapPanelDocker.Controls){if (item.GetType() == typeof(MapNode)){MapNode station = (MapNode)item;string _Name = station.Name;if (!pointListTemp.Contains(_Name)){pointListTemp.Add(_Name);}}}for (int i = 0; i < pointListTemp.Count; i++){if (pointListTemp[i] == null){pointListTemp.Remove(pointListTemp[i]);}}if (pointListTemp.Count == 0){return "001";}else if (pointListTemp.Count == 1 && pointListTemp[0] == ""){return "001";}else{string maxPoint = pointListTemp.OrderBy(a => a.ToString()).Max();string strTemp = maxPoint.Split('-')[1];int intTemp2 = int.Parse(strTemp);return (intTemp2 + 1).ToString().PadLeft(3, '0');}}#endregion#region 获得一个最大的块的名称public string GetMaxBlockName(){AGV_Block[] allBlocks = XmlHelper.ReadXmlFile.ReadAllBlock(GlobalSystemConfig.Instance.AgvConfigPath);if (allBlocks != null && allBlocks.Length > 0){string strTemp = allBlocks.Select(e => e.BlockName).Max();if (strTemp != ""){int intTemp = int.Parse(strTemp.Replace("Block-", ""));return (intTemp + 1).ToString().PadLeft(3, '0');}else{return "001";}}return "001";}#endregion#region 定时器主线程private void timer1_Tick(object sender, EventArgs e){#region 显示指针样式和时间string temp = "";switch (newType){case NodeType.MousePick:default:temp = "鼠标";break;case NodeType.StationNode:temp = "站点";break;case NodeType.ParkingStationNode:temp = "停车点";break;case NodeType.DirectLineCap:temp = "直线箭头";break;case NodeType.BezierLineCap:temp = "曲线箭头";break;case NodeType.Block:temp = "块";break;case NodeType.Vehicle:temp = "车";break;}this.lb_NewType.Text = "当前选项:" + temp;this.lbTime.Text = DateTime.Now.ToString("yyyy-MM-dd  hh:mm:ss(ddd)");#endregion}#endregion#region 窗体关闭时private void frm_AGVMain_FormClosing(object sender, FormClosingEventArgs e){DialogResult dg = MessageBox.Show("Do you want to exit this Application?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);if (dg == DialogResult.OK){try{timer1.Stop();}catch{}finally{loadForm = new LoadingForm();loadForm.ShowLoadingDealy(2);Application.ExitThread();Application.Exit();//通知winform消息循环退出 在所有前台线程退出后退出应用 先停止线程 再终止线程Environment.Exit(1);//直接终止所有线程,code为1即使有错误也直接终止 直接终止线程}}else{e.Cancel = true;}}#endregion#region 打开配置文件private void btn_打开文件_Click(object sender, EventArgs e){OpenFileDialog openFileDialog = new OpenFileDialog();openFileDialog.Filter = @"*.xml|*.xml";openFileDialog.InitialDirectory = GlobalSystemConfig.Instance.AppStartPath + @"\AppConfigDir\";if (openFileDialog.ShowDialog() == DialogResult.Cancel){return;}mapPanelDocker.OpenMap(openFileDialog.FileName);GlobalSystemConfig.Instance.AgvConfigPath = openFileDialog.FileName;InitialTreeViewLayout();floydCurrent = new FloydHelper();}#endregion#region 保存数据到xml文件private void bnt_保存_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog = new SaveFileDialog();saveFileDialog.Filter = @"*.xml|*.xml";saveFileDialog.InitialDirectory = GlobalSystemConfig.Instance.AppStartPath + @"\AppConfigDir\";if (saveFileDialog.ShowDialog() == DialogResult.Cancel){return;}mapPanelDocker.SaveMap(saveFileDialog.FileName);XmlHelper.WriteXmlFile.UpdateModifiedDate(saveFileDialog.FileName);floydCurrent = new FloydHelper();}#endregion#region 上下左右private void btn_Left_Click(object sender, EventArgs e){this.mapPanelDocker.Focus();this.btn_Left.Enabled = false;SendKeys.Send("{LEFT}");this.btn_Left.Enabled = true;}private void btn_up_Click(object sender, EventArgs e){this.mapPanelDocker.Focus();this.btn_Left.Enabled = false;SendKeys.Send("{UP}");this.btn_Left.Enabled = true;}private void button4_Click(object sender, EventArgs e){this.mapPanelDocker.Focus();this.btn_Left.Enabled = false;SendKeys.Send("{DOWN}");this.btn_Left.Enabled = true;}private void btn_right_Click(object sender, EventArgs e){this.mapPanelDocker.Focus();this.btn_Left.Enabled = false;SendKeys.Send("{RIGHT}");this.btn_Left.Enabled = true;}#endregion#region 鼠标移入移出显示坐标private void mapPanelDocker_MouseMove(object sender, MouseEventArgs e){this.lbLocation.Text = "X:" + e.Location.X.ToString() + "、Y:" + e.Location.Y.ToString();}private void mapPanelDocker_MouseLeave(object sender, EventArgs e){this.lbLocation.Text = "";}#endregion#region treeView选中某一项时private void treeviewLayout_AfterSelect(object sender, TreeViewEventArgs e){TreeNode tn = e.Node;if (tn != null){if (tn.Text != ""){if (tn.Text.StartsWith("Path")){this.mapPanelDocker.AddSelectLine(tn.Text);}else if (tn.Text.StartsWith("Point")){this.mapPanelDocker.AddSelectStation(tn.Text);}else if (tn.Text.StartsWith("Block")){this.mapPanelDocker.AddSelectBlck(tn.Text);}}}}#endregion#region 添加或者删除一条路径到Block#region 添加private void addToolStripMenuItem_Click(object sender, EventArgs e){if (mapPanelDocker.SelectMapline != null || mapPanelDocker.SelectMapBezierline != null){string strBlockName = this.treeviewLayout.SelectedNode.Text.Replace(" ", "").Replace("BlockBlock", "Block");string lineName = "";string BezierLineName = "";if (mapPanelDocker.SelectMapline != null){lineName = mapPanelDocker.SelectMapline.LineName;}if (mapPanelDocker.SelectMapBezierline != null){BezierLineName = mapPanelDocker.SelectMapBezierline.LineName;}AGV_Block[] allBlocks = ReadXmlFile.ReadAllBlock(GlobalSystemConfig.Instance.AgvConfigPath);for (int i = 0; i < allBlocks.Length; i++){if (allBlocks[i].BlockName == strBlockName){if (lineName != ""){if (!allBlocks[i].menbers.Contains(lineName)){if (allBlocks[i].menbers == ""){allBlocks[i].menbers = lineName;}else{allBlocks[i].menbers = allBlocks[i].menbers + "," + lineName;}}}if (BezierLineName != ""){if (!allBlocks[i].menbers.Contains(BezierLineName)){if (allBlocks[i].menbers == ""){allBlocks[i].menbers = BezierLineName;}else{allBlocks[i].menbers = allBlocks[i].menbers + "," + BezierLineName;}}}XmlHelper.WriteXmlFile.WriteOrCreateBlockValue(allBlocks[i], GlobalSystemConfig.Instance.AgvConfigPath);InitialTreeViewLayout();}}}}#endregion#region 移除private void deleteSelectPathToBlocksToolStripMenuItem_Click(object sender, EventArgs e){if (mapPanelDocker.SelectMapline != null || mapPanelDocker.SelectMapBezierline != null){string strBlockName = this.treeviewLayout.SelectedNode.Text.Replace(" ", "").Replace("BlockBlock", "Block");string lineName = "";string BezierLineName = "";if (mapPanelDocker.SelectMapline != null){lineName = mapPanelDocker.SelectMapline.LineName;}if (mapPanelDocker.SelectMapBezierline != null){BezierLineName = mapPanelDocker.SelectMapBezierline.LineName;}AGV_Block[] allBlocks = ReadXmlFile.ReadAllBlock(GlobalSystemConfig.Instance.AgvConfigPath);for (int i = 0; i < allBlocks.Length; i++){if (allBlocks[i].BlockName == strBlockName){if (lineName != ""){if (allBlocks[i].menbers.Contains(lineName)){if (allBlocks[i].menbers == lineName){allBlocks[i].menbers = "";}else if (allBlocks[i].menbers.Contains(lineName + ",")){allBlocks[i].menbers = allBlocks[i].menbers.Replace(lineName + ",", "");}else{allBlocks[i].menbers = allBlocks[i].menbers.Replace(lineName, "");}}}if (BezierLineName != ""){if (allBlocks[i].menbers.Contains(BezierLineName)){if (allBlocks[i].menbers == BezierLineName){allBlocks[i].menbers = "";}else if (allBlocks[i].menbers.Contains(BezierLineName + ",")){allBlocks[i].menbers = allBlocks[i].menbers.Replace(BezierLineName + ",", "");}else{allBlocks[i].menbers = allBlocks[i].menbers.Replace(BezierLineName, "");}}}XmlHelper.WriteXmlFile.WriteOrCreateBlockValue(allBlocks[i], GlobalSystemConfig.Instance.AgvConfigPath);InitialTreeViewLayout();}}}}#endregion#region 删除整个块private void deleteEntileBlocksToolStripMenuItem_Click(object sender, EventArgs e){string strBlockName = this.treeviewLayout.SelectedNode.Text.Replace(" ", "").Replace("BlockBlock", "Block");if (strBlockName.StartsWith("Block")){if (mapPanelDocker.ListMapBlock != null && mapPanelDocker.ListMapBlock.Count > 0){for (int i = 0; i < mapPanelDocker.ListMapBlock.Count; i++){if (mapPanelDocker.ListMapBlock[i].BlockName == strBlockName){mapPanelDocker.ListMapBlock.Remove(mapPanelDocker.ListMapBlock[i]);mapPanelDocker.SaveMap(GlobalSystemConfig.Instance.AgvConfigPath);InitialTreeViewLayout();}}}}}#endregion#endregion#region 右键菜单打开时private void menuBlock_Opening(object sender, CancelEventArgs e){}#endregion#region 点击进行选中当前节点private void treeviewLayout_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e){if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right){this.treeviewLayout.SelectedNode = e.Node;}}#endregion#region 块点击事件private void btn_块_Click(object sender, EventArgs e){if (newType == NodeType.Block){MapBlock block = new MapBlock();block.OnColorChange += mapPanelDocker.block_OnColorChange;block.BlockName = "Block-" + GetMaxBlockName();block.BlockColor = Color.Red;block.menberLines = new List<MapLine>();block.menberBezierLines = new List<MapBezierLine>();block.isSlected = true;mapPanelDocker.ListMapBlock.Add(block);mapPanelDocker.SaveMap(GlobalSystemConfig.Instance.AgvConfigPath);}InitialTreeViewLayout();}#endregion#region 双击查找路径或者站点private void treeviewLayout_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e){string whichText = e.Node.Text.Replace(" ", "");if (whichText.StartsWith("PointPoint") || whichText.StartsWith("PathPoint")){AGV_Line[] allLines = XmlHelper.ReadXmlFile.ReadAllLine(GlobalSystemConfig.Instance.AgvConfigPath);if (whichText.StartsWith("PointPoint")){whichText = whichText.Replace("PointPoint", "Point").Replace("PathPoint", "Point");//点foreach (Control item in mapPanelDocker.Controls){if(item.GetType()==typeof(MapNode)){MapNode node = (MapNode)item;if(node.Name==whichText){Graphics g = mapPanelDocker.CreateGraphics();g.SmoothingMode = SmoothingMode.HighQuality;Pen p = new Pen(Color.Lime, 2);Point pointTemp = new Point(node.Location.X - 25, node.Location.Y - 25);Size sizeTemp = new Size(70, 70);g.DrawEllipse(p, pointTemp.X, pointTemp.Y, sizeTemp.Width, sizeTemp.Height);}}}}else{whichText = whichText.Replace("PointPoint", "Point").Replace("PathPoint", "Point");//路径if (allLines != null && allLines.Length > 0){for (int i = 0; i < allLines.Length; i++){if (allLines[i].LineName == whichText){AGV_Line agvLine = allLines[i];Pen p = new Pen(Color.Red, 2);Graphics g = mapPanelDocker.CreateGraphics();g.SmoothingMode = SmoothingMode.HighQuality;if (agvLine.controlPoint1.X != 0){Point pointTemp = new Point(((agvLine.controlPoint1.X + agvLine.controlPoint2.X) / 2) - 20, ((agvLine.controlPoint1.Y + agvLine.controlPoint2.Y) / 2) - 20);Size sizeTemp = new Size(60, 60);g.DrawEllipse(p, pointTemp.X, pointTemp.Y, sizeTemp.Width, sizeTemp.Height);}else{Point pointTemp1 = new Point(0,0);Point pointTemp2 = new Point(0, 0);foreach (Control item in mapPanelDocker.Controls){if (item.GetType() == typeof(MapNode)){MapNode node = (MapNode)item;if (node.Name == agvLine.StartControl){pointTemp1 = node.Location;}if (node.Name == agvLine.EndControl){pointTemp2 = node.Location;}}}if (pointTemp1.X != 0 && pointTemp2.X != 0){Point pointTemp = new Point(((pointTemp1.X + pointTemp2.X) / 2) - 20, ((pointTemp1.Y + pointTemp2.Y) / 2) - 20);Size sizeTemp = new Size(60, 60);g.DrawEllipse(p, pointTemp.X, pointTemp.Y, sizeTemp.Width, sizeTemp.Height);}}}}}}}}#endregion#region 新建一个地图文件private void btn_New_Click(object sender, EventArgs e){mapPanelDocker.OpenMap("");GlobalSystemConfig.Instance.AgvConfigPath = "";InitialTreeViewLayout();floydCurrent = new FloydHelper();}#endregion#region 车点击事件private void btn_车_Click(object sender, EventArgs e){if (newType == NodeType.Vehicle){MapBlock block = new MapBlock();block.OnColorChange += mapPanelDocker.block_OnColorChange;block.BlockName = "Vehicle-" + GetMaxBlockName();block.BlockColor = Color.Red;block.menberLines = new List<MapLine>();block.menberBezierLines = new List<MapBezierLine>();block.isSlected = true;mapPanelDocker.ListMapBlock.Add(block);mapPanelDocker.SaveMap(GlobalSystemConfig.Instance.AgvConfigPath);}InitialTreeViewLayout();}#endregion#region 双击时private void treeViewVehicle_AfterSelect(object sender, TreeViewEventArgs e){}#endregion#region 双击时将当前小车进行标定private void treeViewVehicle_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e){}#endregion#region 鼠标左键或者有键将当前节点选中private void treeViewVehicle_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e){if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right){this.treeViewVehicle.SelectedNode = e.Node;}}#endregion#region 是否显示站点的labelbool showLabelFlag = true;private void button2_Click(object sender, EventArgs e){if (showLabelFlag){this.btn_ShowLabel.BackColor = Color.Transparent;showLabelFlag = false;foreach (Control item in this.mapPanelDocker.Controls){if (item.GetType() == typeof(Label)){item.Text = "";}}}else{this.btn_ShowLabel.BackColor = Color.Wheat;showLabelFlag = true;foreach (Control item in this.mapPanelDocker.Controls){if (item.GetType() == typeof(Label)){item.Text = item.Name;}}}this.mapPanelDocker.Invalidate();}#endregion#region 是否显示块的背景颜色bool showBlockLine = true;private void button1_Click(object sender, EventArgs e){if (showBlockLine){this.btn_ShowBlock.BackColor = Color.Wheat;showBlockLine = false;foreach (MapBlock item in this.mapPanelDocker.ListMapBlock){item.ShowBlockLineColor = false;}}else{this.btn_ShowBlock.BackColor = Color.Transparent;showBlockLine = true;foreach (MapBlock item in this.mapPanelDocker.ListMapBlock){item.ShowBlockLineColor = true;}}this.mapPanelDocker.Invalidate();}#endregionprivate void btn_查找小车_Click(object sender, EventArgs e){}#region 显示当前地图的版本信息private void showToolStripMenuItem_Click(object sender, EventArgs e){string filePath = GlobalSystemConfig.Instance.AgvConfigPath;string StationNum, ParkingNum, DirectNum,BezierNum, FileName, BlockNum,VehicleNum, ModifyDate;ReadXmlFile.GetMapNodeNum(out StationNum, out ParkingNum, out DirectNum,out BezierNum, out FileName, out BlockNum,out VehicleNum, out ModifyDate, filePath);NumberModel model = new NumberModel(){StationNum = StationNum,ParkingStationnum = ParkingNum,DirectLineNum = DirectNum,BezierLineNum = BezierNum,FileName = FileName,BlockNum = BlockNum,VehicleNum = VehicleNum,ModifiedDate = ModifyDate};frm_Property = new frm_ModelProperty(model);frm_Property.ShowDialog();}#endregion

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/693249.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

隐匿的炸弹 — C语言的隐式声明

前言 &#xff08;1&#xff09;如果有嵌入式企业需要招聘湖南区域日常实习生&#xff0c;任何区域的暑假Linux驱动实习岗位&#xff0c;可C站直接私聊&#xff0c;或者邮件&#xff1a;zhangyixu02gmail.com&#xff0c;此消息至2025年1月1日前均有效 &#xff08;2&#xff0…

【Python】OpenCV-图像轮廓检测初学

图像轮廓检测初学 在图像处理领域中&#xff0c;轮廓检测是一项重要的任务&#xff0c;用于寻找并标定图像中的物体边缘。本文将介绍如何使用OpenCV库进行图像轮廓检测&#xff0c;并展示一个简单的示例代码。代码中的注释将详细解释每一步的操作。 1. 引言 图像轮廓检测是图…

基于PSO优化的CNN多输入时序回归预测(Matlab)粒子群算法优化卷积神经网络时序回归预测

目录 一、程序及算法内容介绍&#xff1a; 基本内容&#xff1a; 亮点与优势&#xff1a; 二、实际运行效果&#xff1a; 三、部分代码&#xff1a; 四、完整程序下载&#xff1a; 一、程序及算法内容介绍&#xff1a; 基本内容&#xff1a; 本代码基于Matlab平台编译&…

PHP分析二维数据表(长度|数字字段|空值|纯姓名|英文用户名|科学计数|是否等长|是否唯一)

先看图&#xff0c;后有完整代码 <?php $t "Excel数据转Sql查询系统字段半智能分析"; $s "Excel复制过来的二维结构表内容,分析查询条件&#xff01;"; $x "字段|最大长度|长度有|数字字段|空值存在|纯姓名|英文用户名|科学计数|是否等长|是否…

无痛法门,助力学习

**注&#xff1a;**本文摘自一位网友“我就是贺生啊”&#xff0c;博主觉得很有道理&#xff0c;便想记录下来分享给大家。仅个人想法&#xff0c;谨慎参考&#xff0c;也欢迎大家说出自己的想法。 引言 在我们学习新知识的时候&#xff0c;会觉得很痛苦&#xff0c;制定学习…

【git】提交信息写错了,使用 amend 或者 reset 修改最近一次的提交信息 ,修改上上次/以前的提交信息

如果你的提交信息写错了&#xff0c;比如下面&#xff0c;你想修改【初始化项目】这5个字 修改最近一次的提交新的两个办法 &#xff08;1&#xff09;使用 reset 把这个提交重置&#xff0c;然后重新提交&#xff0c;reset 的使用方法请参考这篇文章。但是 reset 这种方法只能…

Django学习笔记-HTML实现MySQL的图片上传

1.django项目编写index.html代码 创建form表单,路由指向upload,请求方式post,enctype设置"multipart/form-data", post请求添加{% csrf_token %},编写两个input,上传和提交 2.添加upload路由 3.views中创建upload 1).获取上传的文件,没有上传则返回"没有指定…

2024年度最高人气的编程语言

本期共享的是 —— 年度地球人气最高的编程语言。 根据我们对人力资源专家和开发者的年度调查&#xff0c;目前市场需求量最大的 10 种编程技术是&#xff1a; Python&#xff08;42.1% 的受访者对具备该技能的候选人有大量需求&#xff09;JS&#xff08;41.6%&#xff09;Ja…

IMX6ULL裸机之UART串口通信(中断)

由于正点原子的UART串口通信裸机例程&#xff0c;采用的是查询方式来进行串口通信&#xff0c;并未使用中断&#xff0c;导致CPU利用率较低&#xff0c;于是产生做本实验的动力。 查阅资料 通过《IMX6ULL参考手册》&#xff0c;得知其串口中断有 从55.4.5 Receiver中可以看出…

解决pycharm中PIL安装失败

问题&#xff1a;在调用pil时显示pil标红 我在设置中下载每次失败&#xff0c;显示 ERROR: Could not find a version that satisfies the requirement PIL (from versions: none) ERROR: No matching distribution found for PIL我尝试了很久&#xff0c;查看了一些博客 &a…

【笔记】【开发方案】APN 配置参数 bitmask 数据转换(Android KaiOS)

一、参数说明 &#xff08;一&#xff09;APN配置结构对比 平台AndroidKaiOS文件类型xmljson结构每个<apn>标签是一条APN&#xff0c;包含完成的信息层级数组结构&#xff0c;使用JSON格式的数据。最外层是mcc&#xff0c;其次mnc&#xff0c;最后APN用数组形式配置&am…

Java使用企业邮箱发送预警邮件

前言&#xff1a;最近接到一个需求&#xff0c;需要根据所监控设备的信息&#xff0c;在出现问题时发送企业微信进行预警。 POM依赖 <!-- 邮件 --> <dependency><groupId>com.sun.mail</groupId><artifactId>jakarta.mail</artifactId>…

【C++】C++11下线程库

C11下线程库 1. thread类的简单介绍2.线程函数参数3.原子性操作库(atomic)4.mutex的种类5. RAII风格加锁解锁5.1Lock_guard5.2unique_lock 6.condition_variable 1. thread类的简单介绍 在C11之前&#xff0c;涉及到多线程问题&#xff0c;都是和平台相关的&#xff0c;比如wi…

Android | ArcGIS入门

一、概述 ArcGIS是由Esri开发的地理信息系统&#xff08;GIS&#xff09;软件。它用于制图、空间分析和数据可视化。ArcGIS允许用户以各种格式创建、管理、分析和共享地理信息。它通常用于城市规划、环境管理和应急响应等领域。该软件包括一系列工具&#xff0c;用于创建地图、…

新年新方案,制造业数字化经营管理平台方案全新升级

伴随着工业4.0和中国智造2025成为制造业领域的两大重要趋势&#xff0c;“推动制造业智能化改造数字化转型”已经到了“不得不”的阶段。 数字化转型能够为制造企业带来降本增效、扩能提质、优化流程、提升竞争力等优势&#xff0c;是建设现代化产业体系的必经之路。 然而&…

CVE-2016-3088(ActiveMQ任意文件写入漏洞)

漏洞描述 1、漏洞编号&#xff1a;CVE-2016-3088 2、影响版本&#xff1a;Apache ActiveMQ 5.x~5.13.0 在 Apache ActiveMQ 5.12.x~5.13.x 版本中&#xff0c;默认关闭了 fileserver 这个应用&#xff08;不过&#xff0c;可以在conf/jetty.xml 中开启&#xff09;&#xff1b;…

【python】linux系统python报错“ssl module in Python is not available”

一、问题现象 1.1 执行pip命令报错 pip安装时遇到openssl问题&#xff0c;没办法安装第三方库 “WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. ” 1.2 导入import ssl 报错 直接执行python&…

C/C++ BM14 链表的奇偶重排

文章目录 前言题目解决方案一1.1 思路阐述1.2 源码 解决方案二2.1 思路阐述2.2 源码 总结 前言 这道题算是链表思路的一种常规题&#xff0c;看透题目本质做起来还是不难。 题目 描述 给定一个单链表&#xff0c;请设定一个函数&#xff0c;将链表的奇数位节点和偶数位节点分…

电脑开机蓝屏错误代码c000021a怎么办 电脑蓝屏报错c000021a的解决办法

很多小伙伴在电脑开机的时候出现蓝屏代码c000021a都不知道该怎么去解决&#xff0c;所以今天就给你们带来了c000021a蓝屏解救方法&#xff0c;如果你还没解决的话就快来看看吧。 解决办法&#xff1a; 原因&#xff1a; c000021a蓝屏的原因有很多&#xff0c;主要有以下几种…

四非保研之旅

大家好&#xff0c;我是工藤学编程&#xff0c;虽有万分感概&#xff0c;但是话不多说&#xff0c;先直接进入正题&#xff0c;抒情环节最后再说&#xff0c;哈哈哈 写在开头 我的分享是来给大家涨信心的&#xff0c;网上的大佬们都太强了&#xff0c;大家拿我涨涨信心&#…