| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- namespace HySoft.FlowEditor
- {
- /// <summary>
- /// 流程节点
- /// </summary>
- public class FlowNode
- {
- #region 私有字段
- /// <summary>
- /// 节点ID
- /// </summary>
- string _nodeID;
- /// <summary>
- /// 节点名称
- /// </summary>
- string _nodeName;
- /// <summary>
- /// 节点备注
- /// </summary>
- string _nodeNote;
- /// <summary>
- /// 正常图标
- /// </summary>
- System.Drawing.Image _image;
- /// <summary>
- /// 高亮图标
- /// </summary>
- System.Drawing.Image _selectedImage;
- /// <summary>
- /// 尺寸
- /// </summary>
- Size _size;
- /// <summary>
- /// 中心点坐标
- /// </summary>
- Point _centerPoint;
- /// <summary>
- /// 控件
- /// </summary>
- FlowNodeControl _control;
- /// <summary>
- /// 入口端口列表
- /// </summary>
- List<NodePort> _inputNodePortList;
- /// <summary>
- /// 出口端口列表
- /// </summary>
- List<NodePort> _outputNodePortList;
- /// <summary>
- /// 是否可以添加出口
- /// </summary>
- bool _bAddOutputPort = true;
- /// <summary>
- /// 是否可以添加入口
- /// </summary>
- bool _bAddInputPort = true;
- /// <summary>
- /// 自定义对象
- /// </summary>
- Object _tag;
- #endregion
- #region 属性
- /// <summary>
- /// 节点ID
- /// </summary>
- public string ID
- {
- get { return _nodeID; }
- set {
- _nodeID = value;
- //2017-5-11
- _control.NodeID = _nodeID;
- }
- }
- /// <summary>
- /// 名称
- /// </summary>
- public string Name
- {
- get { return _nodeName; }
- set
- {
- _nodeName = value;
- _control.NodeName = _nodeName;
- }
- }
- /// <summary>
- /// 备注
- /// </summary>
- public string Note
- {
- get { return _nodeNote; }
- set
- {
- _nodeNote = value;
- //2017-5-8
- _control.NodeNote = _nodeNote;
- // if(_control.NodeNote=="")
- //{ _control.NodeNote = _control.NodeName; }
- }
- }
- /// <summary>
- /// 控件
- /// </summary>
- public FlowNodeControl Control
- {
- get { return _control; }
- }
- /// <summary>
- /// 尺寸
- /// </summary>
- public Size Size
- {
- get { return _control.Size; }
- }
- /// <summary>
- /// 位置
- /// </summary>
- public Point Location
- {
- get { return _control.Location; }
- }
- /// <summary>
- /// 中心点坐标
- /// </summary>
- public Point CenterPoint
- {
- get { return _control.CenterPoint; }
- set {_control.CenterPoint = value; }
- }
- /// <summary>
- /// 顶点
- /// </summary>
- public Point TopPoint
- {
- get { return _control.TopPoint; }
- }
- /// <summary>
- /// 底点
- /// </summary>
- public Point BottomPoint
- {
- get { return _control.BottomPoint; }
- }
- /// <summary>
- /// 左点
- /// </summary>
- public Point LeftPoint
- {
- get { return _control.LeftPoint; }
- }
- /// <summary>
- /// 右点
- /// </summary>
- public Point RightPoint
- {
- get { return _control.RightPoint; }
- }
- /// <summary>
- /// 出口列表
- /// </summary>
- public List<NodePort> InputPortList
- {
- get { return _inputNodePortList; }
- }
- /// <summary>
- /// 入口列表
- /// </summary>
- public List<NodePort> OutputPortList
- {
- get { return _outputNodePortList; }
- }
- /// <summary>
- /// 是否可以添加入口
- /// </summary>
- public bool CanAddInputPort
- {
- get { return _bAddInputPort; }
- }
- /// <summary>
- /// 是否可以添加出口
- /// </summary>
- public bool CanAddOutputPort
- {
- get { return _bAddOutputPort; }
- }
- /// <summary>
- /// 节点图标
- /// </summary>
- public Image Image
- {
- get { return _image; }
- set
- {
- _image = value;
- if (_control != null)
- _control.Image = _image;
- }
- }
- /// <summary>
- /// 节点被选中图标
- /// </summary>
- public Image SelectedImage
- {
- get { return _selectedImage; }
- set
- {
- _selectedImage = value;
- if (_control != null)
- _control.SelectdImage = _selectedImage;
- }
- }
- #endregion
- #region 公开方法
- /// <summary>
- /// 构造方法
- /// </summary>
- public FlowNode()
- {
- _size = new System.Drawing.Size(80, 50);
- _inputNodePortList = new List<NodePort>();
- _outputNodePortList = new List<NodePort>();
- _control = new FlowNodeControl(this);
- _control.Cursor = System.Windows.Forms.Cursors.SizeAll;
- _control.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- _control.Size = _size;
- _control.Tag = this;
- }
- /// <summary>
- /// 构造方法
- /// </summary>
- /// <param name="size">节点尺寸</param>
- public FlowNode(Size size)
- {
- _size = size;
- _inputNodePortList = new List<NodePort>();
- _outputNodePortList = new List<NodePort>();
- _control = new FlowNodeControl(this);
- _control.Cursor = System.Windows.Forms.Cursors.SizeAll;
- _control.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- _control.Size = _size;
- _control.Tag = this;
- }
- /// <summary>
- /// 添加入口
- /// </summary>
- /// <param name="port"></param>
- public void AddInputPort(NodePort port)
- {
- if(_bAddInputPort)
- _inputNodePortList.Add(port);
- }
- /// <summary>
- /// 添加出口
- /// </summary>
- /// <param name="port"></param>
- public void AddOutputPort(NodePort port)
- {
- if(_bAddOutputPort)
- _outputNodePortList.Add(port);
- }
- /// <summary>
- /// 添加线到指定的入口
- /// </summary>
- /// <param name="line"></param>
- /// <param name="inputPort"></param>
- public void AddLineToInputPort(FlowLine line, NodePort inputPort)
- {
- if (_inputNodePortList.IndexOf(inputPort) < 0)
- return;
- if (inputPort != null)
- {
- inputPort.Line = line;
- line.HeadNode = this;
- line.HeadNodePort = inputPort;
- }
- }
- /// <summary>
- /// 添加线到指定的出口
- /// </summary>
- /// <param name="line"></param>
- /// <param name="outputPort"></param>
- public void AddLineToOutPort(FlowLine line, NodePort outputPort)
- {
- if (_outputNodePortList.IndexOf(outputPort) < 0)
- return;
- if (outputPort != null)
- {
- outputPort.Line = line;
- line.TailNode = this;
- line.TailNodePort = outputPort;
- }
- }
- /// <summary>
- /// 移除入口
- /// </summary>
- /// <param name="port"></param>
- public void RemoveInputPort(NodePort port)
- {
- if (_bAddInputPort)
- _inputNodePortList.Remove(port);
- }
- /// <summary>
- /// 移除入口
- /// </summary>
- /// <param name="port"></param>
- public void RemoveOutputPort(NodePort port)
- {
- if (_bAddOutputPort)
- _outputNodePortList.Remove(port);
- }
- /// <summary>
- /// 从出口移除指定的线
- /// </summary>
- /// <param name="line"></param>
- /// <param name="inputPort"></param>
- public void RemoveLineFromInputPort(FlowLine line, NodePort inputPort)
- {
- if (_inputNodePortList.IndexOf(inputPort) <= 0)
- return;
- if (inputPort != null)
- {
- inputPort.Line = null;
- line.HeadNode = null;
- line.HeadNodePort = null;
- }
- }
- /// <summary>
- /// 从出口移除指定的线
- /// </summary>
- /// <param name="line"></param>
- /// <param name="outputPort"></param>
- public void RemoveLineFromOutputPort(FlowLine line, NodePort outputPort)
- {
- if (_outputNodePortList.IndexOf(outputPort) <= 0)
- return;
- if (outputPort != null)
- {
- outputPort.Line = null;
- line.TailNode = null;
- line.TailNodePort = null;
- }
- }
- /// <summary>
- /// 查找与指定线对应的入口
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public NodePort FindInputPort(FlowLine line)
- {
- if (_inputNodePortList == null || _inputNodePortList.Count <= 0)
- return null;
- foreach (NodePort port in _inputNodePortList)
- {
- if (port.Line == line)
- return port;
- }
- return null;
- }
- /// <summary>
- /// 查找与指定线对应的出口
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public NodePort FindOutputPort(FlowLine line)
- {
- if (_outputNodePortList == null || _outputNodePortList.Count <= 0)
- return null;
- foreach (NodePort port in _outputNodePortList)
- {
- if (port.Line == line)
- return port;
- }
- return null;
- }
- #endregion
- #region 私有方法
- #endregion
- }
- /// <summary>
- /// 节点端口
- /// </summary>
- public class NodePort
- {
- #region 字段
- /// <summary>
- /// 端口ID
- /// </summary>
- string _portID;
- /// <summary>
- /// 端口名称
- /// </summary>
- string _portName;
- /// <summary>
- /// 端口备注
- /// </summary>
- string _portNote;
- /// <summary>
- /// 端口的连线
- /// </summary>
- FlowLine _line;
- /// <summary>
- /// 自定义对象
- /// </summary>
- Object _tag;
- #endregion
- #region 属性
- /// <summary>
- /// 端口ID
- /// </summary>
- public string ID
- {
- get { return _portID; }
- set { _portID = value; }
- }
- /// <summary>
- /// 端口名称
- /// </summary>
- public string Name
- {
- get { return _portName; }
- set { _portName = value; }
- }
- /// <summary>
- /// 端口备注
- /// </summary>
- public string Note
- {
- get { return _portNote; }
- set { _portNote = value; }
- }
- /// <summary>
- /// 端口的连线
- /// </summary>
- public FlowLine Line
- {
- get { return _line; }
- set { _line = value; }
- }
- /// <summary>
- /// 自定义对象
- /// </summary>
- public Object Tag
- {
- get { return _tag; }
- set { _tag = value; }
- }
- #endregion
- #region 公开方法
- #endregion
- #region 私有方法
- #endregion
- }
- /// <summary>
- /// 流程线
- /// </summary>
- public class FlowLine
- {
- #region 字段
- /// <summary>
- /// 线ID
- /// </summary>
- string _lineID;
- /// <summary>
- /// 线名称
- /// </summary>
- string _lineName;
- /// <summary>
- /// 线备注
- /// </summary>
- string _lineNote;
- /// <summary>
- /// 与本线关联对应的头节点
- /// </summary>
- FlowNode _heardNode;
- /// <summary>
- /// 与本线关联对应的头节点的端口
- /// </summary>
- NodePort _heardPort;
- /// <summary>
- /// 与本线关联对应的尾节点
- /// </summary>
- FlowNode _tailNode;
- /// <summary>
- /// 与本线关联对应的尾节点的端口
- /// </summary>
- NodePort _tailPort;
- /// <summary>
- /// 组成线的点列表
- /// </summary>
- List<Point> _pointList;
- /// <summary>
- /// 与本线关联的折线控件
- /// </summary>
- FlowBrokenLineControl _control;
- /// <summary>
- /// 线的颜色
- /// </summary>
- Color _lineColor;
- /// <summary>
- /// 线被选中时的颜色
- /// </summary>
- Color _selectedLineColor;
- /// <summary>
- /// 线的宽度,最好为2的倍数
- /// </summary>
- int _lineWidth;
- /// <summary>
- /// 自定义对象
- /// </summary>
- Object _tag;
- #endregion
- #region 属性
- /// <summary>
- /// ID
- /// </summary>
- public string ID
- {
- get { return _lineID; }
- set
- {
- _lineID = value;
- }
- }
- /// <summary>
- /// 名字
- /// </summary>
- public string Name
- {
- get { return _lineName; }
- set
- {
- _lineName = value;
- _control.Name = _lineName;
- }
- }
- /// <summary>
- /// 备注
- /// </summary>
- public string Note
- {
- get { return _lineNote; }
- set { _lineNote = value; }
- }
- /// <summary>
- /// 用户自定义对象
- /// </summary>
- public Object Tag
- {
- get { return _tag; }
- set { _tag = value; }
- }
- /// <summary>
- /// 流程线控件
- /// </summary>
- public FlowBrokenLineControl Control
- {
- get { return _control; }
- }
- /// <summary>
- /// 组成线的点的列表
- /// </summary>
- public List<Point> PointList
- {
- get { return _pointList; }
- set
- {
- _pointList = value;
- _control.PointList = _pointList;
- }
- }
- /// <summary>
- /// 线的颜色
- /// </summary>
- public Color LineColor
- {
- get{ return _lineColor;}
- set
- {
- _lineColor = value;
- _control.LineColor = _lineColor;
- }
- }
- /// <summary>
- /// 线的被选中颜色
- /// </summary>
- public Color SelectedLineColor
- {
- get { return _selectedLineColor; }
- set
- {
- _selectedLineColor = value;
- _control.SelectedLineColor = _selectedLineColor;
- }
- }
- /// <summary>
- /// 线宽
- /// </summary>
- public int LineWidth
- {
- get { return _lineWidth; }
- set
- {
- _lineWidth = value;
- _control.LineWidth = _lineWidth;
- }
- }
- /// <summary>
- /// 线连接的头节点
- /// </summary>
- public FlowNode HeadNode
- {
- get { return _heardNode; }
- set { _heardNode = value; }
- }
- /// <summary>
- /// 线连接的头节点的端口
- /// </summary>
- public NodePort HeadNodePort
- {
- get { return _heardPort; }
- set { _heardPort = value; }
- }
- /// <summary>
- /// 线连接的尾节点
- /// </summary>
- public FlowNode TailNode
- {
- get { return _tailNode; }
- set { _tailNode = value; }
- }
- /// <summary>
- /// 线连接的尾节点的端口
- /// </summary>
- public NodePort TailNodePort
- {
- get { return _tailPort; }
- set { _tailPort = value; }
- }
- #endregion
- #region 公开方法
- /// <summary>
- /// 构造方法
- /// </summary>
- public FlowLine()
- {
- _control = new FlowBrokenLineControl(this);
- }
- #endregion
- #region 私有方法
- #endregion
- }
- }
|