void Select(UCTopologyItem top) { if (top == null) { if (cmItems.SelectedItem != null && cmItems.SelectedItem is UCTopologyItem) { ((UCTopologyItem)cmItems.SelectedItem).Selected = false; } propertyGrid1.SelectedObject = _Vars.Designer; propertyGrid1.ExpandAllGridItems(); cmItems.SelectedItem = null; _Current = new ConnectedLine(); pItems.Invalidate(); } else { cmItems.SelectedItem = top; propertyGrid1.SelectedObject = top.Item; propertyGrid1.ExpandAllGridItems(); top.Selected = true; } propertyGrid1.Update(); }
void CreateItem(ITopologyItem n, Point location) { if (n == null) { return; } UCTopologyItem top = new UCTopologyItem(n); top.Location = location; n.Tag = top; top.RefreshInPlay(_InPlay); top.MouseDown += pictureBox1_MouseDown; top.MouseMove += pictureBox1_MouseMove; pItems.Controls.Add(top); n.OnProcess += Item_OnProcess; _List.Add(top); if (n is IDataInput) { IDataInput i = (IDataInput)n; _Inputs.Add(i); if (_InPlay) { _Inputs.Stop(); _Inputs.Start(); } } Select(top); }
void pictureBox1_MouseDown(object sender, MouseEventArgs e) { UCTopologyItem top = (UCTopologyItem)sender; MouseDownLocation = e.Location; Select(top); switch (e.Button) { default: { if (_Current.From != null) { goto case MouseButtons.Right; } break; } case MouseButtons.Right: { if (_Current.From == null) { _Current.From = top; pItems.Invalidate(); } else { if (_Current.IsAllowed(top)) { if (_Current.Apply(top)) { _Lines.Add(_Current); _Current = new ConnectedLine(); pItems.Invalidate(); } else { _Current.To = null; _Current.From = null; pItems.Invalidate(); } } else { _Current.To = null; _Current.From = null; pItems.Invalidate(); } } break; } } }
public bool IsAllowed(UCTopologyItem to) { if (to == null) { return(false); } ITopologyItem tfrom = FromItem; ITopologyItem tto = to.Item; if (tfrom is IDataInput || tfrom is IDataProcess) { return(tto is IDataProcess); } return(false); }
void Delete(UCTopologyItem uc) { if (uc.Item is IDataInput) { IDataInput i = (IDataInput)uc.Item; _Inputs.Remove(i); if (i.RaiseMode != null) { i.RaiseMode.Stop(i); } } uc.Item.OnProcess -= Item_OnProcess; _List.Remove(uc); uc.Parent.Controls.Remove(uc); uc.Dispose(); }
void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { if (propertyGrid1.SelectedObject is ITopologyItem) { ITopologyItem t = (ITopologyItem)propertyGrid1.SelectedObject; pItems.Invalidate(true); UCTopologyItem c = SearchControl(t); if (c != null) { c.RefreshDesign(); } for (int x = 0; x < _List.Count; x++) { _List.ResetItem(x); } } }
void Item_OnProcess(ITopologyItem sender, EProcessState state) { if (sender == null) { return; } UCTopologyItem uc = (UCTopologyItem)sender.Tag; if (uc != null) { // Activamos el procesado uc.AreInUse.InUse = state == EProcessState.PreProcess; uc.Invalidate(); } // Controlamos las lineas de conexión foreach (ConnectedLine l in _Lines) { if (state == EProcessState.PreProcess) { // Desactivar todas las lineas que iban a él if (l.ToItem == sender) { l.AreInUse.InUse = false; } } else { // Activar todas las lineas que salen de él if (l.FromItem == sender) { l.AreInUse.InUse = true; } } } pItems.Invalidate(false); }
public bool Apply(UCTopologyItem top) { if (!IsAllowed(top)) { return(false); } ITopologyItem to = top.Item; if (to is IDataProcess) { DataProcessCollection proc = From.Item.Process; if (!proc.Contains((IDataProcess)to)) { proc.Add((IDataProcess)to); To = top; return(true); } } return(false); }
void LoadFile(string fileName) { TLYFile t = null; bool isFile = false; try { if (File.Exists(fileName)) { t = TLYFile.LoadFromFile(fileName); isFile = true; } else { t = TLYFile.Load(fileName); } } catch (Exception e) { ITopologyItem_OnException(null, e); return; } if (t != null) { NewTopology(); if (isFile) { LasterHelper.SetEnvironmentPath(fileName); LastFile = fileName; } else { LasterHelper.SetEnvironmentPath(""); LastFile = ""; } if (t.Variables != null) { foreach (Variable v in t.Variables) { _Vars.Add(v.Clone()); } } if (t.Items.Values != null) { foreach (TLYFile.TopologyItem i in t.Items.Values) { CreateItem(i.Item, i.Position); } if (t.Relations != null) { foreach (TLYFile.Relation rel in t.Relations) { TLYFile.TopologyItem from, to; if (t.Items.TryGetValue(rel.From, out from) && t.Items.TryGetValue(rel.To, out to) && from != null && to != null) { UCTopologyItem searchFrom = SearchControl(from.Item); UCTopologyItem searchTo = SearchControl(to.Item); if (searchFrom != null && searchTo != null) { _Lines.Add(new ConnectedLine() { From = searchFrom, To = searchTo }); if (to.Item is IDataProcess) { from.Item.Process.Add((IDataProcess)to.Item); } } } } } } pItems.Invalidate(); } }
void FEditTopology_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Escape: { if (_Current.From != null) { _Current.From = null; _Current.To = null; pItems.Invalidate(); e.Handled = true; e.SuppressKeyPress = true; } break; } case Keys.Delete: { if (ActiveControl == propertyGrid1) { return; } if (_Current.From != null) { goto case Keys.Escape; } UCTopologyItem uc = (UCTopologyItem)cmItems.SelectedItem; if (uc != null) { bool entra = false; for (int x = _Lines.Count - 1; x >= 0; x--) { ConnectedLine c = _Lines[x]; if (c.From == uc || c.To == uc) { _Lines.Remove(c); c.FromItem.Process.Remove(c.ToItem); entra = true; } } if (!entra) { Delete(uc); foreach (UCTopologyItem c in pItems.Controls) { Select(c); break; } } pItems.Invalidate(); propertyGrid1.Update(); e.Handled = true; e.SuppressKeyPress = true; } break; } } }
void cmItems_SelectedIndexChanged(object sender, EventArgs e) { UCTopologyItem top = (UCTopologyItem)cmItems.SelectedItem; Select(top); }
void cmItems_Format(object sender, ListControlConvertEventArgs e) { UCTopologyItem top = (UCTopologyItem)e.ListItem; e.Value = top.Title; }