Skip to content

Commit 5323358

Browse files
committed
修复HUB节点断开链接BUG 将编辑器连线图层移动至节点图层后方 修改部分STNode重载ADD:(OnSetOptionDotLocation,OnSetOptionTextRectangle,OnEditorLoadCompleted) 对保存的文件进行GZIP压缩
1 parent f429f2d commit 5323358

File tree

15 files changed

+504
-127
lines changed

15 files changed

+504
-127
lines changed

ST.Library.UI/ST.Library.UI.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
<WarningLevel>4</WarningLevel>
2424
</PropertyGroup>
2525
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26-
<DebugType>none</DebugType>
26+
<DebugType>pdbonly</DebugType>
2727
<Optimize>true</Optimize>
2828
<OutputPath>bin\Release\</OutputPath>
2929
<DefineConstants>TRACE</DefineConstants>
3030
<ErrorReport>prompt</ErrorReport>
3131
<WarningLevel>4</WarningLevel>
3232
<DocumentationFile>bin\Release\ST.Library.UI.XML</DocumentationFile>
33+
<DebugSymbols>true</DebugSymbols>
3334
</PropertyGroup>
3435
<ItemGroup>
3536
<Reference Include="System" />

ST.Library.UI/STNodeEditor/STNode.cs

Lines changed: 100 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public STNodeEditor Owner {
4848
internal set {
4949
if (value == _Owner) return;
5050
if (_Owner != null) {
51-
foreach (STNodeOption op in this._InputOptions) op.DisConnectionAll();
52-
foreach (STNodeOption op in this._OutputOptions) op.DisConnectionAll();
51+
foreach (STNodeOption op in this._InputOptions.ToArray()) op.DisConnectionAll();
52+
foreach (STNodeOption op in this._OutputOptions.ToArray()) op.DisConnectionAll();
5353
}
5454
_Owner = value;
55+
this.BuildSize(true, true, false);
5556
this.OnOwnerChanged();
5657
}
5758
}
@@ -368,8 +369,14 @@ public object Tag {
368369
set { _Tag = value; }
369370
}
370371

371-
private bool m_isBuildNodeSize;
372-
private bool m_isBuildMarkSize;
372+
private Guid _Guid;
373+
/// <summary>
374+
/// 获取全局唯一标识
375+
/// </summary>
376+
public Guid Guid {
377+
get { return _Guid; }
378+
}
379+
373380
private static Point m_static_pt_init = new Point(10, 10);
374381

