博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF的2D图形化实现--WPF 集装箱堆场图形化实现实例
阅读量:5264 次
发布时间:2019-06-14

本文共 5807 字,大约阅读时间需要 19 分钟。

终于有空整理一下关于WPF的2D图形化实现的代码样例了。

目前阶段,已经把功能封装成了一个控件,主要有一下的功能

1、图形对与滚动条支持的功能。

2、图形中的图元同步的移动功能。

3、图形中的图元同步的缩放。

4、图形中的图元对象的分层的概念(层可以套层,图元下面加载子图元)。

5、图形中的图元的选中功能。

6、为图形中的图元提供虚拟图层(提供缓创建功能)功能

7、加载自定义图形的支持,并且同步移动,缩放功能。

8、图形中的图元闪烁功能。

9、图元的移动功能。

10、框选区域放大功能。

基本就是上面的功能,有些功能,相隔时间久了,偶有可能忘记,只能考大家发现了。

基于NET4.0 开发工具VS2010

 

下面讲一下主要功能的实现的代码

加载对层和加载对象

加载对层和加载对象

     for (int i = 0; i < 1; i++)
            {
                //加载箱区
                foreach (var area in areaGisData)
                {
                    BayVisualShape bayVisualShape = new BayVisualShape(area.AreaNo + i.ToString(), new Point(area.GisPoint.X + i * 1000, area.GisPoint.Y), area.GisWidth - 0.2, area.GisHeight - 0.2);
                    bayVisualShape.Color = Colors.Blue;
                    bayVisualShape.VisualLable = new VisualLable(area.AreaNo){LableDirection=LabelPosition.MiddleRight};
                
                    //图层加载对象
                    AreaLayer.AddObject(bayVisualShape);
                    bayVisualShape.Virtual = true;
                    //加载场箱位
                    foreach (var slotGisData in area.SlotGisData)
                    {
                      
                        YardSlotVisualShape slotGisDataShape = new YardSlotVisualShape(slotGisData.SlotNo + i.ToString(), new Point(slotGisData.GisPoint.X + i * 1000, slotGisData.GisPoint.Y), slotGisData.GisWidth - 0.2, slotGisData.GisHeight - 0.2);
                        slotGisDataShape.Color = Colors.Red;
                        // 对象加载子对象
                        bayVisualShape.AddObject(slotGisDataShape);
                    }
                    //break;
                }
            }     for (int i = 0; i < 1; i++)
            {
                //加载箱区
                foreach (var area in areaGisData)
                {
                    BayVisualShape bayVisualShape = new BayVisualShape(area.AreaNo + i.ToString(), new Point(area.GisPoint.X + i * 1000, area.GisPoint.Y), area.GisWidth - 0.2, area.GisHeight - 0.2);
                    bayVisualShape.Color = Colors.Blue;
                    bayVisualShape.VisualLable = new VisualLable(area.AreaNo){LableDirection=LabelPosition.MiddleRight};
                
                    //图层加载对象
                    AreaLayer.AddObject(bayVisualShape);
                    bayVisualShape.Virtual = true;
                    //加载场箱位
                    foreach (var slotGisData in area.SlotGisData)
                    {
                      
                        YardSlotVisualShape slotGisDataShape = new YardSlotVisualShape(slotGisData.SlotNo + i.ToString(), new Point(slotGisData.GisPoint.X + i * 1000, slotGisData.GisPoint.Y), slotGisData.GisWidth - 0.2, slotGisData.GisHeight - 0.2);
                        slotGisDataShape.Color = Colors.Red;
                        // 对象加载子对象
                        bayVisualShape.AddObject(slotGisDataShape);
                    }
                    //break;
                }
            }

加载对层和加载对象

     for (int i = 0; i < 1; i++)
            {
                //加载箱区
                foreach (var area in areaGisData)
                {
                    BayVisualShape bayVisualShape = new BayVisualShape(area.AreaNo + i.ToString(), new Point(area.GisPoint.X + i * 1000, area.GisPoint.Y), area.GisWidth - 0.2, area.GisHeight - 0.2);
                    bayVisualShape.Color = Colors.Blue;
                    bayVisualShape.VisualLable = new VisualLable(area.AreaNo){LableDirection=LabelPosition.MiddleRight};
                
                    //图层加载对象
                    AreaLayer.AddObject(bayVisualShape);
                    bayVisualShape.Virtual = true;
                    //加载场箱位
                    foreach (var slotGisData in area.SlotGisData)
                    {
                      
                        YardSlotVisualShape slotGisDataShape = new YardSlotVisualShape(slotGisData.SlotNo + i.ToString(), new Point(slotGisData.GisPoint.X + i * 1000, slotGisData.GisPoint.Y), slotGisData.GisWidth - 0.2, slotGisData.GisHeight - 0.2);
                        slotGisDataShape.Color = Colors.Red;
                        // 对象加载子对象
                        bayVisualShape.AddObject(slotGisDataShape);
                    }
                    //break;
                }
            }     for (int i = 0; i < 1; i++)
            {
                //加载箱区
                foreach (var area in areaGisData)
                {
                    BayVisualShape bayVisualShape = new BayVisualShape(area.AreaNo + i.ToString(), new Point(area.GisPoint.X + i * 1000, area.GisPoint.Y), area.GisWidth - 0.2, area.GisHeight - 0.2);
                    bayVisualShape.Color = Colors.Blue;
                    bayVisualShape.VisualLable = new VisualLable(area.AreaNo){LableDirection=LabelPosition.MiddleRight};
                
                    //图层加载对象
                    AreaLayer.AddObject(bayVisualShape);
                    bayVisualShape.Virtual = true;
                    //加载场箱位
                    foreach (var slotGisData in area.SlotGisData)
                    {
                      
                        YardSlotVisualShape slotGisDataShape = new YardSlotVisualShape(slotGisData.SlotNo + i.ToString(), new Point(slotGisData.GisPoint.X + i * 1000, slotGisData.GisPoint.Y), slotGisData.GisWidth - 0.2, slotGisData.GisHeight - 0.2);
                        slotGisDataShape.Color = Colors.Red;
                        // 对象加载子对象
                        bayVisualShape.AddObject(slotGisDataShape);
                    }
                    //break;
                }
            }

 

   //虚拟图层(提供缓创建功能)

