duheng
2025-03-28 b825d70578b0ddf6d479569887c194f919795dad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
 
namespace HydroUI
{
    public partial class DMap : XtraUserControl
    {
 
        public TContainer TC = new TContainer();
 
        /// <summary>
        /// 地图选项
        /// </summary>
        public MapDimensions mapOption
        {
            get { return TC.mapOption; }
            set { TC.mapOption = value; }
        }
 
 
        /// <summary>
        /// 临时管网层
        /// </summary>
        [Browsable(false)]
        public Template _newTemplate
        {
            get { return TC.newTemplate; }
            set { TC.newTemplate = value; }
        }
 
 
        [Browsable(false)]
        public Template _Template
        {
            get { return TC.template; }
        }
 
 
        private bool _needPaintAll;
        private Bitmap buffer;
 
        public DrawDelegate DrawNet = null;
        public DrawDelegate DrawNetNew = null;
 
        public DrawDelegate DrawBackGroundPic = null;
 
        //绘制辅助线
        public DrawDelegate DrawAuxiliary = null;
 
        public MouseDelegate onMouseDown = null;
        public MouseDelegate onMouseMove = null;
        public MouseDelegate onMouseUp = null;
        public MouseDelegate onMouseWheel = null;
        public DrawingMode drawingMode = DrawingMode.All;
 
        private bool Inited = false;
 
        public DrawingStatus Status = DrawingStatus.Ready;
        public DMap()
        {
            InitializeComponent();
            DoubleBuffered = true;
        }
 
        //补充参数
        public void Init(TContainer TC, DrawDelegate[] Draws, MouseDelegate[] MouseEvents)
        {
            this.TC = TC;
            this.DrawNet = Draws[0];
            this.DrawNetNew = Draws[1];
            this.DrawBackGroundPic = Draws[2];
            this.DrawAuxiliary = Draws[3];
            this.onMouseDown = MouseEvents[0];
            this.onMouseMove = MouseEvents[1];
            this.onMouseUp = MouseEvents[2];
            this.onMouseWheel = MouseEvents[3];
            this.Inited = true;
            this.Status = DrawingStatus.Ready;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            this.Status = DrawingStatus.drawingBase;
            base.OnPaint(e);
            if (!Inited) { this.Status = DrawingStatus.Ready; return; }
            if (float.IsInfinity(mapOption.zoom)) { this.Status = DrawingStatus.Ready; return; }
 
            _needPaintAll = false;
            if (buffer == null || buffer.Width != Width || buffer.Height != Height)
            {
                buffer?.Dispose();
                buffer = new Bitmap(Width, Height);
            }
            // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素
            var bufferG = Graphics.FromImage(buffer);
            // 先将控件的背景填充为白色
            bufferG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            bufferG.Clear(Color.Transparent);
            bufferG.TranslateTransform(Width / 2, Height / 2);
            bufferG.ScaleTransform(mapOption.zoom, -mapOption.zoom);
            bufferG.TranslateTransform(-mapOption.Center.X, -mapOption.Center.Y);
 
 
            this.Status = DrawingStatus.drawingPic;
            DrawBackGroundPic(bufferG, _Template);
            this.Status = DrawingStatus.drawingNet;
            //BookMark    :绘制地图事件
            DrawNet(bufferG, _Template);
 
            this.Status = DrawingStatus.drawingNetNew;
            if (_newTemplate?.network != null) DrawNetNew(bufferG, _newTemplate);
 
            this.Status = DrawingStatus.drawingOthers;
            DrawAuxiliary(bufferG, null);
            // 将生成的画布绘制到控件上
            e.Graphics.DrawImage(buffer, 0, 0);
 
            bufferG.Dispose();
            this.Status = DrawingStatus.Ready;
 
        }
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (Inited) onMouseDown(e);
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (Inited) onMouseMove(e);
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (Inited) onMouseUp(e);
        }
 
        private void InitializeComponent()
        {
 
        }
 
        protected override void OnMouseWheel(MouseEventArgs ev)
        {
            base.OnMouseWheel(ev);
            if (Inited) onMouseWheel(ev);
        }
 
    }
}