375382
public STNode(/*string strTitle, int x, int y*/) {
@@ -395,6 +402,7 @@ public STNode(/*string strTitle, int x, int y*/) {
395402
m_sf.SetTabStops(0, new float[] { 40 });
396403
m_static_pt_init.X += 10;
397404
m_static_pt_init.Y += 10;
405+
this._Guid = Guid.NewGuid();
398406
this.OnCreate();
399407
}
400408

@@ -409,30 +417,34 @@ public STNode(/*string strTitle, int x, int y*/) {
409417
/// </summary>
410418
protected STNodeControl m_ctrl_hover;
411419

412-
public void BuildSize(bool bBuildNode, bool bBuildMark, bool bRedraw) {
413-
m_isBuildNodeSize = bBuildNode;
414-
m_isBuildMarkSize = bBuildMark;
415-
if (bRedraw) {
416-
if (this._Owner != null) this._Owner.Invalidate();
417-
}
418-
}
419-
420-
internal void CheckSize(DrawingTools dt) {
421-
if (m_isBuildNodeSize) {
422-
Size sz = this.OnBuildNodeSize(dt);
423-
this._Width = sz.Width;
424-
this._Height = sz.Height;
425-
m_isBuildNodeSize = false;
426-
}
427-
if (m_isBuildMarkSize) {
428-
m_isBuildMarkSize = true;
429-
if (string.IsNullOrEmpty(this._Mark)) return;
430-
this._MarkRectangle = this.OnBuildMarkRectangle(dt);
420+
protected internal void BuildSize(bool bBuildNode, bool bBuildMark, bool bRedraw) {
421+
if (this._Owner == null) return;
422+
Pen p = new Pen(this._BackColor);
423+
SolidBrush sb = new SolidBrush(this._BackColor);
424+
using (Graphics g = this._Owner.CreateGraphics()) {
425+
DrawingTools dt = new DrawingTools() {
426+
Graphics = g,
427+
Pen = p,
428+
SolidBrush = sb
429+
};
430+
if (bBuildNode) {
431+
Size sz = this.OnBuildNodeSize(dt);
432+
this._Width = sz.Width;
433+
this._Height = sz.Height;
434+
this.SetOptionLocation();
435+
this.OnResize(new EventArgs());
436+
}
437+
if (bBuildMark) {
438+
if (string.IsNullOrEmpty(this._Mark)) return;
439+
this._MarkRectangle = this.OnBuildMarkRectangle(dt);
440+
}
431441
}
442+
if (bRedraw) this._Owner.Invalidate();
432443
}
433444

434445
internal Dictionary<string, byte[]> OnSaveNode() {
435446
Dictionary<string, byte[]> dic = new Dictionary<string, byte[]>();
447+
dic.Add("Guid", this._Guid.ToByteArray());
436448
dic.Add("Left", BitConverter.GetBytes(this._Left));
437449
dic.Add("Top", BitConverter.GetBytes(this._Top));
438450
dic.Add("Mark", string.IsNullOrEmpty(this._Mark) ? new byte[] { 0 } : Encoding.UTF8.GetBytes(this._Mark));
@@ -444,7 +456,11 @@ internal Dictionary<string, byte[]> OnSaveNode() {
444456

445457
internal virtual byte[] GetSaveData() {
446458
List<byte> lst = new List<byte>();
447-
byte[] byData = Encoding.UTF8.GetBytes(this.GetType().GUID.ToString());
459+
Type t = this.GetType();
460+
byte[] byData = Encoding.UTF8.GetBytes(t.Module.Name);
461+
lst.Add((byte)byData.Length);
462+
lst.AddRange(byData);
463+
byData = Encoding.UTF8.GetBytes(t.GUID.ToString());
448464
lst.Add((byte)byData.Length);
449465
lst.AddRange(byData);
450466

@@ -552,31 +568,13 @@ protected virtual void OnDrawTitle(DrawingTools dt) {
552568
/// <param name="dt">绘制工具</param>
553569
protected virtual void OnDrawBody(DrawingTools dt) {
554570
SolidBrush brush = dt.SolidBrush;
555-
Rectangle rect = new Rectangle(this.Left + 10, this._Top + this._TitleHeight, this._Width - 20, m_nItemHeight);
556-
m_sf.Alignment = StringAlignment.Near;
557571
foreach (STNodeOption op in this._InputOptions) {
558-
brush.Color = op.TextColor;// this._ForeColor;
559-
dt.Graphics.DrawString(op.Text, this._Font, brush, rect, m_sf);
560-
op.DotLeft = this.Left - 5;
561-
op.DotTop = rect.Y + 5;
562-
Point pt = this.OnSetOptionLocation(op);
563-
op.DotLeft = pt.X;
564-
op.DotTop = pt.Y;
565572
this.OnDrawOptionDot(dt, op);
566-
rect.Y += m_nItemHeight;
573+
this.OnDrawOptionText(dt, op);
567574
}
568-
rect.Y = this._Top + this._TitleHeight;
569-
m_sf.Alignment = StringAlignment.Far;
570575
foreach (STNodeOption op in this._OutputOptions) {
571-
brush.Color = op.TextColor;// this._ForeColor;
572-
dt.Graphics.DrawString(op.Text, this._Font, brush, rect, m_sf);
573-
op.DotLeft = this.Left + this.Width - 5;
574-
op.DotTop = rect.Y + 5;
575-
Point pt = this.OnSetOptionLocation(op);
576-
op.DotLeft = pt.X;
577-
op.DotTop = pt.Y;
578576
this.OnDrawOptionDot(dt, op);
579-
rect.Y += m_nItemHeight;
577+
this.OnDrawOptionText(dt, op);
580578
}
581579
if (this._Controls.Count != 0) { //绘制子控件
582580
//将坐标原点与节点对齐
@@ -655,12 +653,38 @@ protected virtual void OnDrawOptionDot(DrawingTools dt, STNodeOption op) {
655653
}
656654
}
657655
/// <summary>
658-
/// 当计算Option位置时候发生
656+
/// 绘制选项的文本
657+
/// </summary>
658+
/// <param name="dt">绘制工具</param>
659+
/// <param name="op">指定的选项</param>
660+
protected virtual void OnDrawOptionText(DrawingTools dt, STNodeOption op) {
661+
Graphics g = dt.Graphics;
662+
SolidBrush brush = dt.SolidBrush;
663+
if (op.IsInput) {
664+
m_sf.Alignment = StringAlignment.Near;
665+
} else {
666+
m_sf.Alignment = StringAlignment.Far;
667+
}
668+
brush.Color = op.TextColor;
669+
g.DrawString(op.Text, this.Font, brush, op.TextRectangle, m_sf);
670+
}
671+
/// <summary>
672+
/// 当计算Option连线点位置时候发生
659673
/// </summary>
660674
/// <param name="op">需要计算的Option</param>
675+
/// <param name="pt">自动计算出的位置</param>
661676
/// <returns>新的位置</returns>
662-
protected virtual Point OnSetOptionLocation(STNodeOption op) {
663-
return new Point(op.DotLeft, op.DotTop);
677+
protected virtual Point OnSetOptionDotLocation(STNodeOption op, Point pt) {
678+
return pt;
679+
}
680+
/// <summary>
681+
/// 当计算Option文本区域时候发生
682+
/// </summary>
683+
/// <param name="op">需要计算的Option</param>
684+
/// <param name="rect">自动计算出的区域</param>
685+
/// <returns>新的区域</returns>
686+
protected virtual Rectangle OnSetOptionTextRectangle(STNodeOption op, Rectangle rect) {
687+
return rect;
664688
}
665689
/// <summary>
666690
/// 计算当前Node所需要的矩形区域
@@ -712,6 +736,7 @@ protected virtual void OnSaveNode(Dictionary<string, byte[]> dic) { }
712736
/// </summary>
713737
/// <param name="dic">保存时候的数据</param>
714738
protected internal virtual void OnLoadNode(Dictionary<string, byte[]> dic) {
739+
if (dic.ContainsKey("Guid")) this._Guid = new Guid(dic["Guid"]);
715740
if (dic.ContainsKey("Left")) this._Left = BitConverter.ToInt32(dic["Left"], 0);
716741
if (dic.ContainsKey("Top")) this._Top = BitConverter.ToInt32(dic["Top"], 0);
717742
if (dic.ContainsKey("Mark")) {
@@ -721,6 +746,12 @@ protected internal virtual void OnLoadNode(Dictionary<string, byte[]> dic) {
721746
if (dic.ContainsKey("LockOption")) this._LockOption = dic["LockOption"][0] == 1;
722747
if (dic.ContainsKey("LockLocation")) this._LockLocation = dic["LockLocation"][0] == 1;
723748
}
749+
/// <summary>
750+
/// 当编辑器加载完成所有的节点时候发生
751+
/// </summary>
752+
protected internal virtual void OnEditorLoadCompleted() {
753+
754+
}
724755

725756
//[event]===========================[event]==============================[event]============================[event]
726757

@@ -821,8 +852,8 @@ protected internal virtual void OnKeyPress(KeyPressEventArgs e) {
821852
if (m_ctrl_active != null) m_ctrl_active.OnKeyPress(e);
822853
}
823854

824-
protected internal virtual void OnMove(EventArgs e) { }
825-
protected internal virtual void OnResize(EventArgs e) { }
855+
protected internal virtual void OnMove(EventArgs e) { this.SetOptionLocation(); }
856+
protected internal virtual void OnResize(EventArgs e) { this.SetOptionLocation(); }
826857

827858

828859
/// <summary>
@@ -840,6 +871,26 @@ protected virtual void OnActiveChanged() { }
840871

841872
#endregion protected
842873

874+
private void SetOptionLocation() {
875+
Rectangle rect = new Rectangle(this.Left + 10, this._Top + this._TitleHeight, this._Width - 20, m_nItemHeight);
876+
foreach (STNodeOption op in this._InputOptions) {
877+
Point pt = this.OnSetOptionDotLocation(op, new Point(this.Left - 5, rect.Y + 5));
878+
op.TextRectangle = this.OnSetOptionTextRectangle(op, rect);
879+
op.DotLeft = pt.X;
880+
op.DotTop = pt.Y;
881+
rect.Y += m_nItemHeight;
882+
}
883+
rect.Y = this._Top + this._TitleHeight;
884+
m_sf.Alignment = StringAlignment.Far;
885+
foreach (STNodeOption op in this._OutputOptions) {
886+
Point pt = this.OnSetOptionDotLocation(op, new Point(this._Left + this._Width - 5, rect.Y + 5));
887+
op.TextRectangle = this.OnSetOptionTextRectangle(op, rect);
888+
op.DotLeft = pt.X;
889+
op.DotTop = pt.Y;
890+
rect.Y += m_nItemHeight;
891+
}
892+
}
893+
843894
/// <summary>
844895
/// 重绘Node
845896
/// </summary>

ST.Library.UI/STNodeEditor/STNodeCollection.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public int Add(STNode node) {
2727
if (-1 == nIndex) {
2828
nIndex = this._Count;
2929
node.Owner = m_owner;
30-
node.BuildSize(true, true, false);
30+
//node.BuildSize(true, true, false);
3131
m_nodes[this._Count++] = node;
3232
m_owner.BuildBounds();
3333
m_owner.OnNodeAdded(new STNodeEditorEventArgs(node));
@@ -87,7 +87,7 @@ public void Insert(int nIndex, STNode node) {
8787
node.Owner = m_owner;
8888
m_nodes[nIndex] = node;
8989
this._Count++;
90-
node.BuildSize(true, true,false);
90+
//node.BuildSize(true, true,false);
9191
m_owner.Invalidate();
9292
m_owner.BuildBounds();
9393
}
@@ -225,5 +225,12 @@ object ICollection.SyncRoot {
225225
IEnumerator IEnumerable.GetEnumerator() {
226226
return this.GetEnumerator();
227227
}
228+
229+
public STNode[] ToArray() {
230+
STNode[] nodes = new STNode[this._Count];
231+
for (int i = 0; i < nodes.Length; i++)
232+
nodes[i] = m_nodes[i];
233+
return nodes;
234+
}
228235
}
229236
}

0 commit comments

Comments
 (0)