visualMainWindow1.AddVirtualLayers(AreaLayer);

 

// 染色

 

       foreach (var sharp in AreaLayer.SharpList)
            {
                foreach (var child in sharp.SharpList)
                {
                    if (((VisualSharp)child).Color == Colors.Red)
                        ((VisualSharp)child).Color = Colors.DarkGreen;                
                    else
                    {
                        ((VisualSharp)child).Color = Colors.Red;
                    }
                }
            
            }       foreach (var sharp in AreaLayer.SharpList)
            {
                foreach (var child in sharp.SharpList)
                {
                    if (((VisualSharp)child).Color == Colors.Red)
                        ((VisualSharp)child).Color = Colors.DarkGreen;                
                    else
                    {
                        ((VisualSharp)child).Color = Colors.Red;
                    }
                }
            
            }

 

 //移动

 

                   foreach (var sharp in AreaLayer1.SharpList)

            {
                sharp.StartTransformAnimation(new Point(sharp.OrgPos.X + 1000, sharp.OrgPos.Y + 1000), 1);
            }       
            foreach (var sharp in AreaLayer1.SharpList)
            {
                sharp.StartTransformAnimation(new Point(sharp.OrgPos.X + 1000, sharp.OrgPos.Y + 1000), 1);
            }

 

 

 

 

//闪烁

 

      foreach (var sharp in AreaLayer1.SharpList)

            {
                sharp.StartColorAnimation(Colors.Blue, Colors.Red, 3, true, true);
            }

            foreach (var sharp in AreaLayer.SharpList)

            {
                foreach (var visualSharp in sharp.SharpList)
                {
                    visualSharp.StartColorAnimation(Colors.White, Colors.Black, 3, true, true);
                  
                }
                return;
            }      foreach (var sharp in AreaLayer1.SharpList)
            {
                sharp.StartColorAnimation(Colors.Blue, Colors.Red, 3, true, true);
            }

            foreach (var sharp in AreaLayer.SharpList)

            {
                foreach (var visualSharp in sharp.SharpList)
                {
                    visualSharp.StartColorAnimation(Colors.White, Colors.Black, 3, true, true);
                  
                }
                return;
            }

 

    

//取消闪烁

 

       foreach (var sharp in AreaLayer1.SharpList)
            {
                sharp.CancelColorAnimation(Colors.Blue);
            }       foreach (var sharp in AreaLayer1.SharpList)
            {
                sharp.CancelColorAnimation(Colors.Blue);
            }

 

 

//单击得到对象

 

     private void visualMainWindow1_MouseLeftButtonDownGetVisual(object sender, System.EventArgs e)
        {
            MessageBox.Show("单击选中的对象"+((VisualSharp)sender).UniqueId, "单击选中的对象");
        }
     private void visualMainWindow1_MouseLeftButtonDownGetVisual(object sender, System.EventArgs e)
        {
            MessageBox.Show("单击选中的对象"+((VisualSharp)sender).UniqueId, "单击选中的对象");
        }

 

 

 

 先写这些。。哈哈哈。。。困了。。去休息一下。。。

 

 

 

 

 

转载于:https://www.cnblogs.com/dyheee/archive/2011/02/24/1963773.html

你可能感兴趣的文章
NPOI处理Word文本中上下角标
查看>>
Android笔记 Handler
查看>>
如何阅读大型前端开源项目的源码(转)
查看>>
java.util.Arrays类详解
查看>>
idea搭建tocmat
查看>>
NYOJ-626-intersection set(二分查找)
查看>>
项目管理之路(1):初步踏入项目管理
查看>>
Java 中 静态方法与非静态方法的区别
查看>>
echarts饼图显示百分比
查看>>
JMS消息
查看>>
Jenkins+ProGet+Windows Batch搭建全自动的内部包(NuGet)打包和推送及管理平台
查看>>
php上传文件及头像预览
查看>>
大四java实习生的一些经历
查看>>
线程池的概念
查看>>
Oracle_Statspack性能诊断工具
查看>>
转获取sql维护的表关系
查看>>
Java 序列化
查看>>
Java 时间处理实例
查看>>
Java 多线程编程
查看>>
Java 数组实例
查看>>