I would like to know if there is a way to block this operation: user trying to link 2, 3, … any times one node to the same node…see my image ( Step 1 to Step 3, 2 links at the same node…)
How to block this operation in FlowChart project, for example?
Hi Jake, sorry, but I still don´t know how to resolve my problem using my class… Not allow 2 links from the same Task to another task…Can you send me more information? Thanks!!!
See my Task class…
//TaskProcessItem Class: Task
public class TaskProcessItem : GoTextNode
{
//Variables
private ItemKind mProcessItemKind;
private ResourceManager rm;
//This field keeps track of this process item image
private ProcessItemImage mProcessItemImage;
private Color mfirst_color = Color.White;
private Color msecond_color = Color.White;
//Constructor with parameter to create Process Item
public TaskProcessItem(ItemKind prcItemKind)
{
//Resources
rm = new ResourceManager("constants", this.GetType().Assembly);
//Reset variables
mProcessItemImage = null;
mProcessItemKind = ItemKind.None;
//Change internal Object kind
this.ProcessItemKind = prcItemKind;
}
//This property is for convenience in accessing the Process Item Image class
public ProcessItemImage ProcessImage
{
get { return mProcessItemImage; }
}
//Adjust port positions for certain background shapes
public override void LayoutChildren(GoObject childchanged)
{
base.LayoutChildren(childchanged);
//Get Process Image
ProcessItemImage dec = this.ProcessImage;
//Check if image exists and Rectangle as background
if (dec != null && this.Background != null)
{
//Set image position
PointF pt = new PointF(this.Background.Left + 3, this.Background.Top + 1);
if (dec.Image != null)
{
dec.Image.SetSpotLocation(TopLeft, pt);
}
}
}
//When the mouse passes over a node, display all of its ports.All ports on all nodes are hidden when the mouse hovers over the background.
public override bool OnMouseOver(GoInputEventArgs evt, GoView view)
{
ProcessView v = view as ProcessView;
if (v != null)
{
foreach (GoPort p in this.Ports)
{
p.Style = GoPortStyle.Ellipse;
}
}
return false;
}
public ItemKind ProcessItemKind
{
get { return mProcessItemKind; }
set
{
ItemKind old = mProcessItemKind;
if (old != value)
{
mProcessItemKind = value;
OnKindChanged(old, value);
}
}
}
protected virtual void OnKindChanged(ItemKind oldkind, ItemKind newkind)
{
switch (newkind)
{
//Task Types
case ItemKind.Task:
{
ConfigureTaskProcessItem(ItemKind.None, rm.GetString("PROCESS_DIAGRAM_TASK_ITEM_NAME"), mfirst_color, msecond_color);
break;
}
case ItemKind.UserTask:
{
ConfigureTaskProcessItem(ItemKind.UserTask, rm.GetString("PROCESS_DIAGRAM_USERTASK_ITEM_NAME"), mfirst_color, msecond_color);
break;
}
default: throw new InvalidEnumArgumentException("newkind", (int)newkind, typeof(ItemKind));
}
}
protected override GoPort CreatePort(int spot)
{
GoPort p = base.CreatePort(spot);
p.Brush = null;
return p;
}
private void UpdatePorts(String t, String r, String b, String l)
{
//TopPort, RightPort, BottomPort, LeftPort
if (t == "")
{
this.TopPort = null;
}
else
{
if (this.TopPort == null) this.TopPort = CreatePort(MiddleTop);
if (this.TopPort != null)
{
this.TopPort.IsValidFrom = t.IndexOf('o') > -1;
this.TopPort.IsValidTo = t.IndexOf('i') > -1;
}
}
if (r == "")
{
this.RightPort = null;
}
else
{
if (this.RightPort == null) this.RightPort = CreatePort(MiddleRight);
if (this.RightPort != null)
{
this.RightPort.IsValidFrom = r.IndexOf('o') > -1;
this.RightPort.IsValidTo = r.IndexOf('i') > -1;
}
}
if (b == "")
{
this.BottomPort = null;
}
else
{
if (this.BottomPort == null) this.BottomPort = CreatePort(MiddleBottom);
if (this.BottomPort != null)
{
this.BottomPort.IsValidFrom = b.IndexOf('o') > -1;
this.BottomPort.IsValidTo = b.IndexOf('i') > -1;
}
}
if (l == "")
{
this.LeftPort = null;
}
else
{
if (this.LeftPort == null) this.LeftPort = CreatePort(MiddleLeft);
if (this.LeftPort != null)
{
this.LeftPort.IsValidFrom = l.IndexOf('o') > -1;
this.LeftPort.IsValidTo = l.IndexOf('i') > -1;
}
}
}
//Configure each Task process item
private void ConfigureTaskProcessItem(ItemKind PrcItemKind, string ProcessItemText, Color first, Color second)
{
//Insert Image
ProcessItemImage m_PocessItemImage = new ProcessItemImage(PrcItemKind);
mProcessItemImage = m_PocessItemImage;
InsertBefore(this.Background, m_PocessItemImage);
this.Text = ProcessItemText;
GoRoundedRectangle bkground_shape = new GoRoundedRectangle();
bkground_shape.Corner = new SizeF(5, 5);
this.Background = bkground_shape;
if (ProcessImage != null)
{
this.ProcessImage.AutoRescales = false;
}
this.AutoResizes = true;
this.Resizable = false;
this.Shape.FillShapeHighlight(first, second);
this.TopLeftMargin = new SizeF(10, 10);
this.BottomRightMargin = new SizeF(10, 0);
this.Editable = true;
this.Shadowed = false;
this.Label.Wrapping = true;
this.Label.Editable = true;
this.Label.Alignment = Middle;
this.Pen = new Pen(Color.Black, 1);
UpdatePorts("io", "io", "io", "io");
}
}
You want to override IsValidLink (in either GoPort or GoToolLinking… GoPort may make more sense in this case) and return false if your code detects a link from Node A to Node B.