| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 |
-
- using System.Collections.Generic;
- using System.Drawing;
- namespace Dongke.IBOSS.Basics.FlowSetting
- {
- /// <summary>
- /// 节点
- /// </summary>
- public class FlowNode : FlowItem
- {
- #region 成员变量
- /// <summary>
- /// 节点范围
- /// </summary>
- private Rectangle _bounds = Rectangle.Empty;
- /// <summary>
- /// 节点图片类型(等于null时,NodeImage会保存;不等于null时,NodeImage不会保存,由外部指定)
- /// </summary>
- private int? _nodeImageType = null;
- /// <summary>
- /// 节点图片
- /// </summary>
- private Image _nodeImage = null;
- /// <summary>
- /// 节点边框宽度
- /// </summary>
- private int _borderWidth = Consts.NODE_BORDERWIDTH_DEFAULT;
- /// <summary>
- /// 节点边框颜色
- /// </summary>
- private Color _borderColor = Consts.NODE_BORDERCOLOR_DEFAULT;
- /// <summary>
- /// 节点填充颜色
- /// </summary>
- private Color? _fillColor = Consts.NODE_FILLCOLOR_DEFAULT;
- /// <summary>
- /// 能否跳过此节点
- /// </summary>
- private bool _canSkip = false;
- /// <summary>
- /// 流程节点状态(不保存xml)
- /// </summary>
- private FlowNodeState _flowNodeState = FlowNodeState.Detached;
- /// <summary>
- /// 流程节点类型(不保存xml)
- /// </summary>
- private FlowNodeType _checkedFlowNodeType = FlowNodeType.Alone;
- /// <summary>
- /// 是否显示锚点(不保存xml)
- /// </summary>
- private bool _showAnchor = false;
- /// <summary>
- /// 连入的线(不保存xml)
- /// </summary>
- private List<FlowLine> _inLines = new List<FlowLine>();
- /// <summary>
- /// 连出的线(不保存xml)
- /// </summary>
- private List<FlowLine> _outLines = new List<FlowLine>();
- /// <summary>
- /// 顶端的连接线(不保存xml)
- /// </summary>
- private List<FlowLine> _topLines = new List<FlowLine>();
- /// <summary>
- /// 底端的连接线(不保存xml)
- /// </summary>
- private List<FlowLine> _bottomLines = new List<FlowLine>();
- /// <summary>
- /// 左端的连接线(不保存xml)
- /// </summary>
- private List<FlowLine> _leftLines = new List<FlowLine>();
- /// <summary>
- /// 右端的连接线(不保存xml)
- /// </summary>
- private List<FlowLine> _rightLines = new List<FlowLine>();
- /// <summary>
- /// 前置节点(不保存xml)
- /// </summary>
- private List<FlowNode> _preNodes = new List<FlowNode>();
- /// <summary>
- /// 后续节点(不保存xml)
- /// </summary>
- private List<FlowNode> _nextNodes = new List<FlowNode>();
- #endregion 成员变量
-
- #region 构造函数
- /// <summary>
- /// 新节点
- /// </summary>
- /// <param name="manager">流程项目管理</param>
- internal FlowNode(ItemManager manager)
- : base(manager)
- {
- this.ShowName = true;
- this.Name = "节点" + this.ItemID;
- }
- /// <summary>
- /// 导入的节点
- /// </summary>
- /// <param name="manager">流程项目管理</param>
- /// <param name="itemID">项目ID</param>
- /// <param name="onlyCode">唯一编码</param>
- internal FlowNode(ItemManager manager, int itemID, string onlyCode)
- : base(manager, itemID, onlyCode)
- {
- this.ShowName = true;
- this.Name = "节点" + this.ItemID;
- this._flowNodeState = FlowNodeState.Unchanged;
- }
- #endregion 构造函数
- #region 属性
- /// <summary>
- /// 获取或设置节点上边缘与画布上边缘之间的距离(以像素为单位)。
- /// </summary>
- public int Top
- {
- get
- {
- return this._bounds.Top;
- }
- internal set
- {
- //if (value >= 0)
- //{
- // this._bounds.Y = value;
- //}
- this._bounds.Y = value;
- this.CheckBounds();
- }
- }
- /// <summary>
- /// 获取或设置节点左边缘与画布左边缘之间的距离(以像素为单位)。
- /// </summary>
- public int Left
- {
- get
- {
- return this._bounds.Left;
- }
- internal set
- {
- //if (value >= 0)
- //{
- // this._bounds.X = value;
- //}
- this._bounds.X = value;
- this.CheckBounds();
- }
- }
- /// <summary>
- /// 获取或设置节点的左上角相对于画布的左上角的坐标(以像素为单位)。
- /// </summary>
- public Point Location
- {
- get
- {
- return this._bounds.Location;
- }
- internal set
- {
- //if (value.X >= 0 && value.Y >= 0)
- //{
- // this._bounds.Location = value;
- //}
- this._bounds.Location = value;
- this.CheckBounds();
- }
- }
- /// <summary>
- /// 获取或设置节点的宽度(以像素为单位)。
- /// </summary>
- public int Width
- {
- get
- {
- return this._bounds.Width;
- }
- internal set
- {
- //if (value > 0)
- //{
- // this._bounds.Width = value;
- //}
- this._bounds.Width = value;
- this.CheckBounds();
- }
- }
- /// <summary>
- /// 获取或设置节点的高度(以像素为单位)。
- /// </summary>
- public int Height
- {
- get
- {
- return this._bounds.Height;
- }
- internal set
- {
- //if (value > 0)
- //{
- // this._bounds.Height = value;
- //}
- this._bounds.Height = value;
- this.CheckBounds();
- }
- }
- /// <summary>
- /// 获取或设置节点的尺寸(以像素为单位)。
- /// </summary>
- public Size Size
- {
- get
- {
- return this._bounds.Size;
- }
- internal set
- {
- //if (value.Width > 0 && value.Height > 0)
- //{
- // this._bounds.Size = value;
- //}
- this._bounds.Size = value;
- this.CheckBounds();
- }
- }
- /// <summary>
- /// 获取或设置节点相对于画布的位置和尺寸(以像素为单位)。
- /// </summary>
- public Rectangle Bounds
- {
- get
- {
- return this._bounds;
- }
- set
- {
- //if (value.X >= 0 && value.Y >= 0 && value.Width > 0 && value.Height > 0)
- //{
- // this._bounds = value;
- //}
- this._bounds = value;
- this.CheckBounds();
- }
- }
- /// <summary>
- /// 节点图片类型(等于null时,NodeImage会保存;不等于null时,NodeImage不会保存,由外部指定)
- /// </summary>
- public int? NodeImageType
- {
- get
- {
- return this._nodeImageType;
- }
- set
- {
- this._nodeImageType = value;
- }
- }
- /// <summary>
- /// 获取或设置节点图片
- /// </summary>
- public Image NodeImage
- {
- get
- {
- return this._nodeImage;
- }
- set
- {
- this._nodeImage = value;
- }
- }
- /// <summary>
- /// 获取或设置节点边框宽度
- /// </summary>
- public int BorderWidth
- {
- get
- {
- return this._borderWidth;
- }
- set
- {
- this._borderWidth = value < 0 ? 0 : value;
- }
- }
- /// <summary>
- /// 获取或设置节点边框颜色
- /// </summary>
- public Color BorderColor
- {
- get
- {
- return this._borderColor;
- }
- set
- {
- this._borderColor = value;
- }
- }
- /// <summary>
- /// 获取或设置节点填充颜色
- /// </summary>
- public Color? FillColor
- {
- get
- {
- return this._fillColor;
- }
- set
- {
- this._fillColor = value;
- }
- }
- /// <summary>
- /// 获取或设置能否跳过此节点
- /// </summary>
- public bool CanSkip
- {
- get
- {
- return this._canSkip;
- }
- set
- {
- this._canSkip = value;
- }
- }
- /// <summary>
- /// 获取流程节点状态
- /// </summary>
- public FlowNodeState NodeState
- {
- get
- {
- return this._flowNodeState;
- }
- internal set
- {
- this._flowNodeState = value;
- }
- }
- /// <summary>
- /// 获取流程节点类型
- /// </summary>
- public FlowNodeType NodeType
- {
- get
- {
- if (this.InLinesCount == 0)
- {
- if (this.OutLinesCount == 0)
- {
- return FlowNodeType.Alone;
- }
- else
- {
- return FlowNodeType.Begin;
- }
- }
- else if (this.OutLinesCount == 0)
- {
- return FlowNodeType.End;
- }
- else
- {
- return FlowNodeType.General;
- }
- }
- }
- /// <summary>
- /// 获取或设置流程节点类型(调用 FlowBox.CheckFlow() 后会更新此状态,默认状态为 FlowNodeType.Alone 单独节点。)
- /// </summary>
- public FlowNodeType CheckedNodeType
- {
- get
- {
- return this._checkedFlowNodeType;
- }
- set
- {
- this._checkedFlowNodeType = value;
- }
- }
- /// <summary>
- /// 获取连入的线
- /// </summary>
- public List<FlowLine> InLines
- {
- get
- {
- //if (this._inLines == null)
- //{
- // this._inLines = new List<FlowLine>();
- //}
- return this._inLines;
- }
- }
- /// <summary>
- /// 获取连出的线
- /// </summary>
- public List<FlowLine> OutLines
- {
- get
- {
- //if (this._outLines == null)
- //{
- // this._outLines = new List<FlowLine>();
- //}
- return this._outLines;
- }
- }
- /// <summary>
- /// 获取连入的线个数
- /// </summary>
- public int InLinesCount
- {
- get
- {
- if (this._inLines == null)
- {
- return 0;
- }
- return this._inLines.Count;
- }
- }
- /// <summary>
- /// 获取连出的线个数
- /// </summary>
- public int OutLinesCount
- {
- get
- {
- if (this._outLines == null)
- {
- return 0;
- }
- return this._outLines.Count;
- }
- }
- /// <summary>
- /// 获取或设置鼠标按下时,节点的范围
- /// </summary>
- internal Rectangle MouseDownRect
- {
- get;
- set;
- }
- /// <summary>
- /// 获取或设置是否显示锚点
- /// </summary>
- internal bool ShowAnchor
- {
- get
- {
- return this._showAnchor;
- }
- set
- {
- this._showAnchor = value;
- }
- }
- /// <summary>
- /// 顶端的连接线
- /// </summary>
- public List<FlowLine> TopLines
- {
- get
- {
- return this._topLines;
- }
- }
- /// <summary>
- /// 底端的连接线
- /// </summary>
- public List<FlowLine> BottomLines
- {
- get
- {
- return this._bottomLines;
- }
- }
- /// <summary>
- /// 左端的连接线
- /// </summary>
- public List<FlowLine> LeftLines
- {
- get
- {
- return this._leftLines;
- }
- }
- /// <summary>
- /// 右端的连接线
- /// </summary>
- public List<FlowLine> RightLines
- {
- get
- {
- return this._rightLines;
- }
- }
- #region CheckFlow时做成
- /// <summary>
- /// 获取前置节点(CheckFlow时做成)
- /// </summary>
- public List<FlowNode> PreNodes
- {
- get
- {
- return this._preNodes;
- }
- }
- /// <summary>
- /// 获取后续节点(CheckFlow时做成)
- /// </summary>
- public List<FlowNode> NextNodes
- {
- get
- {
- return this._nextNodes;
- }
- }
- /// <summary>
- /// 获取前置节点个数(CheckFlow时做成)
- /// </summary>
- public int PreNodesCount
- {
- get
- {
- if (this._preNodes == null)
- {
- return 0;
- }
- return this._preNodes.Count;
- }
- }
- /// <summary>
- /// 获取后续节点个数(CheckFlow时做成)
- /// </summary>
- public int NextNodesCount
- {
- get
- {
- if (this._nextNodes == null)
- {
- return 0;
- }
- return this._nextNodes.Count;
- }
- }
- #endregion
- #endregion 属性
- #region 公有方法
- /// <summary>
- /// 获取选择状态样式范围
- /// </summary>
- /// <returns>选择状态样式范围</returns>
- public override Rectangle[] GetSelectedStyle()
- {
- /* 操作场所 handler(#) / side-#-
- * (0)---0---(4)---1---(1)
- * | |
- * 2 6
- * | |
- * (6) (8) (7)
- * | |
- * 3 7
- * | |
- * (2)---4---(5)---5---(3)
- */
- int styleSize = Consts.SELECTEDSTYLE_WIDTH;
- int styleSizeHalf = Consts.SELECTEDSTYLE_WIDTH_HALF;
- Rectangle[] rects = new Rectangle[8];
- rects[0] = new Rectangle(this.Left - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
- rects[1] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
- rects[2] = new Rectangle(this.Left - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
- rects[3] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
- rects[4] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
- rects[5] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
- rects[6] = new Rectangle(this.Left - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
- rects[7] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
- return rects;
- }
- /// <summary>
- /// 获取锚点范围
- /// </summary>
- /// <returns>锚点范围</returns>
- public Rectangle[] GetAnchorRects()
- {
- int styleSize = Consts.SELECTEDSTYLE_WIDTH;
- int styleSizeHalf = Consts.SELECTEDSTYLE_WIDTH_HALF;
- Rectangle[] rects = new Rectangle[4];
- rects[0] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Top - styleSizeHalf, styleSize, styleSize);
- rects[1] = new Rectangle(this.Left + this.Width / 2 - styleSizeHalf, this.Bounds.Bottom - styleSizeHalf, styleSize, styleSize);
- rects[2] = new Rectangle(this.Left - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
- rects[3] = new Rectangle(this.Bounds.Right - styleSizeHalf, this.Top + this.Height / 2 - styleSizeHalf, styleSize, styleSize);
- return rects;
- }
- /// <summary>
- /// 获取锚点
- /// </summary>
- /// <param name="anchorKind">锚点类型</param>
- /// <returns>锚点</returns>
- public Point GetAnchor(AnchorKind anchorKind)
- {
- switch (anchorKind)
- {
- case AnchorKind.Top:
- return new Point(this.Left + this.Width / 2, this.Top);
- case AnchorKind.Bottom:
- return new Point(this.Left + this.Width / 2, this.Bounds.Bottom);
- case AnchorKind.Left:
- return new Point(this.Left, this.Top + this.Height / 2);
- case AnchorKind.Right:
- return new Point(this.Bounds.Right, this.Top + this.Height / 2);
- default:
- return Point.Empty;
- }
- }
- #endregion 公有方法
- #region 私有方法
- /// <summary>
- /// 校验节点范围(保证Width,Height大于0)
- /// </summary>
- private void CheckBounds()
- {
- if (this._bounds.Width < 0)
- {
- this._bounds.X += this._bounds.Width;
- this._bounds.Width = -this._bounds.Width;
- }
- if (this._bounds.Height < 0)
- {
- this._bounds.Y += this._bounds.Height;
- this._bounds.Height = -this._bounds.Height;
- }
- }
- #endregion 私有方法
- }
- }
|