private void MakeTemporaryLink() { if (myLink == null) { // create a new link starting at the bottom port of the first block GoLink l = new GoLink(); l.Orthogonal = true; GoPort fp = new GoPort(); fp.Style = GoPortStyle.Rectangle; fp.FromSpot = this.Predecessor.BottomPort.FromSpot; fp.Bounds = this.Predecessor.BottomPort.Bounds; l.FromPort = fp; GoPort tp = new GoPort(); tp.Size = new SizeF(1, 1); tp.Position = this.LastInput.DocPoint; tp.ToSpot = GoObject.MiddleTop; l.ToPort = tp; // the link is temporarily a view object this.View.Layers.Default.Add(l); myLink = l; } }
/// <summary> /// If any part is removed from this group, /// be sure to remove any references in local fields. /// </summary> /// <param name="obj"></param> public override bool Remove(GoObject obj) { bool result = base.Remove(obj); if (obj == myBack) { myBack = null; return(result); } if (obj == myLabel) { myLabel = null; return(result); } if (obj == myTopPort) { myTopPort = null; return(result); } if (obj == myRightPort) { myRightPort = null; return(result); } if (obj == myBottomPort) { myBottomPort = null; return(result); } if (obj == myLeftPort) { myLeftPort = null; } return(result); }
/// <summary> /// Handle this class's property changes for undo and redo /// </summary> /// <param name="e"></param> /// <param name="undo"></param> public override void ChangeValue(GoChangedEventArgs e, bool undo) { switch (e.SubHint) { case 2101: LabelSpot = e.GetInt(undo); break; case 2102: Shape = (GoShape)e.GetValue(undo); break; case 2103: Label = (GoText)e.GetValue(undo); break; case 2104: Port = (GoPort)e.GetValue(undo); break; case 2105: MiddleLabelMargin = e.GetSize(undo); break; case 2106: AutoResizes = (bool)e.GetValue(undo); break; default: base.ChangeValue(e, undo); break; } }
protected override GoPort CreatePort(int spot) { GoPort p = base.CreatePort(spot); p.Brush = null; return(p); }
// Implement a simple tree-layout algorithm public float LayoutTree(TextNode node, float oldx, float oldy) { float origy = oldy; float newy = oldy; // recurse through all the node's children GoPort outp = node.RightPort; // for each link attached to the output port... foreach (GoLink link in outp.Links) { // in case we link things up in the wrong direction sometime in the future, // this gets the other end of the link no matter which way we're going GoPort inp = link.GetOtherPort(outp) as GoPort; if (inp == null) { continue; } // get the child node, and lay it out recursively if not already positioned TextNode child = (TextNode)inp.Parent; if (child.Top <= 0) { newy = LayoutTree(child, oldx + node.Width + myHorizSeparation, oldy); // increment the Y position for the next child, if any oldy = newy + node.Height + myVertSeparation; } } // position this node at the average Y position of the children node.Position = new PointF(oldx, (origy + newy) / 2); return(newy); // updated by recursive layoutTree calls }
/// <summary> /// If any part is removed from this group, /// be sure to remove any references in local fields. /// </summary> /// <param name="obj"></param> public override bool Remove(GoObject obj) { bool result = base.Remove(obj); if (obj == myIcon) { myIcon = null; return(result); } if (obj == myLabel) { myLabel.RemoveObserver(this); myLabel = null; return(result); } if (obj == myInPort) { myInPort = null; return(result); } if (obj == myOutPort) { myOutPort = null; } return(result); }
/// <summary> /// Create a GoTextNode with four ports and a <see cref="T:Northwoods.Go.GoDrawing" /> background, /// initialized to have the figure <paramref name="fig" />. /// </summary> /// <param name="fig">a <see cref="T:Northwoods.Go.GoFigure" /> enumeration value</param> /// <remarks> /// This constructor basically does the following, but more efficiently: /// <pre><code> /// GoTextNode n = new GoTextNode(); /// n.Background = new GoDrawing(fig); /// </code></pre> /// </remarks> public GoTextNode(GoFigure fig) { base.InternalFlags &= -17; base.InternalFlags |= 16908288; myBack = new GoDrawing(fig) { Selectable = false, Resizable = false, Reshapable = false, Brush = GoShape.Brushes_LightGray }; Add(myBack); myLabel = CreateLabel(); Add(myLabel); myTopPort = CreatePort(32); Add(myTopPort); myRightPort = CreatePort(64); Add(myRightPort); myBottomPort = CreatePort(128); Add(myBottomPort); myLeftPort = CreatePort(256); Add(myLeftPort); base.Initializing = false; LayoutChildren(null); }
public new GoPort CreatePort(int spot) { GoPort p = base.CreatePort(spot); p.Size = new SizeF(p.Size.Width * 2, p.Size.Height * 2); p.EndSegmentLength = 15 + 5; // arrowheadlength + some offset p.Brush = null; return(p); }
private void initializeCommon(string name) { myLabel = CreateLabel(name); Add(myLabel); myPort = CreatePort(); Add(myPort); base.PropertiesDelegatedToSelectionObject = true; base.Initializing = false; LayoutChildren(null); }
/// <summary> /// Construct a GoBoxNode that by default has a body that is a multiline /// <see cref="T:Northwoods.Go.GoText" /> object with a white background. /// </summary> /// <remarks> /// This calls <see cref="M:Northwoods.Go.GoBoxNode.CreatePort" /> and <see cref="M:Northwoods.Go.GoBoxNode.CreateBody" /> /// to get initial values for <see cref="P:Northwoods.Go.GoBoxNode.Port" /> and <see cref="P:Northwoods.Go.GoBoxNode.Body" />. /// </remarks> public GoBoxNode() { base.InternalFlags |= 131072; base.InternalFlags &= -17; myPort = CreatePort(); Add(myPort); myBody = CreateBody(); Add(myBody); base.Initializing = false; LayoutChildren(null); }
/// <summary> /// Create and initialize a <see cref="T:Northwoods.Go.GoShape" />. /// </summary> /// <param name="p">the <see cref="T:Northwoods.Go.GoPort" /> created for this node by <see cref="M:Northwoods.Go.GoBasicNode.CreatePort" /></param> /// <returns> /// By default this returns a <see cref="T:Northwoods.Go.GoEllipse" /> that is somewhat larger than the port <paramref name="p" />. /// </returns> /// <remarks> /// By default the ellipse uses a white brush--set the <see cref="P:Northwoods.Go.GoBasicNode.Pen" /> /// and <see cref="P:Northwoods.Go.GoBasicNode.Brush" /> properties to change the appearance. /// The shape is not itself selectable, resizable, or reshapable. /// </remarks> /// <example> /// If you override this method, you may want the definition to do /// some of the things that the standard definition does: /// <code> /// protected virtual GoShape CreateShape(GoPort p) { /// // create the bigger circle/ellipse around and behind the port /// GoShape e = new GoEllipse(); /// SizeF psize = p.Size; /// e.Size = new SizeF(psize.Width + 2*7, psize.Height + 2*7); /// e.Selectable = false; /// e.Resizable = false; /// e.Reshapable = false; /// e.Brush = GoShape.Brushes_White; /// return e; /// } /// </code> /// </example> protected virtual GoShape CreateShape(GoPort p) { GoEllipse goEllipse = new GoEllipse(); SizeF size = p.Size; goEllipse.Size = new SizeF(size.Width + 2f * DefaultShapeMargin.Width, size.Height + 2f * DefaultShapeMargin.Height); goEllipse.Selectable = false; goEllipse.Resizable = false; goEllipse.Reshapable = false; goEllipse.Brush = GoShape.Brushes_White; return(goEllipse); }
/// <summary> /// If any part is removed from this group, /// be sure to remove any references in local fields. /// </summary> /// <param name="obj"></param> public override bool Remove(GoObject obj) { bool result = base.Remove(obj); if (obj == myBody) { myBody = null; return(result); } if (obj == myPort) { myPort = null; } return(result); }
/// <summary> /// Create a GoBasicNode with just a port and a shape centered behind the port, /// but no label. /// </summary> /// <remarks> /// This calls <see cref="M:Northwoods.Go.GoBasicNode.CreatePort" /> and <see cref="M:Northwoods.Go.GoBasicNode.CreateShape(Northwoods.Go.GoPort)" /> /// to get initial values for <see cref="P:Northwoods.Go.GoBasicNode.Port" /> and <see cref="P:Northwoods.Go.GoBasicNode.Shape" />. /// </remarks> public GoBasicNode() { base.InternalFlags |= 16908288; myPort = CreatePort(); myShape = CreateShape(myPort); Add(myShape); Add(myPort); if (myPort != null) { myPort.PortObject = myShape; } base.PropertiesDelegatedToSelectionObject = true; base.Initializing = false; LayoutChildren(null); }
public GoPort FindNearestPort(PointF pt, GraphNode gn) { float maxdist = 10e20f; GoPort closest = null; GoPort p; p = gn.TopPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } p = gn.RightPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } p = gn.BottomPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } p = gn.LeftPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } return(closest); }
public GoPort FindNearestPort(PointF pt, FlowBlock fb) { float maxdist = 10e20f; GoPort closest = null; GoPort p; p = fb.TopPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } p = fb.RightPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } p = fb.BottomPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } p = fb.LeftPort; if (p != null) { float dist = (p.Left - pt.X) * (p.Left - pt.X) + (p.Top - pt.Y) * (p.Top - pt.Y); if (dist < maxdist) { maxdist = dist; closest = p; } } return(closest); }
private void initializeCommon(string name) { myText = name; myLabel = CreateLabel(name); Add(myLabel); if (myLabel != null) { myLabel.AddObserver(this); } myInPort = CreatePort(input: true); Add(myInPort); myOutPort = CreatePort(input: false); Add(myOutPort); base.PropertiesDelegatedToSelectionObject = true; base.Initializing = false; LayoutChildren(null); }
/// <summary> /// Handle this class's property changes for undo and redo /// </summary> /// <param name="e"></param> /// <param name="undo"></param> public override void ChangeValue(GoChangedEventArgs e, bool undo) { switch (e.SubHint) { case 2801: Label = (GoText)e.GetValue(undo); break; case 2802: Background = (GoObject)e.GetValue(undo); break; case 2803: TopPort = (GoPort)e.GetValue(undo); break; case 2804: RightPort = (GoPort)e.GetValue(undo); break; case 2805: BottomPort = (GoPort)e.GetValue(undo); break; case 2806: LeftPort = (GoPort)e.GetValue(undo); break; case 2807: TopLeftMargin = e.GetSize(undo); break; case 2808: BottomRightMargin = e.GetSize(undo); break; case 2809: AutoResizes = (bool)e.GetValue(undo); break; default: base.ChangeValue(e, undo); break; } }
/// <summary> /// Create a top or bottom port for this node. /// </summary> /// <param name="top"></param> /// <returns></returns> /// <example> /// If you override this method, you may want the definition to do /// some of the things that the standard definition does: /// <code> /// public virtual GoObject CreateEndPort(bool top) { /// GoPort p = new GoPort(); /// p.Size = new SizeF(5, 3); /// p.Style = GoPortStyle.None; /// if (top) { /// p.FromSpot = MiddleTop; /// p.ToSpot = MiddleTop; /// } else { /// p.FromSpot = MiddleBottom; /// p.ToSpot = MiddleBottom; /// } /// return p; /// } /// </code> /// </example> public virtual GoObject CreateEndPort(bool top) { GoPort goPort = new GoPort(); goPort.Size = new SizeF(5f, 3f); goPort.Style = GoPortStyle.None; if (top) { goPort.FromSpot = 32; goPort.ToSpot = 32; } else { goPort.FromSpot = 128; goPort.ToSpot = 128; } return(goPort); }
/// <summary> /// Create and initialize a port that may go on either the left side or the right side. /// </summary> /// <param name="left"></param> /// <param name="idx"></param> /// <returns>by default, a <see cref="T:Northwoods.Go.GoPort" /></returns> /// <remarks> /// </remarks> /// <example> /// If you override this method, you may want the definition to do /// some of the things that the standard definition does: /// <code> /// public virtual GoObject CreatePort(bool left, int idx) { /// GoPort p = new GoPort(); /// p.Size = new SizeF(3, 5); /// p.Style = GoPortStyle.None; /// if (left) { /// p.FromSpot = MiddleLeft; /// p.ToSpot = MiddleLeft; /// } else { /// p.FromSpot = MiddleRight; /// p.ToSpot = MiddleRight; /// } /// return p; /// } /// </code> /// </example> public virtual GoObject CreatePort(bool left, int idx) { GoPort goPort = new GoPort(); goPort.Size = new SizeF(3f, 5f); goPort.Style = GoPortStyle.None; if (left) { goPort.FromSpot = 256; goPort.ToSpot = 256; } else { goPort.FromSpot = 64; goPort.ToSpot = 64; } return(goPort); }
/// <summary> /// Create a GoTextNode displaying an empty text string with a rectangular /// background and a port at each side. /// </summary> /// <remarks> /// This calls <see cref="M:Northwoods.Go.GoTextNode.CreateBackground" />, <see cref="M:Northwoods.Go.GoTextNode.CreateLabel" />, /// and <see cref="M:Northwoods.Go.GoTextNode.CreatePort(System.Int32)" /> for each of the four <c>Middle...</c> spots, /// to get initial values for <see cref="P:Northwoods.Go.GoTextNode.Background" />, <see cref="P:Northwoods.Go.GoTextNode.Label" />, /// <see cref="P:Northwoods.Go.GoTextNode.TopPort" />, <see cref="P:Northwoods.Go.GoTextNode.RightPort" />, <see cref="P:Northwoods.Go.GoTextNode.BottomPort" />, /// and <see cref="P:Northwoods.Go.GoTextNode.LeftPort" />. /// </remarks> public GoTextNode() { base.InternalFlags &= -17; base.InternalFlags |= 16908288; myBack = CreateBackground(); Add(myBack); myLabel = CreateLabel(); Add(myLabel); myTopPort = CreatePort(32); Add(myTopPort); myRightPort = CreatePort(64); Add(myRightPort); myBottomPort = CreatePort(128); Add(myBottomPort); myLeftPort = CreatePort(256); Add(myLeftPort); base.Initializing = false; LayoutChildren(null); }
/// <summary> /// Because the label may be selectable and deleted by the user, /// be sure to remove any reference to the label. /// </summary> /// <param name="obj"></param> /// <remarks> /// Remember to override this to clear any child object references you add to this class. /// </remarks> public override bool Remove(GoObject obj) { bool result = base.Remove(obj); if (obj == myIcon) { myIcon = null; return(result); } if (obj == myLabel) { myLabel = null; return(result); } if (obj == myPort) { myPort = null; } return(result); }
public override void main() { IList <Thread> thread_list = new List <Thread> (); // Disparar todos os componentes de computação e sincronizadores (activate kind). foreach (string port_name in PortNames) { gov.cca.Port unit = Services.getPort(port_name); if (unit is GoPort) { GoPort unit_go = (GoPort)unit; Thread tgo = new Thread(new ThreadStart(() => unit_go.go())); tgo.Start(); } } foreach (Thread t in thread_list) { t.Join(); } }
public override void DoMouseMove() { if (myLink != null && myLink.ToPort != null) { GoPort p = myLink.ToPort.GoObject as GoPort; if (p != null) { p.Position = this.LastInput.DocPoint; FlowBlock gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as FlowBlock; if (gn != null && gn != this.Predecessor && !FlowView.IsLinked(this.Predecessor, gn)) { GoPort nearest = FindNearestPort(this.LastInput.DocPoint, gn); if (nearest != null) { p.Position = nearest.Position; p.ToSpot = nearest.ToSpot; } } } } }
public override void DoMouseDown() { if (this.Predecessor == null) { FlowBlock gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as FlowBlock; if (gn == null) { return; } if (!gn.IsPredecessor) { return; } this.Predecessor = gn; MainBase.App.SetStatusMessage("From block " + this.Predecessor.Text); MakeTemporaryLink(); } else { FlowBlock gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as FlowBlock; if (gn != null && gn != this.Predecessor && !FlowView.IsLinked(this.Predecessor, gn)) { // delete the temporary link this.View.Layers.Default.Remove(myLink); myLink = null; // create the link in the design GoPort nearest = FindNearestPort(this.LastInput.DocPoint, gn); IGoLink link = this.View.CreateLink(this.Predecessor.BottomPort, nearest); if (link != null) { this.TransactionResult = "New link"; this.View.RaiseLinkCreated(link.GoObject); this.View.Selection.Select(link.GoObject); } StopTool(); } } }
public override void DoMouseDown() { if (this.Predecessor == null) { GraphNode gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as GraphNode; if (gn == null) { return; } if (!gn.IsPredecessor) { return; } this.Predecessor = gn; MainForm.App.SetStatusMessage("Predecessor will be " + this.Predecessor.Text); MakeTemporaryLink(); } else { GraphNode gn = this.View.PickObject(true, false, this.LastInput.DocPoint, true) as GraphNode; if (gn != null && gn != this.Predecessor && !GraphView.IsLinked(this.Predecessor, gn)) { // get rid of the temporary link this.View.Layers.Default.Remove(myLink); myLink = null; // create the link in the document GoPort nearest = FindNearestPort(this.LastInput.DocPoint, gn); IGoLink link = this.View.CreateLink(this.Predecessor.BottomPort, nearest); if (link != null) { this.TransactionResult = "New Relationship"; this.View.RaiseLinkCreated(link.GoObject); this.View.Selection.Select(link.GoObject); } StopTool(); } } }
/// <summary> /// Create a GoBasicNode with a port and a label and a <see cref="T:Northwoods.Go.GoDrawing" /> shape, /// initialized to have the figure <paramref name="fig" /> and a Middle <see cref="P:Northwoods.Go.GoBasicNode.LabelSpot" />. /// </summary> /// <param name="fig">a <see cref="T:Northwoods.Go.GoFigure" /> enumeration value</param> /// <remarks> /// This constructor basically does the following, but more efficiently: /// <pre><code> /// GoBasicNode n = new GoBasicNode(); /// n.LabelSpot = GoObject.Middle; /// n.Text = ""; /// n.Shape = new GoDrawing(fig); /// </code></pre> /// </remarks> public GoBasicNode(GoFigure fig) { base.InternalFlags |= 16908288; myLabelSpot = 1; myShape = new GoDrawing(fig); myShape.Selectable = false; myShape.Resizable = false; myShape.Reshapable = false; myShape.Brush = GoShape.Brushes_White; myPort = CreatePort(); myPort.Style = GoPortStyle.None; myLabel = CreateLabel(""); Add(myShape); Add(myPort); Add(myLabel); if (myPort != null) { myPort.PortObject = myShape; } base.PropertiesDelegatedToSelectionObject = true; base.Initializing = false; LayoutChildren(null); }
public void TruncateLabel() { GoText lab = this.FromLabel as GoText; GoPort fp = this.FromPort as GoPort; GoPort tp = this.ToPort as GoPort; if (lab == null || fp == null || tp == null) { return; } string s = _msg; float w = Math.Abs(tp.Center.X - fp.Center.X) - 10; while (s.Length > 0) { lab.Text = s; if (lab.Width < w) { break; } s = s.Substring(1); } }
private void findAllAux <T>(GoObject obj, Search s, List <T> items) { IGoPort goPort = obj as IGoPort; if (goPort != null) { if ((s & Search.Ports) != 0) { addItem(items, (T)goPort); } GoPort goPort2 = goPort as GoPort; if (goPort2 != null) { foreach (IGoLink link in goPort2.Links) { considerLink(link, goPort, s, items); } } else { foreach (IGoLink link2 in goPort.Links) { considerLink(link2, goPort, s, items); } } } GoGroup goGroup = obj as GoGroup; if (goGroup != null) { foreach (GoObject item in goGroup.GetEnumerator()) { findAllAux(item, s, items); } } }
public void addPort(GoPort port) { ports.Add(port); }