FlowNode.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. 
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. namespace Dongke.IBOSS.Basics.FlowSetting
  5. {
  6. /// <summary>
  7. /// 节点
  8. /// </summary>
  9. public class FlowNode : FlowItem
  10. {
  11. #region 成员变量
  12. /// <summary>
  13. /// 节点范围
  14. /// </summary>
  15. private Rectangle _bounds = Rectangle.Empty;
  16. /// <summary>
  17. /// 节点图片类型(等于null时,NodeImage会保存;不等于null时,NodeImage不会保存,由外部指定)
  18. /// </summary>
  19. private int? _nodeImageType = null;
  20. /// <summary>
  21. /// 节点图片
  22. /// </summary>
  23. private Image _nodeImage = null;
  24. /// <summary>
  25. /// 节点边框宽度
  26. /// </summary>
  27. private int _borderWidth = Consts.NODE_BORDERWIDTH_DEFAULT;
  28. /// <summary>
  29. /// 节点边框颜色
  30. /// </summary>
  31. private Color _borderColor = Consts.NODE_BORDERCOLOR_DEFAULT;
  32. /// <summary>
  33. /// 节点填充颜色
  34. /// </summary>
  35. private Color? _fillColor = Consts.NODE_FILLCOLOR_DEFAULT;
  36. /// <summary>
  37. /// 能否跳过此节点
  38. /// </summary>
  39. private bool _canSkip = false;
  40. /// <summary>
  41. /// 流程节点状态(不保存xml)
  42. /// </summary>
  43. private FlowNodeState _flowNodeState = FlowNodeState.Detached;
  44. /// <summary>
  45. /// 流程节点类型(不保存xml)
  46. /// </summary>
  47. private FlowNodeType _checkedFlowNodeType = FlowNodeType.Alone;
  48. /// <summary>
  49. /// 是否显示锚点(不保存xml)
  50. /// </summary>
  51. private bool _showAnchor = false;
  52. /// <summary>
  53. /// 连入的线(不保存xml)
  54. /// </summary>
  55. private List<FlowLine> _inLines = new List<FlowLine>();
  56. /// <summary>
  57. /// 连出的线(不保存xml)
  58. /// </summary>
  59. private List<FlowLine> _outLines = new List<FlowLine>();
  60. /// <summary>
  61. /// 顶端的连接线(不保存xml)
  62. /// </summary>
  63. private List<FlowLine> _topLines = new List<FlowLine>();
  64. /// <summary>
  65. /// 底端的连接线(不保存xml)
  66. /// </summary>
  67. private List<FlowLine> _bottomLines = new List<FlowLine>();
  68. /// <summary>
  69. /// 左端的连接线(不保存xml)
  70. /// </summary>
  71. private List<FlowLine> _leftLines = new List<FlowLine>();
  72. /// <summary>
  73. /// 右端的连接线(不保存xml)
  74. /// </summary>
  75. private List<FlowLine> _rightLines = new List<FlowLine>();
  76. /// <summary>
  77. /// 前置节点(不保存xml)
  78. /// </summary>
  79. private List<FlowNode> _preNodes = new List<FlowNode>();
  80. /// <summary>
  81. /// 后续节点(不保存xml)
  82. /// </summary>
  83. private List<FlowNode> _nextNodes = new List<FlowNode>();
  84. #endregion 成员变量
  85. #region 构造函数
  86. /// <summary>
  87. /// 新节点
  88. /// </summary>
  89. /// <param name="manager">流程项目管理</param>
  90. internal FlowNode(ItemManager manager)
  91. : base(manager)
  92. {
  93. this.ShowName = true;
  94. this.Name = "节点" + this.ItemID;
  95. }
  96. /// <summary>
  97. /// 导入的节点
  98. /// </summary>
  99. /// <param name="manager">流程项目管理</param>
  100. /// <param name="itemID">项目ID</param>
  101. /// <param name="onlyCode">唯一编码</param>
  102. internal FlowNode(ItemManager manager, int itemID, string onlyCode)
  103. : base(manager, itemID, onlyCode)
  104. {
  105. this.ShowName = true;
  106. this.Name = "节点" + this.ItemID;
  107. this._flowNodeState = FlowNodeState.Unchanged;
  108. }
  109. #endregion 构造函数
  110. #region 属性
  111. /// <summary>
  112. /// 获取或设置节点上边缘与画布上边缘之间的距离(以像素为单位)。
  113. /// </summary>
  114. public int Top
  115. {
  116. get
  117. {
  118. return this._bounds.Top;
  119. }
  120. internal set
  121. {
  122. //if (value >= 0)
  123. //{
  124. // this._bounds.Y = value;
  125. //}
  126. this._bounds.Y = value;
  127. this.CheckBounds();
  128. }
  129. }
  130. /// <summary>
  131. /// 获取或设置节点左边缘与画布左边缘之间的距离(以像素为单位)。
  132. /// </summary>
  133. public int Left
  134. {
  135. get
  136. {
  137. return this._bounds.Left;
  138. }
  139. internal set
  140. {
  141. //if (value >= 0)
  142. //{
  143. // this._bounds.X = value;
  144. //}
  145. this._bounds.X = value;
  146. this.CheckBounds();
  147. }
  148. }
  149. /// <summary>
  150. /// 获取或设置节点的左上角相对于画布的左上角的坐标(以像素为单位)。
  151. /// </summary>
  152. public Point Location
  153. {
  154. get
  155. {
  156. return this._bounds.Location;
  157. }
  158. internal set
  159. {
  160. //if (value.X >= 0 && value.Y >= 0)
  161. //{
  162. // this._bounds.Location = value;
  163. //}
  164. this._bounds.Location = value;
  165. this.CheckBounds();
  166. }
  167. }
  168. /// <summary>
  169. /// 获取或设置节点的宽度(以像素为单位)。
  170. /// </summary>
  171. public int Width
  172. {
  173. get
  174. {
  175. return this._bounds.Width;
  176. }
  177. internal set
  178. {
  179. //if (value > 0)
  180. //{
  181. // this._bounds.Width = value;
  182. //}
  183. this._bounds.Width = value;
  184. this.CheckBounds();
  185. }
  186. }
  187. /// <summary>
  188. /// 获取或设置节点的高度(以像素为单位)。
  189. /// </summary>
  190. public int Height
  191. {
  192. get
  193. {
  194. return this._bounds.Height;
  195. }
  196. internal set
  197. {
  198. //if (value > 0)
  199. //{
  200. // this._bounds.Height = value;
  201. //}
  202. this._bounds.Height = value;
  203. this.CheckBounds();
  204. }
  205. }
  206. /// <summary>
  207. /// 获取或设置节点的尺寸(以像素为单位)。
  208. /// </summary>
  209. public Size Size
  210. {
  211. get
  212. {
  213. return this._bounds.Size;
  214. }
  215. internal set
  216. {
  217. //if (value.Width > 0 && value.Height > 0)
  218. //{
  219. // this._bounds.Size = value;
  220. //}
  221. this._bounds.Size = value;
  222. this.CheckBounds();
  223. }
  224. }
  225. /// <summary>
  226. /// 获取或设置节点相对于画布的位置和尺寸(以像素为单位)。
  227. /// </summary>
  228. public Rectangle Bounds
  229. {
  230. get
  231. {
  232. return this._bounds;
  233. }
  234. set
  235. {
  236. //if (value.X >= 0 && value.Y >= 0 && value.Width > 0 && value.Height > 0)
  237. //{
  238. // this._bounds = value;
  239. //}
  240. this._bounds = value;
  241. this.CheckBounds();
  242. }
  243. }
  244. /// <summary>
  245. /// 节点图片类型(等于null时,NodeImage会保存;不等于null时,NodeImage不会保存,由外部指定)
  246. /// </summary>
  247. public int? NodeImageType
  248. {
  249. get
  250. {
  251. return this._nodeImageType;
  252. }
  253. set
  254. {
  255. this._nodeImageType = value;
  256. }
  257. }
  258. /// <summary>
  259. /// 获取或设置节点图片
  260. /// </summary>
  261. public Image NodeImage
  262. {
  263. get
  264. {
  265. return this._nodeImage;
  266. }
  267. set
  268. {
  269. this._nodeImage = value;
  270. }
  271. }
  272. /// <summary>
  273. /// 获取或设置节点边框宽度
  274. /// </summary>
  275. public int BorderWidth
  276. {
  277. get
  278. {
  279. return this._borderWidth;
  280. }
  281. set
  282. {
  283. this._borderWidth = value < 0 ? 0 : value;
  284. }
  285. }
  286. /// <summary>
  287. /// 获取或设置节点边框颜色
  288. /// </summary>
  289. public Color BorderColor
  290. {
  291. get
  292. {
  293. return this._borderColor;
  294. }
  295. set
  296. {
  297. this._borderColor = value;
  298. }
  299. }
  300. /// <summary>
  301. /// 获取或设置节点填充颜色
  302. /// </summary>
  303. public Color? FillColor
  304. {
  305. get
  306. {
  307. return this._fillColor;
  308. }
  309. set
  310. {
  311. this._fillColor = value;
  312. }
  313. }
  314. /// <summary>
  315. /// 获取或设置能否跳过此节点
  316. /// </summary>
  317. public bool CanSkip
  318. {
  319. get
  320. {
  321. return this._canSkip;
  322. }
  323. set
  324. {
  325. this._canSkip = value;
  326. }
  327. }
  328. /// <summary>
  329. /// 获取流程节点状态
  330. /// </summary>
  331. public FlowNodeState NodeState
  332. {
  333. get
  334. {
  335. return this._flowNodeState;
  336. }
  337. internal set
  338. {
  339. this._flowNodeState = value;
  340. }
  341. }
  342. /// <summary>
  343. /// 获取流程节点类型
  344. /// </summary>
  345. public FlowNodeType NodeType
  346. {
  347. get
  348. {
  349. if (this.InLinesCount == 0)
  350. {
  351. if (this.OutLinesCount == 0)
  352. {
  353. return FlowNodeType.Alone;
  354. }
  355. else
  356. {
  357. return FlowNodeType.Begin;
  358. }
  359. }
  360. else if (this.OutLinesCount == 0)
  361. {
  362. return FlowNodeType.End;
  363. }
  364. else
  365. {
  366. return FlowNodeType.General;
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 获取或设置流程节点类型(调用 FlowBox.CheckFlow() 后会更新此状态,默认状态为 FlowNodeType.Alone 单独节点。)
  372. /// </summary>
  373. public FlowNodeType CheckedNodeType
  374. {
  375. get
  376. {
  377. return this._checkedFlowNodeType;
  378. }
  379. set
  380. {
  381. this._checkedFlowNodeType = value;
  382. }
  383. }
  384. /// <summary>
  385. /// 获取连入的线
  386. /// </summary>
  387. public List<FlowLine> InLines
  388. {
  389. get
  390. {
  391. //if (this._inLines == null)
  392. //{
  393. // this._inLines = new List<FlowLine>();
  394. //}
  395. return this._inLines;
  396. }
  397. }
  398. /// <summary>
  399. /// 获取连出的线
  400. /// </summary>
  401. public List<FlowLine> OutLines
  402. {
  403. get
  404. {
  405. //if (this._outLines == null)
  406. //{
  407. // this._outLines = new List<FlowLine>();
  408. //}
  409. return this._outLines;
  410. }
  411. }
  412. /// <summary>
  413. /// 获取连入的线个数
  414. /// </summary>
  415. public int InLinesCount
  416. {
  417. get
  418. {
  419. if (this._inLines == null)
  420. {
  421. return 0;
  422. }
  423. return this._inLines.Count;
  424. }
  425. }
  426. /// <summary>
  427. /// 获取连出的线个数
  428. /// </summary>
  429. public int OutLinesCount
  430. {
  431. get
  432. {
  433. if (this._outLines == null)
  434. {
  435. return 0;
  436. }
  437. return this._outLines.Count;
  438. }
  439. }
  440. /// <summary>
  441. /// 获取或设置鼠标按下时,节点的范围
  442. /// </summary>
  443. internal Rectangle MouseDownRect
  444. {
  445. get;
  446. set;
  447. }
  448. /// <summary>
  449. /// 获取或设置是否显示锚点
  450. /// </summary>
  451. internal bool ShowAnchor
  452. {
  453. get
  454. {
  455. return this._showAnchor;
  456. }
  457. set
  458. {
  459. this._showAnchor = value;
  460. }
  461. }
  462. /// <summary>
  463. /// 顶端的连接线
  464. /// </summary>
  465. public List<FlowLine> TopLines
  466. {
  467. get
  468. {
  469. return this._topLines;
  470. }
  471. }
  472. /// <summary>
  473. /// 底端的连接线
  474. /// </summary>
  475. public List<FlowLine> BottomLines
  476. {
  477. get
  478. {
  479. return this._bottomLines;
  480. }
  481. }
  482. /// <summary>
  483. /// 左端的连接线
  484. /// </summary>
  485. public List<FlowLine> LeftLines
  486. {
  487. get
  488. {
  489. return this._leftLines;
  490. }
  491. }
  492. /// <summary>
  493. /// 右端的连接线
  494. /// </summary>
  495. public List<FlowLine> RightLines
  496. {
  497. get
  498. {
  499. return this._rightLines;
  500. }
  501. }
  502. #region CheckFlow时做成
  503. /// <summary>
  504. /// 获取前置节点(CheckFlow时做成)
  505. /// </summary>
  506. public List<FlowNode> PreNodes
  507. {
  508. get
  509. {
  510. return this._preNodes;
  511. }
  512. }
  513. /// <summary>
  514. /// 获取后续节点(CheckFlow时做成)
  515. /// </summary>
  516. public List<FlowNode> NextNodes
  517. {
  518. get
  519. {
  520. return this._nextNodes;
  521. }
  522. }
  523. /// <summary>
  524. /// 获取前置节点个数(CheckFlow时做成)
  525. /// </summary>
  526. public int PreNodesCount
  527. {
  528. get
  529. {
  530. if (this._preNodes == null)
  531. {
  532. return 0;
  533. }
  534. return this._preNodes.Count;
  535. }
  536. }
  537. /// <summary>
  538. /// 获取后续节点个数(CheckFlow时做成)
  539. /// </summary>
  540. public int NextNodesCount
  541. {
  542. get
  543. {
  544. if (this._nextNodes == null)
  545. {
  546. return 0;
  547. }
  548. return this._nextNodes.Count;
  549. }
  550. }
  551. #endregion
  552. #endregion 属性
  553. #region 公有方法
  554. /// <summary>
  555. /// 获取选择状态样式范围
  556. /// </summary>
  557. /// <returns>选择状态样式范围</returns>
  558. public override Rectangle[] GetSelectedStyle()
  559. {
  560. /* 操作场所 handler(#) / side-#-
  561. * (0)---0---(4)---1---(1)
  562. * | |
  563. * 2 6
  564. * | |
  565. * (6) (8) (7)
  566. * | |
  567. * 3 7
  568. * | |
  569. * (2)---4---(5)---5---(3)
  570. */
  571. int styleSize = Consts.SELECTEDSTYLE_WIDTH;
  572. int styleSizeHalf = Consts.SELECTEDSTYLE_WIDTH_HALF;
  573. Rectangle[] rects = new Rectangle[8];
  574. rects[0] = new Rectangle(this.Left - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
  575. rects[1] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
  576. rects[2] = new Rectangle(this.Left - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
  577. rects[3] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
  578. rects[4] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
  579. rects[5] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
  580. rects[6] = new Rectangle(this.Left - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
  581. rects[7] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
  582. return rects;
  583. }
  584. /// <summary>
  585. /// 获取锚点范围
  586. /// </summary>
  587. /// <returns>锚点范围</returns>
  588. public Rectangle[] GetAnchorRects()
  589. {
  590. int styleSize = Consts.SELECTEDSTYLE_WIDTH;
  591. int styleSizeHalf = Consts.SELECTEDSTYLE_WIDTH_HALF;
  592. Rectangle[] rects = new Rectangle[4];
  593. rects[0] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
  594. rects[1] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
  595. rects[2] = new Rectangle(this.Left - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
  596. rects[3] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
  597. return rects;
  598. }
  599. /// <summary>
  600. /// 获取锚点
  601. /// </summary>
  602. /// <param name="anchorKind">锚点类型</param>
  603. /// <returns>锚点</returns>
  604. public Point GetAnchor(AnchorKind anchorKind)
  605. {
  606. switch (anchorKind)
  607. {
  608. case AnchorKind.Top:
  609. return new Point(this.Left + this.Width / 2, this.Top);
  610. case AnchorKind.Bottom:
  611. return new Point(this.Left + this.Width / 2, this.Bounds.Bottom);
  612. case AnchorKind.Left:
  613. return new Point(this.Left, this.Top + this.Height / 2);
  614. case AnchorKind.Right:
  615. return new Point(this.Bounds.Right, this.Top + this.Height / 2);
  616. default:
  617. return Point.Empty;
  618. }
  619. }
  620. #endregion 公有方法
  621. #region 私有方法
  622. /// <summary>
  623. /// 校验节点范围(保证Width,Height大于0)
  624. /// </summary>
  625. private void CheckBounds()
  626. {
  627. if (this._bounds.Width < 0)
  628. {
  629. this._bounds.X += this._bounds.Width;
  630. this._bounds.Width = -this._bounds.Width;
  631. }
  632. if (this._bounds.Height < 0)
  633. {
  634. this._bounds.Y += this._bounds.Height;
  635. this._bounds.Height = -this._bounds.Height;
  636. }
  637. }
  638. #endregion 私有方法
  639. }
  640. }