TrafficAreaModel.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. //AGV进入管制区
  193. public void AGVINTER(AGVInfoModel agv, bool falg)
  194. {
  195. bool agvfirst = falg;
  196. if (!this.IsTraffic) { this.IsTraffic = true; }
  197. if (this.MainAgv != agv && !this.listAgvQueue.Contains(agv))
  198. ++agv.ReleaseCount;
  199. if (this.MainAgv != null)
  200. {
  201. #region 管制区已经有主机占领了
  202. if (this.MainAgv != agv)
  203. {
  204. #region 主机不是我,这个管制区不是我管制
  205. foreach (var traffic in agv.TRAFFICNUM)
  206. {
  207. //如果我所管制的区域里的等候名单中有即将进入的这个管制区的主机
  208. //表明将会发生死管现象,应该避免。所以在此检查一下。
  209. if (traffic.listAgvQueue.Contains(this.MainAgv))
  210. {
  211. ReleaseMixMainAgv();
  212. break;
  213. }
  214. }
  215. //排队等候
  216. agv.TRAFFICAGV = this.MainAgv;
  217. if (!this.listAgvQueue.Contains(agv))
  218. {
  219. if (!agvfirst)//看是否进入交叉管制区
  220. {
  221. this.listAgvQueue.Add(agv);
  222. }
  223. else
  224. {
  225. this.listAgvQueue.Insert(0, agv);
  226. }
  227. //this.listAgvQueue.Add(agv);
  228. }
  229. #endregion
  230. }
  231. else
  232. {
  233. #region 主机是我,这个管制区是我管制的
  234. agv.TRAFFICAGV = null;
  235. if (this.listAgvQueue.Contains(agv))
  236. {
  237. this.listAgvQueue.Remove(agv);
  238. }
  239. #endregion
  240. }
  241. #endregion
  242. }
  243. else
  244. {
  245. #region 这个管制区没有主机,我将成为主机占领该区
  246. if (this.listAgvQueue.Count > 0 && this.listAgvQueue[0] != agv)
  247. {
  248. this.MainAgv = this.listAgvQueue[0];
  249. this.listAgvQueue.RemoveAt(0);
  250. if (!agvfirst)//看是否进入交叉管制区修改
  251. {
  252. this.listAgvQueue.Add(agv);
  253. }
  254. else
  255. {
  256. this.listAgvQueue.Insert(0, agv);
  257. }
  258. //this.listAgvQueue.Add(agv);
  259. }
  260. else
  261. {
  262. this.MainAgv = agv;
  263. agv.IsMainAgv = true;
  264. agv.TrafficFlag = false;//---罗国--2017-10-30成主机后状态变成不管制,为了解决互相管制的问题。
  265. foreach (var a in this.listAgvQueue)
  266. {
  267. a.TRAFFICAGV = agv;
  268. }
  269. if (this.listAgvQueue.Contains(agv))
  270. {
  271. this.listAgvQueue.Remove(agv);
  272. }
  273. //this.listAgvQueue.Add(agv);
  274. }
  275. #endregion
  276. }
  277. }
  278. //AGV进入管制区
  279. public void AGVINTER0(AGVInfoModel agv, bool falg)
  280. {
  281. bool agvfirst = falg;
  282. if (!this.IsTraffic) { this.IsTraffic = true; }
  283. if (this.MainAgv != agv && !this.listAgvQueue.Contains(agv))
  284. ++agv.ReleaseCount;
  285. //if (!GlobalPara.IsRealOpenSystem)
  286. //{
  287. // if (!GlobalPara.dicTraffic.ContainsKey(this.TrafficNum))
  288. // {
  289. // GlobalPara.dicTraffic.Add(this.TrafficNum, agv);
  290. // this.MainAgv = agv;
  291. // if (this.listAgvQueue.Contains(agv))
  292. // {
  293. // this.listAgvQueue.Remove(agv);
  294. // }
  295. // if (!this.IsTraffic)
  296. // {
  297. // this.IsTraffic = true;
  298. // }
  299. // }
  300. // else
  301. // {
  302. // if (this.listMark.Contains(agv.MARKNUM))
  303. // {
  304. // int index = this.listMark.IndexOf(agv.MARKNUM);
  305. // if (index > this.listMark.IndexOf((GlobalPara.dicTraffic[this.TrafficNum].MARKNUM)))
  306. // {
  307. // this.MainAgv = agv;
  308. // if (!this.IsTraffic)
  309. // {
  310. // this.IsTraffic = true;
  311. // }
  312. // GlobalPara.dicTraffic[this.TrafficNum].TRAFFICAGV = this.MainAgv;
  313. // GlobalPara.dicTraffic[this.TrafficNum].TrafficFlag = true;
  314. // if (this.listAgvQueue.Contains(agv))
  315. // {
  316. // this.listAgvQueue.Remove(agv);
  317. // }
  318. // if (!this.listAgvQueue.Contains(GlobalPara.dicTraffic[this.TrafficNum]))
  319. // {
  320. // this.listAgvQueue.Add(GlobalPara.dicTraffic[this.TrafficNum]);
  321. // }
  322. // GlobalPara.dicTraffic[this.TrafficNum] = agv;
  323. // }
  324. // else
  325. // {
  326. // if (index == this.listMark.IndexOf((GlobalPara.dicTraffic[this.TrafficNum].MARKNUM)))
  327. // {
  328. // int trafficAGVNum = GlobalPara.dicTraffic[this.TrafficNum].AGVNUM;
  329. // int trafficIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == agv.AGVNUM.ToString());
  330. // int curIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == agv.AGVNUM.ToString());
  331. // if (trafficIndex > -1 && curIndex > -1)
  332. // {
  333. // string[] trafficAry = GlobalPara.lastReadMarkList[trafficIndex].Split(',');
  334. // string[] curAry = GlobalPara.lastReadMarkList[curIndex].Split(',');
  335. // DateTime trTraTime, curTime;
  336. // if (trafficAry.Length > 2 && curAry.Length > 2 && trafficAry[1] == curAry[1])
  337. // {
  338. // bool b1 = DateTime.TryParse(trafficAry[2], out trTraTime);
  339. // bool b2 = DateTime.TryParse(curAry[2], out curTime);
  340. // if (b1 && b2 && curTime < trTraTime)
  341. // {
  342. // this.MainAgv = agv;
  343. // if (!this.IsTraffic)
  344. // {
  345. // this.IsTraffic = true;
  346. // }
  347. // GlobalPara.dicTraffic[this.TrafficNum].TRAFFICAGV = null;
  348. // GlobalPara.dicTraffic[this.TrafficNum].TrafficFlag = false;
  349. // GlobalPara.dicTraffic[this.TrafficNum] = agv;
  350. // }
  351. // else
  352. // {
  353. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  354. // agv.TrafficFlag = true;
  355. // if (!this.listAgvQueue.Contains(agv))
  356. // {
  357. // this.listAgvQueue.Add(agv);
  358. // }
  359. // }
  360. // }
  361. // else
  362. // {
  363. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  364. // agv.TrafficFlag = true;
  365. // if (!this.listAgvQueue.Contains(agv))
  366. // {
  367. // this.listAgvQueue.Add(agv);
  368. // }
  369. // }
  370. // }
  371. // else
  372. // {
  373. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  374. // agv.TrafficFlag = true;
  375. // if (!this.listAgvQueue.Contains(agv))
  376. // {
  377. // this.listAgvQueue.Add(agv);
  378. // }
  379. // }
  380. // }
  381. // else
  382. // {
  383. // agv.TRAFFICAGV = GlobalPara.dicTraffic[this.TrafficNum];
  384. // agv.TrafficFlag = true;
  385. // if (!this.listAgvQueue.Contains(agv))
  386. // {
  387. // this.listAgvQueue.Add(agv);
  388. // }
  389. // }
  390. // }
  391. // }
  392. // }
  393. //}
  394. //else
  395. {
  396. if (this.MainAgv != null)
  397. {
  398. #region 管制区已经有主机占领了
  399. if (this.MainAgv != agv)
  400. {
  401. if (this.listMark.Contains(agv.MARKNUM))
  402. {
  403. int index = this.listMark.IndexOf(agv.MARKNUM);
  404. if (index < this.listMark.IndexOf(this.MainAgv.MARKNUM))
  405. {
  406. if (this.listAgvQueue.Contains(agv))
  407. {
  408. this.listAgvQueue.Remove(agv);
  409. }
  410. // this.MainAgv.TRAFFICAGV = agv;
  411. // this.MainAgv.TrafficFlag = true;
  412. if (!this.listAgvQueue.Contains(this.MainAgv))
  413. {
  414. this.listAgvQueue.Add(this.MainAgv);
  415. }
  416. for (int i = 0; i < this.listAgvQueue.Count; i++)
  417. {
  418. this.listAgvQueue[i].TRAFFICAGV = agv;
  419. this.listAgvQueue[i].TrafficFlag = true;
  420. }
  421. this.MainAgv = agv;
  422. if (!this.IsTraffic)
  423. {
  424. this.IsTraffic = true;
  425. }
  426. }
  427. else
  428. {
  429. if (index == this.listMark.IndexOf(this.MainAgv.MARKNUM))
  430. {
  431. // int trafficAGVNum = GlobalPara.dicTraffic[this.TrafficNum].AGVNUM;
  432. // int trafficIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == this.MainAgv.AGVNUM.ToString());
  433. // int curIndex = GlobalPara.lastReadMarkList.FindIndex(o => o.Split(',')[0] == agv.AGVNUM.ToString());
  434. // if (trafficIndex > -1 && curIndex > -1)
  435. // {
  436. // string[] trafficAry = GlobalPara.lastReadMarkList[trafficIndex].Split(',');
  437. // string[] curAry = GlobalPara.lastReadMarkList[curIndex].Split(',');
  438. DateTime trTraTime, curTime;
  439. // if (trafficAry.Length > 2 && curAry.Length > 2 && trafficAry[1] == curAry[1])
  440. // {
  441. // bool b1 = DateTime.TryParse(trafficAry[2], out trTraTime);
  442. // bool b2 = DateTime.TryParse(curAry[2], out curTime);
  443. // if (b1 && b2 && curTime < trTraTime)
  444. if (agv.LastModifyMarkTime < this.MainAgv.LastModifyMarkTime)
  445. {
  446. if (this.listAgvQueue.Contains(agv))
  447. {
  448. this.listAgvQueue.Remove(agv);
  449. }
  450. //this.MainAgv.TRAFFICAGV = agv;
  451. //this.MainAgv.TrafficFlag = true;
  452. if (!this.listAgvQueue.Contains(this.MainAgv))
  453. {
  454. this.listAgvQueue.Add(this.MainAgv);
  455. }
  456. for (int i = 0; i < this.listAgvQueue.Count; i++)
  457. {
  458. this.listAgvQueue[i].TRAFFICAGV = agv;
  459. this.listAgvQueue[i].TrafficFlag = true;
  460. }
  461. this.MainAgv = agv;
  462. if (!this.IsTraffic)
  463. {
  464. this.IsTraffic = true;
  465. }
  466. }
  467. else
  468. {
  469. agv.TRAFFICAGV = this.MainAgv;
  470. agv.TrafficFlag = true;
  471. if (!this.listAgvQueue.Contains(agv))
  472. {
  473. this.listAgvQueue.Add(agv);
  474. }
  475. }
  476. // }
  477. // else
  478. // {
  479. // agv.TRAFFICAGV = this.MainAgv;
  480. // agv.TrafficFlag = true;
  481. // if (!this.listAgvQueue.Contains(agv))
  482. // {
  483. // this.listAgvQueue.Add(agv);
  484. // }
  485. // }
  486. //}
  487. //else
  488. //{
  489. // agv.TRAFFICAGV = this.MainAgv;
  490. // agv.TrafficFlag = true;
  491. // if (!this.listAgvQueue.Contains(agv))
  492. // {
  493. // this.listAgvQueue.Add(agv);
  494. // }
  495. //}
  496. }
  497. else
  498. {
  499. agv.TRAFFICAGV = this.MainAgv;
  500. agv.TrafficFlag = true;
  501. if (!this.listAgvQueue.Contains(agv))
  502. {
  503. this.listAgvQueue.Add(agv);
  504. }
  505. }
  506. }
  507. }
  508. #region 主机不是我,这个管制区不是我管制
  509. //foreach (var traffic in agv.TRAFFICNUM)
  510. //{
  511. // //如果我所管制的区域里的等候名单中有即将进入的这个管制区的主机
  512. // //表明将会发生死管现象,应该避免。所以在此检查一下。
  513. // if (traffic.listAgvQueue.Contains(this.MainAgv))
  514. // {
  515. // ReleaseMixMainAgv();
  516. // break;
  517. // }
  518. //}
  519. ////排队等候
  520. //agv.TRAFFICAGV = this.MainAgv;
  521. //if (!this.listAgvQueue.Contains(agv))
  522. //{
  523. // if (!agvfirst)//看是否进入交叉管制区
  524. // {
  525. // this.listAgvQueue.Add(agv);
  526. // }
  527. // else
  528. // {
  529. // this.listAgvQueue.Insert(0, agv);
  530. // }
  531. // //this.listAgvQueue.Add(agv);
  532. //}
  533. #endregion
  534. }
  535. else
  536. {
  537. #region 主机是我,这个管制区是我管制的
  538. agv.TRAFFICAGV = null;
  539. if (this.listAgvQueue.Contains(agv))
  540. {
  541. this.listAgvQueue.Remove(agv);
  542. }
  543. #endregion
  544. }
  545. #endregion
  546. }
  547. else
  548. {
  549. #region 这个管制区没有主机,我将成为主机占领该区
  550. // else
  551. {
  552. if (this.listAgvQueue.Count > 0 && this.listAgvQueue[0] != agv)
  553. {
  554. {
  555. this.MainAgv = this.listAgvQueue[0];
  556. this.listAgvQueue.RemoveAt(0);
  557. if (!agvfirst)//看是否进入交叉管制区修改
  558. {
  559. this.listAgvQueue.Add(agv);
  560. }
  561. else
  562. {
  563. this.listAgvQueue.Insert(0, agv);
  564. }
  565. }
  566. //this.listAgvQueue.Add(agv);
  567. }
  568. else
  569. {
  570. this.MainAgv = agv;
  571. agv.IsMainAgv = true;
  572. agv.TrafficFlag = false;//---罗国--2017-10-30成主机后状态变成不管制,为了解决互相管制的问题。
  573. foreach (var a in this.listAgvQueue)
  574. {
  575. a.TRAFFICAGV = agv;
  576. }
  577. if (this.listAgvQueue.Contains(agv))
  578. {
  579. this.listAgvQueue.Remove(agv);
  580. }
  581. //this.listAgvQueue.Add(agv);
  582. }
  583. }
  584. #endregion
  585. }
  586. }
  587. }
  588. //AGV离开管制区
  589. public void AGVLEAVE(AGVInfoModel agv)
  590. {
  591. --agv.ReleaseCount;
  592. //解除管制
  593. if (this.MainAgv == agv)
  594. {
  595. this.IsTraffic = false;
  596. this.MainAgv = null;
  597. }
  598. else if (this.MainAgv == null)
  599. {
  600. this.IsTraffic = false;
  601. }
  602. if (this.listAgvQueue.Contains(agv))
  603. {
  604. this.listAgvQueue.Remove(agv);
  605. }
  606. if (agv.TRAFFICAGV != null && agv.TRAFFICAGV.TRAFFICNUM.Contains(this))
  607. {
  608. this.listAgvQueue.Insert(0, agv.TRAFFICAGV);
  609. }
  610. }
  611. public void ReleaseAgv()
  612. {
  613. AGVInfoModel reAgv = this.listAgvQueue[0];
  614. if (reAgv.ReleaseCount > 1)//本来是按照1来判断
  615. {
  616. #region 它相对这个管制区是管制者,但它不被允许放行,因为还有其他区域的管制者管制着它。
  617. this.IsTraffic = true;
  618. this.MainAgv = reAgv;
  619. if (this.listAgvQueue.Contains(reAgv))
  620. {
  621. this.listAgvQueue.Remove(reAgv);
  622. }
  623. reAgv.IsMainAgv = true;
  624. foreach (var a in this.listAgvQueue)
  625. {
  626. a.TRAFFICAGV = reAgv;
  627. }
  628. //判断AGV是否可以被放行
  629. bool fx = true;
  630. foreach (var t in reAgv.TRAFFICNUM)
  631. {
  632. if (t.MainAgv != reAgv)
  633. {
  634. fx = false;
  635. }
  636. }
  637. if (fx)
  638. {
  639. reAgv.TrafficFlag = false;
  640. this.AGVINTER(reAgv, false);
  641. }
  642. else
  643. {
  644. reAgv.TrafficFlag = true;
  645. }
  646. #endregion
  647. }
  648. else
  649. {
  650. //reAgv.TrafficFlag = false;
  651. this.AGVINTER(reAgv, false);
  652. }
  653. }
  654. public void ReleaseAgv(AGVInfoModel reAgv)
  655. {
  656. if (reAgv.ReleaseCount > 1)
  657. {
  658. #region 它相对这个管制区是管制者,但它不被允许放行,因为还有其他区域的管制者管制着它。
  659. this.IsTraffic = true;
  660. this.MainAgv = reAgv;
  661. if (this.listAgvQueue.Contains(reAgv))
  662. {
  663. this.listAgvQueue.Remove(reAgv);
  664. }
  665. reAgv.IsMainAgv = true;
  666. foreach (var a in this.listAgvQueue)
  667. {
  668. a.TRAFFICAGV = reAgv;
  669. }
  670. //判断AGV是否可以被放行
  671. bool fx = true;
  672. foreach (var t in reAgv.TRAFFICNUM)
  673. {
  674. if (t.MainAgv != reAgv)
  675. {
  676. fx = false;
  677. }
  678. }
  679. if (fx)
  680. {
  681. reAgv.TrafficFlag = false;//放行之前把标识位给置为false
  682. this.AGVINTER(reAgv, false);
  683. }
  684. else
  685. {
  686. reAgv.TrafficFlag = true;
  687. }
  688. #endregion
  689. }
  690. else
  691. {
  692. //reAgv.TrafficFlag = false;
  693. this.AGVINTER(reAgv, false);
  694. }
  695. }
  696. public void ReleaseMainAgv()
  697. {
  698. if (this.MainAgv.ReleaseCount < 2)//被管制的数量小于2时,说明管制区里只有1车被管制,则主机可以随便走。
  699. {
  700. this.MainAgv.TrafficFlag = false;
  701. if (this.MainAgv.TRAFFICAGV != null) this.MainAgv.TRAFFICAGV = null;
  702. if (this.listAgvQueue.Contains(this.MainAgv)) this.listAgvQueue.Remove(this.MainAgv);
  703. }
  704. }
  705. public void ReleaseMixMainAgv()
  706. {
  707. this.MainAgv.TrafficFlag = false;
  708. if (this.MainAgv.TRAFFICAGV != null) this.MainAgv.TRAFFICAGV = null;
  709. if (this.listAgvQueue.Contains(this.MainAgv)) this.listAgvQueue.Remove(this.MainAgv);
  710. }
  711. public int Blockade(AGVInfoModel agv)
  712. {
  713. if (!this.IsTraffic) this.IsTraffic = true; //确保管制区的状态是管制中,封锁该管制区。
  714. if (this.MainAgv != null)
  715. {
  716. if (this.MainAgv != agv)
  717. {
  718. this.listAgvQueue.Add(agv); //把该AGV加入到管制区前的等候队伍中等候。
  719. return 2;
  720. }
  721. }
  722. else
  723. {
  724. this.MainAgv = agv;//直接让该AGV占领该管制区成为主机。
  725. return 1;
  726. }
  727. return 0;
  728. }
  729. private void NotifyPropertyChanged(String info)
  730. {
  731. if (PropertyChanged != null)
  732. {
  733. PropertyChanged(this, new PropertyChangedEventArgs(info));
  734. }
  735. }
  736. public void Dispose()
  737. {
  738. throw new NotImplementedException();
  739. }
  740. }
  741. }