public void SetEnds(ILinkLineNode start, ILinkLineNode end) { Control c; if (objStart != null) { c = objStart as Control; if (c != null) { c.Move -= new EventHandler(src_Move); } } objStart = start; c = objStart as Control; if (c != null) { c.Move += new EventHandler(src_Move); } if (objEnd != null) { c = objEnd as Control; if (c != null) { c.Move -= new EventHandler(tgt_Move); } } objEnd = end; c = objEnd as Control; if (c != null) { c.Move += new EventHandler(tgt_Move); } this.SetEnds(objStart.Center.X - scrollPos.X, objStart.Center.Y - scrollPos.Y, objEnd.Center.X - scrollPos.X, objEnd.Center.Y - scrollPos.Y); }
void mnuRemovePort_Click(object sender, EventArgs e) { Control p = this.Parent; if (p != null) { ObjectDrawing ov = this.Owner as ObjectDrawing; if (ov != null && ov.ObjectEntity != null && ov.ObjectEntity.ProgEntity != null) { ov.ObjectEntity.ProgEntity.RemoveOutport(this.PortID); this.ClearLine(); p.Controls.Remove(this.Label); p.Controls.Remove(this); ILinkLineNode l = this.NextNode; while (l != null) { l.ClearLine(); p.Controls.Remove((Control)l); l = l.NextNode; } p.Refresh(); IMathDesigner im = p as IMathDesigner; if (im != null) { im.Changed = true; } } } }
public void AssignMapObjects(ILinkLineNode src, ILinkLineNode tgt) { objStart = src; objEnd = tgt; Control c = src as Control; if (c != null) { c.Move += new EventHandler(src_Move); } c = tgt as Control; if (c != null) { c.Move += new EventHandler(tgt_Move); } this.SetEnds(objStart.Center.X - scrollPos.X, objStart.Center.Y - scrollPos.Y, objEnd.Center.X - scrollPos.X, objEnd.Center.Y - scrollPos.Y); }
public void SetEnd(ILinkLineNode obj) { if (objEnd != null) { Control c = objEnd as Control; if (c != null) { c.Move -= new EventHandler(tgt_Move); } } objEnd = obj; if (objEnd != null) { Control c = objEnd as Control; if (c != null) { c.Move += new EventHandler(tgt_Move); } SetEnd(objEnd.Center.X - scrollPos.X, objEnd.Center.Y - scrollPos.Y); } }
public void SetStart(ILinkLineNode obj) { if (objStart != null) { Control c = objStart as Control; if (c != null) { c.Move -= new EventHandler(src_Move); } } objStart = obj; if (objStart != null) { Control c = objStart as Control; if (c != null) { c.Move += new EventHandler(src_Move); } SetStart(objStart.Center.X - scrollPos.X, objStart.Center.Y - scrollPos.Y); } }
/// <summary> /// new load or re-load. /// this control must already be added to the viewer (DiagramViewer). /// It generates ports for all variables /// </summary> /// <param name="data">the result of lower level editing</param> public void LoadData(IMathExpression data) { bLoading = true; DiagramViewer dv = this.Parent as DiagramViewer; VariableList currentVariables = null; IVariable currOutVar = null; if (mathExp != null) { currOutVar = mathExp.OutputVariable; currentVariables = mathExp.InputVariables; } mathExp = data; if (mathExp == null) { mathExp = new MathNodeRoot(); } mathExp.ClearFocus(); //1. find out all unique and non-local variables VariableList _portVariables = mathExp.InputVariables; //2. remove removed ports if (currentVariables != null) { foreach (IVariable v in currentVariables) { if (_portVariables.GetVariableById(v.ID) == null) { //remove port and nodes List <Control> cs = new List <Control>(); foreach (Control c in dv.Controls) { LinkLineNodeInPort p = c as LinkLineNodeInPort; if (p != null) { if (p.PortID == v.ID) { cs.Add(p); cs.Add(p.Label); ILinkLineNode prev = p.PrevNode; while (prev != null) { if (prev is LinkLineNodePort) { break; } cs.Add((Control)prev); prev = prev.PrevNode; } break; } } } foreach (Control c in cs) { dv.Controls.Remove(c); } } } } List <Control> newControls = new List <Control>(); List <LinkLineNodeInPort> newInPorts = new List <LinkLineNodeInPort>(); //3.create new ports foreach (IVariable v in _portVariables) { if (currentVariables == null || currentVariables.GetVariableById(v.ID) == null) { if (data.IsContainer) { //create a new variable instance MathNodeRoot r = new MathNodeRoot(); ((MathNode)v).root.CopyAttributesToTarget(r); r[1] = new MathNodeVariable(r); IVariable vi = (IVariable)r[1]; vi.VariableType = (RaisDataType)v.VariableType.Clone(); vi.VariableName = v.VariableName; vi.SubscriptName = v.SubscriptName; vi.ResetID(v.ID); vi.InPort = new LinkLineNodeInPort(vi); vi.InPort.SetPortOwner(vi); vi.InPort.Owner = this; newControls.Add(vi.InPort); newControls.Add(vi.InPort.Label); vi.InPort.CheckCreatePreviousNode(); newControls.Add((Control)vi.InPort.PrevNode); newInPorts.Add(vi.InPort); } else { v.InPort = new LinkLineNodeInPort(v); v.InPort.Owner = this; newControls.Add(v.InPort); newControls.Add(v.InPort.Label); v.InPort.CheckCreatePreviousNode(); newControls.Add((Control)v.InPort.PrevNode); newInPorts.Add(v.InPort); } } } if (newInPorts.Count > 0) { int dn = this.Width / (newInPorts.Count + 1); for (int i = 0; i < newInPorts.Count; i++) { newInPorts[i].Position = i * dn + dn; newInPorts[i].Left = this.Left + newInPorts[i].Position; newInPorts[i].SaveLocation(); newInPorts[i].PrevNode.Left = newInPorts[i].Left; } } //3. re-map to existing ports if (currOutVar != null && currOutVar.OutPorts != null) { //if port exists then re-use it mathExp.OutputVariable.OutPorts = currOutVar.OutPorts; for (int i = 0; i < mathExp.OutputVariable.OutPorts.Length; i++) { mathExp.OutputVariable.OutPorts[i].SetPortOwner(mathExp.OutputVariable); //if linking exists then re-establish it if (currOutVar.OutPorts[i].LinkedPortID != 0) { //find the variable if (dv != null) { IVariable v = dv.FindVariableById(currOutVar.OutPorts[i].LinkedPortID); if (v != null) { v.InPort.LinkedPortID = mathExp.OutputVariable.ID; } } } } } else { //for a new load, create the output port mathExp.OutputVariable.OutPorts = new LinkLineNodeOutPort[] { new LinkLineNodeOutPort(mathExp.OutputVariable) }; mathExp.OutputVariable.OutPorts[0].CheckCreateNextNode(); ////use the default position mathExp.OutputVariable.OutPorts[0].Position = this.Width / 2; } for (int i = 0; i < mathExp.OutputVariable.OutPorts.Length; i++) { mathExp.OutputVariable.OutPorts[i].Owner = this; mathExp.OutputVariable.OutPorts[i].Label.Visible = false; mathExp.OutputVariable.OutPorts[i].SaveLocation(); } if (!(currOutVar != null && currOutVar.OutPorts != null)) { for (int i = 0; i < mathExp.OutputVariable.OutPorts.Length; i++) { //for a new load, set default postion for the empty linking node ((Control)(mathExp.OutputVariable.OutPorts[i].NextNode)).Location = mathExp.OutputVariable.OutPorts[i].DefaultNextNodePosition(); //add new controls newControls.Add(mathExp.OutputVariable.OutPorts[i]); newControls.Add((Control)mathExp.OutputVariable.OutPorts[i].NextNode); newControls.Add(mathExp.OutputVariable.OutPorts[i].Label); } } //add the new controls if (this.Parent != null && newControls.Count > 0) { Control[] a = new Control[newControls.Count]; newControls.CopyTo(a); this.Parent.Controls.AddRange(a); } mathExp.PrepareDrawInDiagram(); // createImage(); bLoading = false; }
public List <Control> GetRelatedControls() { List <Control> lst = new List <Control>(); lst.Add(this); lst.Add(_label); if (_outPortList != null && _outPortList.Count > 0) { foreach (EventPortOut po in _outPortList) { lst.Add(po); if (po.Label != null) { lst.Add(po.Label); } ILinkLineNode l = po.NextNode; while (l != null && l.NextNode != null) { Control c = l as Control; if (c != null) { lst.Add(c); } l = l.NextNode; } EventPortIn pi = l as EventPortIn; if (pi != null) { lst.Add(pi); if (pi.Label != null) { lst.Add(pi.Label); } ComponentIconEventhandle cieh = pi.Owner as ComponentIconEventhandle; if (cieh != null) { if (cieh.Label != null) { lst.Add(cieh.Label); } lst.Add(cieh); } else { ComponentIconEvent cie = pi.Owner as ComponentIconEvent; if (cie != null) { cie.RemoveDestinationIcon(pi); } } if (this.Parent != null) { foreach (Control c in this.Parent.Controls) { ComponentIconEvent cie = c as ComponentIconEvent; if (cie != null) { List <EventPortIn> pis = cie.DestinationPorts; if (pis != null && pis.Count > 0) { bool b = false; foreach (EventPortIn p in pis) { if (p == pi) { b = true; break; } } if (b) { pis.Remove(pi); break; } } } } } } } } return(lst); }
protected override List <Control> GetRelatedControls() { List <Control> lst = base.GetRelatedControls(); if (_inPortList != null && _inPortList.Count > 0) { foreach (EventPortIn pi in _inPortList) { lst.Add(pi); if (pi.Label != null) { lst.Add(pi.Label); } ILinkLineNode l = pi.PrevNode; while (l != null && l.PrevNode != null) { Control c = l as Control; if (c != null) { lst.Add(c); } l = l.PrevNode; } EventPortOut po = l as EventPortOut; if (po != null) { EventIcon ei = po.Owner as EventIcon; if (ei != null) { if (ei.SourcePorts.Count == 1) { lst.Add(po); if (po.Label != null) { lst.Add(po.Label); } lst.Add(ei); if (ei.Label != null) { lst.Add(ei.Label); } ComponentIconEvent cie = ei.RelativeOwner as ComponentIconEvent; if (cie != null) { if (cie._events != null && cie._events.Contains(ei)) { cie._events.Remove(ei); } } } } } } } if (_events != null && _events.Count > 0) { foreach (EventIcon ei in _events) { lst.AddRange(ei.GetRelatedControls()); } } return(lst); }