WPF的2D图形化实现--WPF 集装箱堆场图形化实现实例

终于有空整理一下关于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, "单击选中的对象");
        }

 

 

 

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

 

 /Files/dyheee/WPFBeta.rar

 

 

 

posted @ 2011-02-24 14:30  dyheee  阅读(1434)  评论(1编辑  收藏  举报