Пример #1
0
		/// <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();
		}
Пример #2
0
		internal void complete(PointF point, FlowChart fc)
		{
			cycleRoots.Clear();
			affectedArrows.Clear();
			completing = true;

			// someone might have deleted the item from a selection- change event
			if (currentObject == null)
				return;

			if (action == Action.Create)
			{
				currentObject.completeCreate(point);

				// someone might have deleted the item in itemCreated handler
				if (itemDeleted)
					return;

				invalidRect = Utilities.unionRects(
					invalidRect, currentObject.getRepaintRect(true));
				fc.Dirty = true;

				if (currentObject.getType() != ItemType.Selection)
				{
					// add to the diagram
					AddItemCmd cmd = new AddItemCmd(currentObject);
					cmd.Execute();
					fc.fireObjCreated(currentObject);

					// select the new item if SelectAfterCreate == true;
					// check for null because people just love to delete currObject
					// from within its xCreated or xActivated event handlers
					if (fc.SelectAfterCreate && currentObject != null && !itemDeleted)
					{
						invalidRect = Utilities.unionRects(
							invalidRect, fc.Selection.getRepaintRect(true));
						fc.Selection.Change(currentObject);
						if (currentObject != null)
						{
							invalidRect = Utilities.unionRects(
								invalidRect, currentObject.getRepaintRect(true));
						}
					}

					if (fc.UndoManager.UndoEnabled)
						cmd.saveSelState();
				}
			}
			else
			{
				currentObject.completeModify(point, this);
				fc.UndoManager.onCompleteModify();
				if (!itemDeleted)
				{
					invalidRect = Utilities.unionRects(invalidRect,
						currentObject.getRepaintRect(true));
				}
				fc.Dirty = true;
			}
		}