TrafficAreaModel.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using AGV_WPF_Global;
  6. using System.ComponentModel;
  7. namespace AGV_WPF.Models
  8. {
  9. public class TrafficAreaModel : INotifyPropertyChanged
  10. {
  11. public int TrafficNum { get; set; } //管制区编号
  12. public string TrafficName { get; set; } //管制区别名
  13. public AGVInfoModel MainAgv { get; set; } //管制区主机
  14. public DateTime EnterTime { get; set; } //管制区主机
  15. public bool IsTraffic { get; set; } //管制区主机
  16. private IList<AGVInfoModel> ListAgvQueue; //排队AGV
  17. private IList<int> ListMark; //包含的地标卡号
  18. public IList<AGVInfoModel> listAgvQueue
  19. {
  20. get
  21. {
  22. if (ListAgvQueue != null)
  23. {
  24. return ListAgvQueue;
  25. }
  26. else
  27. {
  28. ListAgvQueue = new List<AGVInfoModel>();
  29. return ListAgvQueue;
  30. }
  31. }
  32. }
  33. public IList<int> listMark
  34. {
  35. get
  36. {
  37. if (ListMark != null)
  38. {
  39. return ListMark;
  40. }
  41. else
  42. {
  43. ListMark = new List<int>();
  44. return ListMark;
  45. }
  46. }
  47. }
  48. object objLock = new object();
  49. public event PropertyChangedEventHandler PropertyChanged;
  50. //有agv进入该管制区
  51. public bool InTraffic(AGVInfoModel agv)
  52. {
  53. bool re = false;
  54. if (!this.listAgvQueue.Contains(agv))
  55. {
  56. lock (objLock)
  57. {
  58. this.listAgvQueue.Add(agv);
  59. re = true;
  60. }
  61. }
  62. if (this.MainAgv == null)
  63. {
  64. if (this.listAgvQueue.Count > 0)
  65. {
  66. this.MainAgv = this.listAgvQueue[0];
  67. this.IsTraffic = true;
  68. if (agv == this.listAgvQueue[0])
  69. {
  70. agv.TrafficFlag = false;
  71. agv.TRAFFICAGV = null;
  72. re = true;
  73. }
  74. else
  75. {
  76. agv.TrafficFlag = true;
  77. agv.TRAFFICAGV = this.MainAgv;
  78. re = true;
  79. }
  80. }
  81. }
  82. else
  83. {
  84. if (this.MainAgv == agv)
  85. {
  86. agv.TRAFFICAGV = null;
  87. agv.TrafficFlag = false;
  88. re = true;
  89. }
  90. else
  91. {
  92. agv.TRAFFICAGV = this.MainAgv;
  93. agv.TrafficFlag = true;
  94. re = true;
  95. }
  96. }
  97. return re;
  98. }
  99. //有AGV进入混合管制区(交叉区域)
  100. public bool InMixTraffic(AGVInfoModel agv)
  101. {
  102. bool re = false;
  103. if (!this.listAgvQueue.Contains(agv))
  104. {
  105. lock (objLock)
  106. {
  107. this.listAgvQueue.Insert(0, agv);
  108. re = true;
  109. }
  110. }
  111. if (this.MainAgv == null)
  112. {
  113. if (this.listAgvQueue.Count > 0)
  114. {
  115. this.MainAgv = this.listAgvQueue[0];
  116. this.IsTraffic = true;
  117. if (agv == this.listAgvQueue[0])
  118. {
  119. agv.TrafficFlag = false;
  120. agv.TRAFFICAGV = null;
  121. re = true;
  122. }
  123. else
  124. {
  125. agv.TrafficFlag = true;
  126. agv.TRAFFICAGV = this.MainAgv;
  127. re = true;
  128. }
  129. }
  130. }
  131. else
  132. {
  133. if (this.MainAgv == agv)
  134. {
  135. agv.TRAFFICAGV = null;
  136. agv.TrafficFlag = false;
  137. re = true;
  138. }
  139. else
  140. {
  141. agv.TRAFFICAGV = this.MainAgv;
  142. agv.TrafficFlag = true;
  143. re = true;
  144. }
  145. }
  146. return re;
  147. }
  148. //有agv退出该管制区
  149. public bool OutTraffic(AGVInfoModel agv)
  150. {
  151. bool re = false;
  152. if (this.listAgvQueue.Contains(agv))
  153. {
  154. lock (objLock)
  155. {
  156. this.listAgvQueue.Remove(agv);
  157. agv.IsMainAgv = false;
  158. agv.TrafficFlag = false;
  159. //agv.TRAFFICNUM.Remove(this);
  160. agv.TRAFFICAGV = null;
  161. }
  162. }
  163. //更新管制区状态
  164. if (agv == this.MainAgv)
  165. {
  166. if (this.listAgvQueue.Count > 0)
  167. {
  168. this.IsTraffic = true;
  169. AGVInfoModel tempAgv = this.listAgvQueue[0];
  170. //获取AGV对象
  171. tempAgv.TrafficFlag = false;
  172. tempAgv.IsMainAgv = true;
  173. tempAgv.TRAFFICAGV = null;
  174. this.MainAgv = tempAgv;
  175. foreach (var i in this.listAgvQueue)
  176. {
  177. if (i != this.MainAgv)
  178. {
  179. i.TRAFFICAGV = this.MainAgv;
  180. }
  181. }
  182. }
  183. else
  184. {
  185. this.IsTraffic = false;
  186. this.MainAgv = null;
  187. }
  188. re = true;
  189. }
  190. return re;
  191. }
  192. public void AGVINTER0(AGVInfoModel agv, bool falg)
  193. {
  194. bool agvfirst = falg;
  195. if (!this.IsTraffic) { this.IsTraffic = true; }
  196. if (this.MainAgv != agv && !this.listAgvQueue.Contains(agv))
  197. ++agv.ReleaseCount;
  198. //if (!GlobalPara.IsRealOpenSystem)
  199. //{
  200. // if (!GlobalPara.dicTraffic.ContainsKey(this.TrafficNum))
  201. // {
  202. // GlobalPara.dicTraffic.Add(this.TrafficNum, agv);
  203. // this.MainAgv = agv;
  204. // if (this.listAgvQueue.Contains(agv))
  205. // {
  206. // this.listAgvQueue.Remove(agv);
  207. // }
  208. // if (!this.IsTraffic)
  209. // {
  210. // this.IsTraffic = true;
  211. // }
  212. // }
  213. // else
  214. // {
  215. // if (this.listMark.Contains(agv.MARKNUM))
  216. // {
  217. // int index = this.listMark.IndexOf(agv.MARKNUM);
  218. // if (index > this.listMark.IndexOf((GlobalPara.dicTraffic[this.TrafficNum].MARKNUM)))
  219. // {
  220. // this.MainAgv = agv;
  221. // if (!this.IsTraffic)
  222. // {
  223. // this.IsTraffic = true;
  224. // }
  225. // GlobalPara.dicTraffic[this.TrafficNum].TRAFFICAGV = this.MainAgv;
  226. // GlobalPara.dicTraffic[this.TrafficNum].TrafficFlag = true;
  227. // if (this.listAgvQueue.Contains(agv))
  228. // {
  229. // this.listAgvQueue.Remove(agv);
  230. // }
  231. // if (!this.listAgvQueue.Contains(GlobalPara.dicTraffic[this.TrafficNum]))
  232. // {
  233. // this.listAgvQueue.Add(GlobalPara.dicTraffic[this.TrafficNum]);
  234. // }
  235. // GlobalPara.dicTraffic[this.TrafficNum] = agv;
  236. // }
  237. // else
  238. // {
  239. // if (index == this.listMark.IndexOf((GlobalPara.dicTraffic[this.TrafficNum].MARKNUM)))
  240. // {
  241. // int trafficAGVNum = GlobalPara.dicTraffic[this.TrafficNum].AGVNUM;
  242. // int trafficIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == agv.AGVNUM.ToString());
  243. // int curIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == agv.AGVNUM.ToString());
  244. // if (trafficIndex > -1 && curIndex > -1)
  245. // {
  246. // string[] trafficAry = GlobalPara.lastReadMarkList[trafficIndex].Split(',');
  247. // string[] curAry = GlobalPara.lastReadMarkList[curIndex].Split(',');
  248. // DateTime trTraTime, curTime;
  249. // if (trafficAry.Length > 2 && curAry.Length > 2 && trafficAry[1] == curAry[1])
  250. // {
  251. // bool b1 = DateTime.TryParse(trafficAry[2], out trTraTime);
  252. // bool b2 = DateTime.TryParse(curAry[2], out curTime);
  253. // if (b1 && b2 && curTime < trTraTime)
  254. // {
  255. // this.MainAgv = agv;
  256. // if (!this.IsTraffic)
  257. // {
  258. // this.IsTraffic = true;
  259. // }
  260. // GlobalPara.dicTraffic[this.TrafficNum].TRAFFICAGV = null;
  261. // GlobalPara.dicTraffic[this.TrafficNum].TrafficFlag = false;
  262. // GlobalPara.dicTraffic[this.TrafficNum] = agv;
  263. // }
  264. // else
  265. // {
  266. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  267. // agv.TrafficFlag = true;
  268. // if (!this.listAgvQueue.Contains(agv))
  269. // {
  270. // this.listAgvQueue.Add(agv);
  271. // }
  272. // }
  273. // }
  274. // else
  275. // {
  276. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  277. // agv.TrafficFlag = true;
  278. // if (!this.listAgvQueue.Contains(agv))
  279. // {
  280. // this.listAgvQueue.Add(agv);
  281. // }
  282. // }
  283. // }
  284. // else
  285. // {
  286. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  287. // agv.TrafficFlag = true;
  288. // if (!this.listAgvQueue.Contains(agv))
  289. // {
  290. // this.listAgvQueue.Add(agv);
  291. // }
  292. // }
  293. // }
  294. // else
  295. // {
  296. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  297. // agv.TrafficFlag = true;
  298. // if (!this.listAgvQueue.Contains(agv))
  299. // {
  300. // this.listAgvQueue.Add(agv);
  301. // }
  302. // }
  303. // }
  304. // }
  305. // }
  306. //}
  307. //else
  308. {
  309. if (this.MainAgv != null)
  310. {
  311. #region 管制区已经有主机占领了
  312. if (this.MainAgv != agv)
  313. {
  314. if (this.listMark.Contains(agv.MARKNUM))
  315. {
  316. int index = this.listMark.IndexOf(agv.MARKNUM);
  317. if (index < this.listMark.IndexOf(this.MainAgv.MARKNUM))
  318. {
  319. if (this.listAgvQueue.Contains(agv))
  320. {
  321. this.listAgvQueue.Remove(agv);
  322. }
  323. // this.MainAgv.TRAFFICAGV = agv;
  324. // this.MainAgv.TrafficFlag = true;
  325. if (!this.listAgvQueue.Contains(this.MainAgv))
  326. {
  327. this.listAgvQueue.Add(this.MainAgv);
  328. }
  329. for (int i = 0; i < this.listAgvQueue.Count; i++)
  330. {
  331. this.listAgvQueue[i].TRAFFICAGV = agv;
  332. this.listAgvQueue[i].TrafficFlag = true;
  333. }
  334. this.MainAgv = agv;
  335. if (!this.IsTraffic)
  336. {
  337. this.IsTraffic = true;
  338. }
  339. }
  340. else
  341. {
  342. if (index == this.listMark.IndexOf(this.MainAgv.MARKNUM))
  343. {
  344. // int trafficAGVNum = GlobalPara.dicTraffic[this.TrafficNum].AGVNUM;
  345. // int trafficIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == this.MainAgv.AGVNUM.ToString());
  346. // int curIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == agv.AGVNUM.ToString());
  347. // if (trafficIndex > -1 && curIndex > -1)
  348. // {
  349. // string[] trafficAry = GlobalPara.lastReadMarkList[trafficIndex].Split(',');
  350. // string[] curAry = GlobalPara.lastReadMarkList[curIndex].Split(',');
  351. DateTime trTraTime, curTime;
  352. // if (trafficAry.Length > 2 && curAry.Length > 2 && trafficAry[1] == curAry[1])
  353. // {
  354. // bool b1 = DateTime.TryParse(trafficAry[2], out trTraTime);
  355. // bool b2 = DateTime.TryParse(curAry[2], out curTime);
  356. // if (b1 && b2 && curTime < trTraTime)
  357. if (agv.LastModifyMarkTime < this.MainAgv.LastModifyMarkTime)
  358. {
  359. if (this.listAgvQueue.Contains(agv))
  360. {
  361. this.listAgvQueue.Remove(agv);
  362. }
  363. //this.MainAgv.TRAFFICAGV = agv;
  364. //this.MainAgv.TrafficFlag = true;
  365. if (!this.listAgvQueue.Contains(this.MainAgv))
  366. {
  367. this.listAgvQueue.Add(this.MainAgv);
  368. }
  369. for (int i = 0; i < this.listAgvQueue.Count; i++)
  370. {
  371. this.listAgvQueue[i].TRAFFICAGV = agv;
  372. this.listAgvQueue[i].TrafficFlag = true;
  373. }
  374. this.MainAgv = agv;
  375. if (!this.IsTraffic)
  376. {
  377. this.IsTraffic = true;
  378. }
  379. }
  380. else
  381. {
  382. agv.TRAFFICAGV = this.MainAgv;
  383. agv.TrafficFlag = true;
  384. if (!this.listAgvQueue.Contains(agv))
  385. {
  386. this.listAgvQueue.Add(agv);
  387. }
  388. }
  389. // }
  390. // else
  391. // {
  392. // agv.TRAFFICAGV = this.MainAgv;
  393. // agv.TrafficFlag = true;
  394. // if (!this.listAgvQueue.Contains(agv))
  395. // {
  396. // this.listAgvQueue.Add(agv);
  397. // }
  398. // }
  399. //}
  400. //else
  401. //{
  402. // agv.TRAFFICAGV = this.MainAgv;
  403. // agv.TrafficFlag = true;
  404. // if (!this.listAgvQueue.Contains(agv))
  405. // {
  406. // this.listAgvQueue.Add(agv);
  407. // }
  408. //}
  409. }
  410. else
  411. {
  412. agv.TRAFFICAGV = this.MainAgv;
  413. agv.TrafficFlag = true;
  414. if (!this.listAgvQueue.Contains(agv))
  415. {
  416. this.listAgvQueue.Add(agv);
  417. }
  418. }
  419. }
  420. }
  421. #region 主机不是我,这个管制区不是我管制
  422. //foreach (var traffic in agv.TRAFFICNUM)
  423. //{
  424. // //如果我所管制的区域里的等候名单中有即将进入的这个管制区的主机
  425. // //表明将会发生死管现象,应该避免。所以在此检查一下。
  426. // if (traffic.listAgvQueue.Contains(this.MainAgv))
  427. // {
  428. // ReleaseMixMainAgv();
  429. // break;
  430. // }
  431. //}
  432. ////排队等候
  433. //agv.TRAFFICAGV = this.MainAgv;
  434. //if (!this.listAgvQueue.Contains(agv))
  435. //{
  436. // if (!agvfirst)//看是否进入交叉管制区
  437. // {
  438. // this.listAgvQueue.Add(agv);
  439. // }
  440. // else
  441. // {
  442. // this.listAgvQueue.Insert(0, agv);
  443. // }
  444. // //this.listAgvQueue.Add(agv);
  445. //}
  446. #endregion
  447. }
  448. else
  449. {
  450. #region 主机是我,这个管制区是我管制的
  451. agv.TRAFFICAGV = null;
  452. if (this.listAgvQueue.Contains(agv))
  453. {
  454. this.listAgvQueue.Remove(agv);
  455. }
  456. #endregion
  457. }
  458. #endregion
  459. }
  460. else
  461. {
  462. #region 这个管制区没有主机,我将成为主机占领该区
  463. // else
  464. {
  465. if (this.listAgvQueue.Count > 0 && this.listAgvQueue[0] != agv)
  466. {
  467. {
  468. this.MainAgv = this.listAgvQueue[0];
  469. this.listAgvQueue.RemoveAt(0);
  470. if (!agvfirst)//看是否进入交叉管制区修改
  471. {
  472. this.listAgvQueue.Add(agv);
  473. }
  474. else
  475. {
  476. this.listAgvQueue.Insert(0, agv);
  477. }
  478. }
  479. //this.listAgvQueue.Add(agv);
  480. }
  481. else
  482. {
  483. this.MainAgv = agv;
  484. agv.IsMainAgv = true;
  485. agv.TrafficFlag = false;//---罗国--2017-10-30成主机后状态变成不管制,为了解决互相管制的问题。
  486. foreach (var a in this.listAgvQueue)
  487. {
  488. a.TRAFFICAGV = agv;
  489. }
  490. if (this.listAgvQueue.Contains(agv))
  491. {
  492. this.listAgvQueue.Remove(agv);
  493. }
  494. //this.listAgvQueue.Add(agv);
  495. }
  496. }
  497. #endregion
  498. }
  499. }
  500. }
  501. //AGV进入管制区
  502. public void AGVINTER(AGVInfoModel agv, bool falg)
  503. {
  504. bool agvfirst = falg;
  505. if (!this.IsTraffic) { this.IsTraffic = true; }
  506. if (this.MainAgv != agv && !this.listAgvQueue.Contains(agv))
  507. ++agv.ReleaseCount;
  508. if (this.MainAgv != null)
  509. {
  510. #region 管制区已经有主机占领了
  511. if (this.MainAgv != agv)
  512. {
  513. #region 主机不是我,这个管制区不是我管制
  514. foreach (var traffic in agv.TRAFFICNUM)
  515. {
  516. //如果我所管制的区域里的等候名单中有即将进入的这个管制区的主机
  517. //表明将会发生死管现象,应该避免。所以在此检查一下。
  518. if (traffic.listAgvQueue.Contains(this.MainAgv))
  519. {
  520. ReleaseMixMainAgv();
  521. break;
  522. }
  523. }
  524. //排队等候
  525. agv.TRAFFICAGV = this.MainAgv;
  526. if (!this.listAgvQueue.Contains(agv))
  527. {
  528. if (!agvfirst)//看是否进入交叉管制区
  529. {
  530. this.listAgvQueue.Add(agv);
  531. }
  532. else
  533. {
  534. this.listAgvQueue.Insert(0, agv);
  535. }
  536. //this.listAgvQueue.Add(agv);
  537. }
  538. #endregion
  539. }
  540. else
  541. {
  542. #region 主机是我,这个管制区是我管制的
  543. agv.TRAFFICAGV = null;
  544. if (this.listAgvQueue.Contains(agv))
  545. {
  546. this.listAgvQueue.Remove(agv);
  547. }
  548. #endregion
  549. }
  550. #endregion
  551. }
  552. else
  553. {
  554. #region 这个管制区没有主机,我将成为主机占领该区
  555. if (this.listAgvQueue.Count > 0 && this.listAgvQueue[0] != agv)
  556. {
  557. this.MainAgv = this.listAgvQueue[0];
  558. this.listAgvQueue.RemoveAt(0);
  559. if (!agvfirst)//看是否进入交叉管制区修改
  560. {
  561. this.listAgvQueue.Add(agv);
  562. }
  563. else
  564. {
  565. this.listAgvQueue.Insert(0, agv);
  566. }
  567. //this.listAgvQueue.Add(agv);
  568. }
  569. else
  570. {
  571. this.MainAgv = agv;
  572. agv.IsMainAgv = true;
  573. agv.TrafficFlag = false;//---罗国--2017-10-30成主机后状态变成不管制,为了解决互相管制的问题。
  574. foreach (var a in this.listAgvQueue)
  575. {
  576. a.TRAFFICAGV = agv;
  577. }
  578. if (this.listAgvQueue.Contains(agv))
  579. {
  580. this.listAgvQueue.Remove(agv);
  581. }
  582. //this.listAgvQueue.Add(agv);
  583. }
  584. #endregion
  585. }
  586. }
  587. //AGV离开管制区
  588. public void AGVLEAVE(AGVInfoModel agv)
  589. {
  590. --agv.ReleaseCount;
  591. //解除管制
  592. if (this.MainAgv == agv)
  593. {
  594. this.IsTraffic = false;
  595. this.MainAgv = null;
  596. }
  597. else if (this.MainAgv == null)
  598. {
  599. this.IsTraffic = false;
  600. }
  601. if (this.listAgvQueue.Contains(agv))
  602. {
  603. this.listAgvQueue.Remove(agv);
  604. }
  605. if (agv.TRAFFICAGV != null && agv.TRAFFICAGV.TRAFFICNUM.Contains(this))
  606. {
  607. this.listAgvQueue.Insert(0, agv.TRAFFICAGV);
  608. }
  609. }
  610. public void ReleaseAgv()
  611. {
  612. AGVInfoModel reAgv = this.listAgvQueue[0];
  613. if (reAgv.ReleaseCount > 1)//本来是按照1来判断
  614. {
  615. #region 它相对这个管制区是管制者,但它不被允许放行,因为还有其他区域的管制者管制着它。
  616. this.IsTraffic = true;
  617. this.MainAgv = reAgv;
  618. if (this.listAgvQueue.Contains(reAgv))
  619. {
  620. this.listAgvQueue.Remove(reAgv);
  621. }
  622. reAgv.IsMainAgv = true;
  623. foreach (var a in this.listAgvQueue)
  624. {
  625. a.TRAFFICAGV = reAgv;
  626. }
  627. //判断AGV是否可以被放行
  628. bool fx = true;
  629. foreach (var t in reAgv.TRAFFICNUM)
  630. {
  631. if (t.MainAgv != reAgv)
  632. {
  633. fx = false;
  634. }
  635. }
  636. if (fx)
  637. {
  638. reAgv.TrafficFlag = false;
  639. this.AGVINTER(reAgv, false);
  640. }
  641. else
  642. {
  643. reAgv.TrafficFlag = true;
  644. }
  645. #endregion
  646. }
  647. else
  648. {
  649. //reAgv.TrafficFlag = false;
  650. this.AGVINTER(reAgv, false);
  651. }
  652. }
  653. public void ReleaseAgv(AGVInfoModel reAgv)
  654. {
  655. if (reAgv.ReleaseCount > 1)
  656. {
  657. #region 它相对这个管制区是管制者,但它不被允许放行,因为还有其他区域的管制者管制着它。
  658. this.IsTraffic = true;
  659. this.MainAgv = reAgv;
  660. if (this.listAgvQueue.Contains(reAgv))
  661. {
  662. this.listAgvQueue.Remove(reAgv);
  663. }
  664. reAgv.IsMainAgv = true;
  665. foreach (var a in this.listAgvQueue)
  666. {
  667. a.TRAFFICAGV = reAgv;
  668. }
  669. //判断AGV是否可以被放行
  670. bool fx = true;
  671. foreach (var t in reAgv.TRAFFICNUM)
  672. {
  673. if (t.MainAgv != reAgv)
  674. {
  675. fx = false;
  676. }
  677. }
  678. if (fx)
  679. {
  680. reAgv.TrafficFlag = false;//放行之前把标识位给置为false
  681. this.AGVINTER(reAgv, false);
  682. }
  683. else
  684. {
  685. reAgv.TrafficFlag = true;
  686. }
  687. #endregion
  688. }
  689. else
  690. {
  691. //reAgv.TrafficFlag = false;
  692. this.AGVINTER(reAgv, false);
  693. }
  694. }
  695. public void ReleaseMainAgv()
  696. {
  697. if (this.MainAgv.ReleaseCount < 2)//被管制的数量小于2时,说明管制区里只有1车被管制,则主机可以随便走。
  698. {
  699. this.MainAgv.TrafficFlag = false;
  700. if (this.MainAgv.TRAFFICAGV != null) this.MainAgv.TRAFFICAGV = null;
  701. if (this.listAgvQueue.Contains(this.MainAgv)) this.listAgvQueue.Remove(this.MainAgv);
  702. }
  703. }
  704. public void ReleaseMixMainAgv()
  705. {
  706. this.MainAgv.TrafficFlag = false;
  707. if (this.MainAgv.TRAFFICAGV != null) this.MainAgv.TRAFFICAGV = null;
  708. if (this.listAgvQueue.Contains(this.MainAgv)) this.listAgvQueue.Remove(this.MainAgv);
  709. }
  710. public int Blockade(AGVInfoModel agv)
  711. {
  712. if (!this.IsTraffic) this.IsTraffic = true; //确保管制区的状态是管制中,封锁该管制区。
  713. if (this.MainAgv != null)
  714. {
  715. if (this.MainAgv != agv)
  716. {
  717. this.listAgvQueue.Add(agv); //把该AGV加入到管制区前的等候队伍中等候。
  718. return 2;
  719. }
  720. }
  721. else
  722. {
  723. this.MainAgv = agv;//直接让该AGV占领该管制区成为主机。
  724. return 1;
  725. }
  726. return 0;
  727. }
  728. private void NotifyPropertyChanged(String info)
  729. {
  730. if (PropertyChanged != null)
  731. {
  732. PropertyChanged(this, new PropertyChangedEventArgs(info));
  733. }
  734. }
  735. public void Dispose()
  736. {
  737. throw new NotImplementedException();
  738. }
  739. }
  740. }