• R/O
  • SSH
  • HTTPS

wheretrainbuild: Commit


Commit MetaInfo

Revision53 (tree)
Zeit2020-07-10 11:16:16
Autordangerouswoo

Log Message

(empty log message)

Ändern Zusammenfassung

Diff

--- WhereTrainBuild/AI/LineWalker.cs (revision 52)
+++ WhereTrainBuild/AI/LineWalker.cs (revision 53)
@@ -18,6 +18,19 @@
1818 public class LineWalker
1919 {
2020 /// <summary>
21+ /// 進捗コール型
22+ /// </summary>
23+ /// <param name="sender"></param>
24+ /// <param name="walkingpoint"></param>
25+ /// <param name="walkcount"></param>
26+ public delegate bool ProgressDelegate(LineWalker sender, latlontool.latlng walkingpoint, int walkcount);
27+
28+ /// <summary>
29+ /// 進捗イベント
30+ /// </summary>
31+ public event ProgressDelegate OnProgress;
32+
33+ /// <summary>
2134 /// ズームレベル
2235 /// </summary>
2336 protected const int m_zoom = 18;
@@ -143,6 +156,10 @@
143156
144157 if (m_walking >= MaxWalking)
145158 return walkinglist;
159+
160+ if (OnProgress != null)
161+ if (OnProgress(this, nlatlng, m_walking) == false)
162+ return walkinglist;
146163 }
147164 }
148165
@@ -265,6 +282,10 @@
265282
266283 if (m_walking >= MaxWalking)
267284 return walkinglist;
285+
286+ if (OnProgress != null)
287+ if (OnProgress(this, nlatlng, m_walking) == false)
288+ return walkinglist;
268289 }
269290 }
270291
@@ -385,10 +406,13 @@
385406
386407 if (m_walking >= MaxWalking)
387408 return walkinglist;
409+
410+ if (OnProgress != null)
411+ if (OnProgress(this, nlatlng, m_walking) == false)
412+ return walkinglist;
388413 }
389414 }
390415
391-
392416 /// <summary>
393417 /// キャッシュ
394418 /// </summary>
--- WhereTrainBuild/Dialog/WalkingDialog.Designer.cs (nonexistent)
+++ WhereTrainBuild/Dialog/WalkingDialog.Designer.cs (revision 53)
@@ -0,0 +1,75 @@
1+namespace WhereTrainBuild.Dialog
2+{
3+ partial class WalkingDialog
4+ {
5+ /// <summary>
6+ /// Required designer variable.
7+ /// </summary>
8+ private System.ComponentModel.IContainer components = null;
9+
10+ /// <summary>
11+ /// Clean up any resources being used.
12+ /// </summary>
13+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
14+ protected override void Dispose(bool disposing)
15+ {
16+ if (disposing && (components != null))
17+ {
18+ components.Dispose();
19+ }
20+ base.Dispose(disposing);
21+ }
22+
23+ #region Windows Form Designer generated code
24+
25+ /// <summary>
26+ /// Required method for Designer support - do not modify
27+ /// the contents of this method with the code editor.
28+ /// </summary>
29+ private void InitializeComponent()
30+ {
31+ this.StopBtn = new System.Windows.Forms.Button();
32+ this.CountLbl = new System.Windows.Forms.Label();
33+ this.SuspendLayout();
34+ //
35+ // StopBtn
36+ //
37+ this.StopBtn.Location = new System.Drawing.Point(29, 56);
38+ this.StopBtn.Name = "StopBtn";
39+ this.StopBtn.Size = new System.Drawing.Size(102, 27);
40+ this.StopBtn.TabIndex = 0;
41+ this.StopBtn.Text = "停止";
42+ this.StopBtn.UseVisualStyleBackColor = true;
43+ this.StopBtn.Click += new System.EventHandler(this.StopBtn_Click);
44+ //
45+ // CountLbl
46+ //
47+ this.CountLbl.AutoSize = true;
48+ this.CountLbl.Location = new System.Drawing.Point(22, 17);
49+ this.CountLbl.Name = "CountLbl";
50+ this.CountLbl.Size = new System.Drawing.Size(11, 12);
51+ this.CountLbl.TabIndex = 1;
52+ this.CountLbl.Text = "0";
53+ //
54+ // WalkingDialog
55+ //
56+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
57+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
58+ this.ClientSize = new System.Drawing.Size(159, 95);
59+ this.Controls.Add(this.CountLbl);
60+ this.Controls.Add(this.StopBtn);
61+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
62+ this.Name = "WalkingDialog";
63+ this.Text = "線路解析";
64+ this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.WalkingDialog_FormClosed);
65+ this.ResumeLayout(false);
66+ this.PerformLayout();
67+
68+ }
69+
70+ #endregion
71+
72+ private System.Windows.Forms.Button StopBtn;
73+ public System.Windows.Forms.Label CountLbl;
74+ }
75+}
\ No newline at end of file
--- WhereTrainBuild/Dialog/WalkingDialog.cs (nonexistent)
+++ WhereTrainBuild/Dialog/WalkingDialog.cs (revision 53)
@@ -0,0 +1,51 @@
1+using System;
2+using System.Collections.Generic;
3+using System.ComponentModel;
4+using System.Data;
5+using System.Drawing;
6+using System.Linq;
7+using System.Text;
8+using System.Threading.Tasks;
9+using System.Windows.Forms;
10+
11+namespace WhereTrainBuild.Dialog
12+{
13+ /// <summary>
14+ /// 線路解析ダイアログ
15+ /// </summary>
16+ public partial class WalkingDialog : Form
17+ {
18+ /// <summary>
19+ /// コンストラクタ
20+ /// </summary>
21+ public WalkingDialog()
22+ {
23+ InitializeComponent();
24+ }
25+
26+ /// <summary>
27+ /// 停止フラグ
28+ /// </summary>
29+ public volatile bool Terminate = false;
30+
31+ /// <summary>
32+ /// 停止ボタン押下
33+ /// </summary>
34+ /// <param name="sender"></param>
35+ /// <param name="e"></param>
36+ private void StopBtn_Click(object sender, EventArgs e)
37+ {
38+ Terminate = true;
39+ }
40+
41+ /// <summary>
42+ /// 閉じた
43+ /// </summary>
44+ /// <param name="sender"></param>
45+ /// <param name="e"></param>
46+ private void WalkingDialog_FormClosed(object sender, FormClosedEventArgs e)
47+ {
48+ Terminate = true;
49+ }
50+ }
51+}
--- WhereTrainBuild/MapForm.cs (revision 52)
+++ WhereTrainBuild/MapForm.cs (revision 53)
@@ -8,12 +8,13 @@
88 using System.Text;
99 using System.Windows.Forms;
1010 using System.Linq;
11+using System.Threading.Tasks;
1112
1213 using WhereTrainBuild.MapUtil;
1314 using WhereTrainBuild.MapUtil.Data;
14-using WhereTrainBuild.Net;
1515 using WhereTrainBuild.Dialog;
1616 using WhereTrainBuild.AI;
17+using WhereTrainBuild.MapUtil.View;
1718
1819 namespace WhereTrainBuild
1920 {
@@ -1055,10 +1056,82 @@
10551056 }
10561057
10571058 /// <summary>
1059+ /// 解析中ポイント表示
1060+ /// </summary>
1061+ protected class WalkPoint : WhereTrainBuild.MapUtil.View.ViewPointIF
1062+ {
1063+ /// <summary>
1064+ /// 緯度経度
1065+ /// </summary>
1066+ protected latlontool.latlng m_point = new latlontool.latlng();
1067+
1068+ public latlontool.latlng Point
1069+ {
1070+ set
1071+ {
1072+ lock (m_point)
1073+ {
1074+ m_point.Set(value);
1075+ }
1076+ }
1077+ }
1078+
1079+ /// <summary>
1080+ /// コンストラクタ
1081+ /// </summary>
1082+ public WalkPoint()
1083+ {
1084+ }
1085+
1086+ /// <summary>
1087+ /// 描画
1088+ /// </summary>
1089+ /// <param name="viewreqinfo">描画情報</param>
1090+ /// <returns>True..描画範囲内 False..範囲外</returns>
1091+ public bool Draw(ViewRequestInfo viewreqinfo)
1092+ {
1093+ //描画座標クリップ領域
1094+ Rectangle cliparea = viewreqinfo.ClipArea();
1095+
1096+ double dMyPositionX = 0;
1097+ double dMyPositionY = 0;
1098+
1099+ lock (m_point)
1100+ {
1101+ //メルカトル座標に変換
1102+ MercatorTrans.Trans(m_point.lat / 180.0d * Math.PI, m_point.lng / 180.0d * Math.PI, viewreqinfo.ZoomLevel, ref dMyPositionX, ref dMyPositionY);
1103+ }
1104+
1105+ //クリップ領域チェック
1106+ if (cliparea.X > dMyPositionX || dMyPositionX > cliparea.Right ||
1107+ cliparea.Y > dMyPositionY || dMyPositionY > cliparea.Bottom)
1108+ return false;
1109+
1110+ int iX = (int)((dMyPositionX - cliparea.Left) * viewreqinfo.Scale);
1111+ int iY = (int)((cliparea.Bottom - dMyPositionY) * viewreqinfo.Scale);
1112+
1113+ viewreqinfo.ViewGraphics.DrawArc(new Pen(Color.Red, 5), iX, iY, 5, 5, 0, 360);
1114+
1115+ return true;
1116+ }
1117+
1118+ /// <summary>
1119+ /// 当たり判定
1120+ /// </summary>
1121+ /// <param name="iX">画像X座標</param>
1122+ /// <param name="iY">画像Y座標</param>
1123+ /// <returns>True..範囲内 False..範囲外</returns>
1124+ public bool IsHit(int iX, int iY, ViewRequestInfo viewreqinfo)
1125+ {
1126+ return false;
1127+ }
1128+ }
1129+
1130+ /// <summary>
10581131 /// ライン解析
10591132 /// </summary>
10601133 /// <param name="crossresult"></param>
1061- protected void WalkLine(OnCrossLineResult crossresult, int iFunc = 0 )
1134+ protected async void WalkLine(OnCrossLineResult crossresult, int iFunc = 0 )
10621135 {
10631136 latlontool.latlng prevposition = null, targetposition = null, startposition = null, endposition = null;
10641137 int iInterIdx = 0;
@@ -1120,53 +1193,111 @@
11201193
11211194 var vdo = Math.Atan2(dY2 - dY1, dX2 - dX1);
11221195 var vector = new PointF((float)Math.Cos(vdo), (float)Math.Sin(vdo));
1123- var walker = new LineWalker(MapViewCnt.TileManager);
1196+ var walkpoint = new WalkPoint();
11241197
1125- List<latlontool.latlng> walklist = null;
1126- switch(iFunc)
1198+ try
11271199 {
1128- case 1:
1129- walklist = walker.Walk2(startposition, vector, endposition);
1130- break;
1200+ Enabled = false;
1201+ MapViewCnt.ViewArea.Add(walkpoint);
11311202
1132- case 2:
1133- walklist = walker.Walk3(startposition, vector, endposition);
1134- break;
1203+ using( var walkdlg = new WalkingDialog() )
1204+ {
1205+ var walker = new LineWalker(MapViewCnt.TileManager);
11351206
1136- default:
1137- walklist = walker.Walk(startposition, vector, endposition);
1138- break;
1139- }
1207+ walker.OnProgress += (owner, walkingpoint, walkcount) =>
1208+ {
1209+ if (walkdlg.Terminate == true)
1210+ {
1211+ return false;
1212+ }
11401213
1141- //最適化
1142- walklist = walker.Optimisation(walklist);
1214+ if(walkcount%10 == 0 )
1215+ {
1216+ Invoke((Action)(() =>
1217+ {
1218+ walkdlg.CountLbl.Text = $"{walkcount}";
11431219
1144- bool bFirst = false;
1145- int iPathIdx = iInterIdx;
1146- foreach (var walk in walklist)
1147- {
1148- //先頭は、ゴミになりやすいので捨てる
1149- if (bFirst == false)
1150- {
1151- bFirst = true;
1152- continue;
1153- }
1220+ walkpoint.Point = walkingpoint;
11541221
1155- //経由地
1156- var position = new TrainPath.Position();
1157- position.Latitude = walk.lat;
1158- position.Longitude = walk.lng;
1222+ MapViewCnt.RefreshImage();
1223+ }));
1224+ }
11591225
1160- int interIdx = Math.Min(crossresult.A, crossresult.B);
1226+ return true;
1227+ };
11611228
1162- crossresult.Path.InsertPosition(iPathIdx, position);
1163- iPathIdx += iIndexDelta;
1229+ walkdlg.Load += async (dlg, args) =>
1230+ {
1231+ await Task.Run(() =>
1232+ {
1233+ try
1234+ {
1235+ List<latlontool.latlng> walkpointlist = null;
1236+
1237+ switch (iFunc)
1238+ {
1239+ case 1:
1240+ walkpointlist = walker.Walk2(startposition, vector, endposition);
1241+ break;
1242+
1243+ case 2:
1244+ walkpointlist = walker.Walk3(startposition, vector, endposition);
1245+ break;
1246+
1247+ default:
1248+ walkpointlist = walker.Walk(startposition, vector, endposition);
1249+ break;
1250+ }
1251+
1252+ //最適化
1253+ walkpointlist = walker.Optimisation(walkpointlist);
1254+
1255+ bool bFirst = false;
1256+ int iPathIdx = iInterIdx;
1257+ foreach (var walk in walkpointlist)
1258+ {
1259+ //先頭は、ゴミになりやすいので捨てる
1260+ if (bFirst == false)
1261+ {
1262+ bFirst = true;
1263+ continue;
1264+ }
1265+
1266+ //経由地
1267+ var position = new TrainPath.Position();
1268+ position.Latitude = walk.lat;
1269+ position.Longitude = walk.lng;
1270+
1271+ int interIdx = Math.Min(crossresult.A, crossresult.B);
1272+
1273+ crossresult.Path.InsertPosition(iPathIdx, position);
1274+ iPathIdx += iIndexDelta;
1275+ }
1276+ }
1277+ finally
1278+ {
1279+ Invoke((Action)(() =>
1280+ {
1281+ //終了
1282+ walkdlg.Close();
1283+ }));
1284+ }
1285+ });
1286+ };
1287+
1288+ walkdlg.ShowDialog(this);
1289+ }
11641290 }
1291+ finally
1292+ {
1293+ Enabled = true;
11651294
1295+ MapViewCnt.ViewArea.Del(walkpoint);
1296+ }
1297+
11661298 MapViewCnt.RefreshImage();
11671299 }
11681300
1169-
11701301 /// <summary>
11711302 /// 駅削除
11721303 /// </summary>
Show on old repository browser