ivr流程编辑器

FlowEditor.cs 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. namespace HySoft.FlowEditor
  5. {
  6. /// <summary>
  7. /// 流程节点
  8. /// </summary>
  9. public class FlowNode
  10. {
  11. #region 私有字段
  12. /// <summary>
  13. /// 节点ID
  14. /// </summary>
  15. string _nodeID;
  16. /// <summary>
  17. /// 节点名称
  18. /// </summary>
  19. string _nodeName;
  20. /// <summary>
  21. /// 节点备注
  22. /// </summary>
  23. string _nodeNote;
  24. /// <summary>
  25. /// 正常图标
  26. /// </summary>
  27. System.Drawing.Image _image;
  28. /// <summary>
  29. /// 高亮图标
  30. /// </summary>
  31. System.Drawing.Image _selectedImage;
  32. /// <summary>
  33. /// 尺寸
  34. /// </summary>
  35. Size _size;
  36. /// <summary>
  37. /// 中心点坐标
  38. /// </summary>
  39. Point _centerPoint;
  40. /// <summary>
  41. /// 控件
  42. /// </summary>
  43. FlowNodeControl _control;
  44. /// <summary>
  45. /// 入口端口列表
  46. /// </summary>
  47. List<NodePort> _inputNodePortList;
  48. /// <summary>
  49. /// 出口端口列表
  50. /// </summary>
  51. List<NodePort> _outputNodePortList;
  52. /// <summary>
  53. /// 是否可以添加出口
  54. /// </summary>
  55. bool _bAddOutputPort = true;
  56. /// <summary>
  57. /// 是否可以添加入口
  58. /// </summary>
  59. bool _bAddInputPort = true;
  60. /// <summary>
  61. /// 自定义对象
  62. /// </summary>
  63. Object _tag;
  64. #endregion
  65. #region 属性
  66. /// <summary>
  67. /// 节点ID
  68. /// </summary>
  69. public string ID
  70. {
  71. get { return _nodeID; }
  72. set {
  73. _nodeID = value;
  74. //2017-5-11
  75. _control.NodeID = _nodeID;
  76. }
  77. }
  78. /// <summary>
  79. /// 名称
  80. /// </summary>
  81. public string Name
  82. {
  83. get { return _nodeName; }
  84. set
  85. {
  86. _nodeName = value;
  87. _control.NodeName = _nodeName;
  88. }
  89. }
  90. /// <summary>
  91. /// 备注
  92. /// </summary>
  93. public string Note
  94. {
  95. get { return _nodeNote; }
  96. set
  97. {
  98. _nodeNote = value;
  99. //2017-5-8
  100. _control.NodeNote = _nodeNote;
  101. // if(_control.NodeNote=="")
  102. //{ _control.NodeNote = _control.NodeName; }
  103. }
  104. }
  105. /// <summary>
  106. /// 控件
  107. /// </summary>
  108. public FlowNodeControl Control
  109. {
  110. get { return _control; }
  111. }
  112. /// <summary>
  113. /// 尺寸
  114. /// </summary>
  115. public Size Size
  116. {
  117. get { return _control.Size; }
  118. }
  119. /// <summary>
  120. /// 位置
  121. /// </summary>
  122. public Point Location
  123. {
  124. get { return _control.Location; }
  125. }
  126. /// <summary>
  127. /// 中心点坐标
  128. /// </summary>
  129. public Point CenterPoint
  130. {
  131. get { return _control.CenterPoint; }
  132. set {_control.CenterPoint = value; }
  133. }
  134. /// <summary>
  135. /// 顶点
  136. /// </summary>
  137. public Point TopPoint
  138. {
  139. get { return _control.TopPoint; }
  140. }
  141. /// <summary>
  142. /// 底点
  143. /// </summary>
  144. public Point BottomPoint
  145. {
  146. get { return _control.BottomPoint; }
  147. }
  148. /// <summary>
  149. /// 左点
  150. /// </summary>
  151. public Point LeftPoint
  152. {
  153. get { return _control.LeftPoint; }
  154. }
  155. /// <summary>
  156. /// 右点
  157. /// </summary>
  158. public Point RightPoint
  159. {
  160. get { return _control.RightPoint; }
  161. }
  162. /// <summary>
  163. /// 出口列表
  164. /// </summary>
  165. public List<NodePort> InputPortList
  166. {
  167. get { return _inputNodePortList; }
  168. }
  169. /// <summary>
  170. /// 入口列表
  171. /// </summary>
  172. public List<NodePort> OutputPortList
  173. {
  174. get { return _outputNodePortList; }
  175. }
  176. /// <summary>
  177. /// 是否可以添加入口
  178. /// </summary>
  179. public bool CanAddInputPort
  180. {
  181. get { return _bAddInputPort; }
  182. }
  183. /// <summary>
  184. /// 是否可以添加出口
  185. /// </summary>
  186. public bool CanAddOutputPort
  187. {
  188. get { return _bAddOutputPort; }
  189. }
  190. /// <summary>
  191. /// 节点图标
  192. /// </summary>
  193. public Image Image
  194. {
  195. get { return _image; }
  196. set
  197. {
  198. _image = value;
  199. if (_control != null)
  200. _control.Image = _image;
  201. }
  202. }
  203. /// <summary>
  204. /// 节点被选中图标
  205. /// </summary>
  206. public Image SelectedImage
  207. {
  208. get { return _selectedImage; }
  209. set
  210. {
  211. _selectedImage = value;
  212. if (_control != null)
  213. _control.SelectdImage = _selectedImage;
  214. }
  215. }
  216. #endregion
  217. #region 公开方法
  218. /// <summary>
  219. /// 构造方法
  220. /// </summary>
  221. public FlowNode()
  222. {
  223. _size = new System.Drawing.Size(80, 50);
  224. _inputNodePortList = new List<NodePort>();
  225. _outputNodePortList = new List<NodePort>();
  226. _control = new FlowNodeControl(this);
  227. _control.Cursor = System.Windows.Forms.Cursors.SizeAll;
  228. _control.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  229. _control.Size = _size;
  230. _control.Tag = this;
  231. }
  232. /// <summary>
  233. /// 构造方法
  234. /// </summary>
  235. /// <param name="size">节点尺寸</param>
  236. public FlowNode(Size size)
  237. {
  238. _size = size;
  239. _inputNodePortList = new List<NodePort>();
  240. _outputNodePortList = new List<NodePort>();
  241. _control = new FlowNodeControl(this);
  242. _control.Cursor = System.Windows.Forms.Cursors.SizeAll;
  243. _control.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  244. _control.Size = _size;
  245. _control.Tag = this;
  246. }
  247. /// <summary>
  248. /// 添加入口
  249. /// </summary>
  250. /// <param name="port"></param>
  251. public void AddInputPort(NodePort port)
  252. {
  253. if(_bAddInputPort)
  254. _inputNodePortList.Add(port);
  255. }
  256. /// <summary>
  257. /// 添加出口
  258. /// </summary>
  259. /// <param name="port"></param>
  260. public void AddOutputPort(NodePort port)
  261. {
  262. if(_bAddOutputPort)
  263. _outputNodePortList.Add(port);
  264. }
  265. /// <summary>
  266. /// 添加线到指定的入口
  267. /// </summary>
  268. /// <param name="line"></param>
  269. /// <param name="inputPort"></param>
  270. public void AddLineToInputPort(FlowLine line, NodePort inputPort)
  271. {
  272. if (_inputNodePortList.IndexOf(inputPort) < 0)
  273. return;
  274. if (inputPort != null)
  275. {
  276. inputPort.Line = line;
  277. line.HeadNode = this;
  278. line.HeadNodePort = inputPort;
  279. }
  280. }
  281. /// <summary>
  282. /// 添加线到指定的出口
  283. /// </summary>
  284. /// <param name="line"></param>
  285. /// <param name="outputPort"></param>
  286. public void AddLineToOutPort(FlowLine line, NodePort outputPort)
  287. {
  288. if (_outputNodePortList.IndexOf(outputPort) < 0)
  289. return;
  290. if (outputPort != null)
  291. {
  292. outputPort.Line = line;
  293. line.TailNode = this;
  294. line.TailNodePort = outputPort;
  295. }
  296. }
  297. /// <summary>
  298. /// 移除入口
  299. /// </summary>
  300. /// <param name="port"></param>
  301. public void RemoveInputPort(NodePort port)
  302. {
  303. if (_bAddInputPort)
  304. _inputNodePortList.Remove(port);
  305. }
  306. /// <summary>
  307. /// 移除入口
  308. /// </summary>
  309. /// <param name="port"></param>
  310. public void RemoveOutputPort(NodePort port)
  311. {
  312. if (_bAddOutputPort)
  313. _outputNodePortList.Remove(port);
  314. }
  315. /// <summary>
  316. /// 从出口移除指定的线
  317. /// </summary>
  318. /// <param name="line"></param>
  319. /// <param name="inputPort"></param>
  320. public void RemoveLineFromInputPort(FlowLine line, NodePort inputPort)
  321. {
  322. if (_inputNodePortList.IndexOf(inputPort) <= 0)
  323. return;
  324. if (inputPort != null)
  325. {
  326. inputPort.Line = null;
  327. line.HeadNode = null;
  328. line.HeadNodePort = null;
  329. }
  330. }
  331. /// <summary>
  332. /// 从出口移除指定的线
  333. /// </summary>
  334. /// <param name="line"></param>
  335. /// <param name="outputPort"></param>
  336. public void RemoveLineFromOutputPort(FlowLine line, NodePort outputPort)
  337. {
  338. if (_outputNodePortList.IndexOf(outputPort) <= 0)
  339. return;
  340. if (outputPort != null)
  341. {
  342. outputPort.Line = null;
  343. line.TailNode = null;
  344. line.TailNodePort = null;
  345. }
  346. }
  347. /// <summary>
  348. /// 查找与指定线对应的入口
  349. /// </summary>
  350. /// <param name="line"></param>
  351. /// <returns></returns>
  352. public NodePort FindInputPort(FlowLine line)
  353. {
  354. if (_inputNodePortList == null || _inputNodePortList.Count <= 0)
  355. return null;
  356. foreach (NodePort port in _inputNodePortList)
  357. {
  358. if (port.Line == line)
  359. return port;
  360. }
  361. return null;
  362. }
  363. /// <summary>
  364. /// 查找与指定线对应的出口
  365. /// </summary>
  366. /// <param name="line"></param>
  367. /// <returns></returns>
  368. public NodePort FindOutputPort(FlowLine line)
  369. {
  370. if (_outputNodePortList == null || _outputNodePortList.Count <= 0)
  371. return null;
  372. foreach (NodePort port in _outputNodePortList)
  373. {
  374. if (port.Line == line)
  375. return port;
  376. }
  377. return null;
  378. }
  379. #endregion
  380. #region 私有方法
  381. #endregion
  382. }
  383. /// <summary>
  384. /// 节点端口
  385. /// </summary>
  386. public class NodePort
  387. {
  388. #region 字段
  389. /// <summary>
  390. /// 端口ID
  391. /// </summary>
  392. string _portID;
  393. /// <summary>
  394. /// 端口名称
  395. /// </summary>
  396. string _portName;
  397. /// <summary>
  398. /// 端口备注
  399. /// </summary>
  400. string _portNote;
  401. /// <summary>
  402. /// 端口的连线
  403. /// </summary>
  404. FlowLine _line;
  405. /// <summary>
  406. /// 自定义对象
  407. /// </summary>
  408. Object _tag;
  409. #endregion
  410. #region 属性
  411. /// <summary>
  412. /// 端口ID
  413. /// </summary>
  414. public string ID
  415. {
  416. get { return _portID; }
  417. set { _portID = value; }
  418. }
  419. /// <summary>
  420. /// 端口名称
  421. /// </summary>
  422. public string Name
  423. {
  424. get { return _portName; }
  425. set { _portName = value; }
  426. }
  427. /// <summary>
  428. /// 端口备注
  429. /// </summary>
  430. public string Note
  431. {
  432. get { return _portNote; }
  433. set { _portNote = value; }
  434. }
  435. /// <summary>
  436. /// 端口的连线
  437. /// </summary>
  438. public FlowLine Line
  439. {
  440. get { return _line; }
  441. set { _line = value; }
  442. }
  443. /// <summary>
  444. /// 自定义对象
  445. /// </summary>
  446. public Object Tag
  447. {
  448. get { return _tag; }
  449. set { _tag = value; }
  450. }
  451. #endregion
  452. #region 公开方法
  453. #endregion
  454. #region 私有方法
  455. #endregion
  456. }
  457. /// <summary>
  458. /// 流程线
  459. /// </summary>
  460. public class FlowLine
  461. {
  462. #region 字段
  463. /// <summary>
  464. /// 线ID
  465. /// </summary>
  466. string _lineID;
  467. /// <summary>
  468. /// 线名称
  469. /// </summary>
  470. string _lineName;
  471. /// <summary>
  472. /// 线备注
  473. /// </summary>
  474. string _lineNote;
  475. /// <summary>
  476. /// 与本线关联对应的头节点
  477. /// </summary>
  478. FlowNode _heardNode;
  479. /// <summary>
  480. /// 与本线关联对应的头节点的端口
  481. /// </summary>
  482. NodePort _heardPort;
  483. /// <summary>
  484. /// 与本线关联对应的尾节点
  485. /// </summary>
  486. FlowNode _tailNode;
  487. /// <summary>
  488. /// 与本线关联对应的尾节点的端口
  489. /// </summary>
  490. NodePort _tailPort;
  491. /// <summary>
  492. /// 组成线的点列表
  493. /// </summary>
  494. List<Point> _pointList;
  495. /// <summary>
  496. /// 与本线关联的折线控件
  497. /// </summary>
  498. FlowBrokenLineControl _control;
  499. /// <summary>
  500. /// 线的颜色
  501. /// </summary>
  502. Color _lineColor;
  503. /// <summary>
  504. /// 线被选中时的颜色
  505. /// </summary>
  506. Color _selectedLineColor;
  507. /// <summary>
  508. /// 线的宽度,最好为2的倍数
  509. /// </summary>
  510. int _lineWidth;
  511. /// <summary>
  512. /// 自定义对象
  513. /// </summary>
  514. Object _tag;
  515. #endregion
  516. #region 属性
  517. /// <summary>
  518. /// ID
  519. /// </summary>
  520. public string ID
  521. {
  522. get { return _lineID; }
  523. set
  524. {
  525. _lineID = value;
  526. }
  527. }
  528. /// <summary>
  529. /// 名字
  530. /// </summary>
  531. public string Name
  532. {
  533. get { return _lineName; }
  534. set
  535. {
  536. _lineName = value;
  537. _control.Name = _lineName;
  538. }
  539. }
  540. /// <summary>
  541. /// 备注
  542. /// </summary>
  543. public string Note
  544. {
  545. get { return _lineNote; }
  546. set { _lineNote = value; }
  547. }
  548. /// <summary>
  549. /// 用户自定义对象
  550. /// </summary>
  551. public Object Tag
  552. {
  553. get { return _tag; }
  554. set { _tag = value; }
  555. }
  556. /// <summary>
  557. /// 流程线控件
  558. /// </summary>
  559. public FlowBrokenLineControl Control
  560. {
  561. get { return _control; }
  562. }
  563. /// <summary>
  564. /// 组成线的点的列表
  565. /// </summary>
  566. public List<Point> PointList
  567. {
  568. get { return _pointList; }
  569. set
  570. {
  571. _pointList = value;
  572. _control.PointList = _pointList;
  573. }
  574. }
  575. /// <summary>
  576. /// 线的颜色
  577. /// </summary>
  578. public Color LineColor
  579. {
  580. get{ return _lineColor;}
  581. set
  582. {
  583. _lineColor = value;
  584. _control.LineColor = _lineColor;
  585. }
  586. }
  587. /// <summary>
  588. /// 线的被选中颜色
  589. /// </summary>
  590. public Color SelectedLineColor
  591. {
  592. get { return _selectedLineColor; }
  593. set
  594. {
  595. _selectedLineColor = value;
  596. _control.SelectedLineColor = _selectedLineColor;
  597. }
  598. }
  599. /// <summary>
  600. /// 线宽
  601. /// </summary>
  602. public int LineWidth
  603. {
  604. get { return _lineWidth; }
  605. set
  606. {
  607. _lineWidth = value;
  608. _control.LineWidth = _lineWidth;
  609. }
  610. }
  611. /// <summary>
  612. /// 线连接的头节点
  613. /// </summary>
  614. public FlowNode HeadNode
  615. {
  616. get { return _heardNode; }
  617. set { _heardNode = value; }
  618. }
  619. /// <summary>
  620. /// 线连接的头节点的端口
  621. /// </summary>
  622. public NodePort HeadNodePort
  623. {
  624. get { return _heardPort; }
  625. set { _heardPort = value; }
  626. }
  627. /// <summary>
  628. /// 线连接的尾节点
  629. /// </summary>
  630. public FlowNode TailNode
  631. {
  632. get { return _tailNode; }
  633. set { _tailNode = value; }
  634. }
  635. /// <summary>
  636. /// 线连接的尾节点的端口
  637. /// </summary>
  638. public NodePort TailNodePort
  639. {
  640. get { return _tailPort; }
  641. set { _tailPort = value; }
  642. }
  643. #endregion
  644. #region 公开方法
  645. /// <summary>
  646. /// 构造方法
  647. /// </summary>
  648. public FlowLine()
  649. {
  650. _control = new FlowBrokenLineControl(this);
  651. }
  652. #endregion
  653. #region 私有方法
  654. #endregion
  655. }
  656. }