/// <summary> /// Adds the specified item to the flowchart. /// </summary> /// <param name="item">A new item that should be added to the flowchart.</param> /// <param name="select">Specifies whether the item should be selected /// after adding it to the flowchart.</param> public void Add(ChartObject item, bool select) { // validity checks can be disabled to save processing time, but beware, // evil things can happen if the item collections are left in invalild state if (validityChecks) { // do not allow adding an item more than once if (zOrder.Contains(item)) return; if (item.getType() == ItemType.Arrow) { Arrow arrow = item as Arrow; // links origin and destination nodes must be in the same diagram if (!zOrder.Contains(arrow.Origin) && (arrow.Origin == null || !(arrow.Origin is DummyNode))) return; if (!zOrder.Contains(arrow.Destination) && (arrow.Destination == null || !(arrow.Destination is DummyNode))) return; } } if (item.getType() == ItemType.ControlHost) { // add the hosted control to the flowchart ControlHost host = item as ControlHost; if (host.Control != null) { this.Controls.Add(host.Control); bringContainedControlToFront(host.Control); } } item.setParent(this); item.setConstructed(); // add to the diagram AddItemCmd cmd = new AddItemCmd(item); cmd.Execute(); RectangleF rc = item.getRepaintRect(false); if (select) { selection.Change(item); rc = Utilities.unionNonEmptyRects(rc, selection.getRepaintRect(true)); } if (undoManager.UndoEnabled) cmd.saveSelState(); // repaint the diagram area covered by the new item if (!LayoutSuspended) invalidate(rc); setDirty(); }