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