public void LinkItems(MapItem srcItem, MapItem destItem) { if (srcItem != null && destItem != null) { LinkingArrow arrow = CreateLinkingArrow(srcItem); LinkArrow(arrow, destItem, false); } }
internal LinkingArrow CreateLinkingArrow(MapItem sourceItem) { LinkingArrow arrow = new LinkingArrow(sourceItem, null, LinkingArrowState.Linking); LinkingArrows.Add(CurrentLinkingArrow = arrow); sourceItem.LinkingArrows.Add(arrow); return(arrow); }
internal void UnlinkArrrow(LinkingArrow arrow, MapItem destinationItem, bool manual) { destinationItem.LinkingArrows.Remove(arrow); if (ItemUnlinked != null && arrow.SourceItem != null && arrow.DestinationItem != null) { ItemUnlinked(arrow.SourceItem, arrow.DestinationItem, manual); } arrow.Unlink(); }
private Point GetLinkArrowStartPoint(LinkingArrow arrow) { Rectangle rectangle = arrow.SourceItem.RightLinkPoint.ClientRectangle; rectangle.Offset(arrow.SourceItem.Left, arrow.SourceItem.Top); int x = rectangle.Left + rectangle.Width - 2; int y = rectangle.Top + (rectangle.Height / 2) - 1; Point startPoint = arrow.SourceItem.PointToClient( arrow.SourceItem.PointToScreen(new Point(x, y))); return(startPoint); }
private Point GetLinkArrowEndPoint(LinkingArrow arrow) { if (arrow.DestinationItem != null) { Rectangle rectangle = arrow.DestinationItem.LeftLinkPoint.ClientRectangle; rectangle.Offset(arrow.DestinationItem.Left, arrow.DestinationItem.Top); int x = rectangle.Left; int y = rectangle.Top + (rectangle.Height / 2) - 1; Point endPoint = arrow.DestinationItem.PointToClient( arrow.DestinationItem.PointToScreen(new Point(x, y))); return(endPoint); } return(arrow.EndPoint); }
public void ClearItems() { foreach (MapItem item in Items) { item.Dispose(); } Items.Clear(); foreach (LinkingArrow arrow in LinkingArrows) { arrow.Dispose(); } LinkingArrows.Clear(); CurrentLinkingArrow = null; Repaint(); }
internal void RemoveLinkingArrow(LinkingArrow arrow) { if (arrow.SourceItem != null) { arrow.SourceItem.LinkingArrows.Remove(arrow); } if (arrow.DestinationItem != null) { arrow.DestinationItem.LinkingArrows.Remove(arrow); } LinkingArrows.Remove(arrow); if (CurrentLinkingArrow == arrow) { CurrentLinkingArrow = null; } arrow.Dispose(); }
internal bool LinkArrow(LinkingArrow arrow, MapItem destinationItem, bool manual) { bool cancelled = false; ItemLinking?.Invoke(arrow.SourceItem, destinationItem, out cancelled); if (!cancelled) { arrow.Link(destinationItem); destinationItem.LinkingArrows.Add(arrow); arrow.SourceItem.RightLinkPoint.Selected = destinationItem.LeftLinkPoint.Selected = true; if (CurrentLinkingArrow == arrow) { CurrentLinkingArrow = null; } ItemLinked?.Invoke(arrow.SourceItem, destinationItem, manual); } return(!cancelled); }
private bool CheckOnSelectedItemControlUnhandleMouse() { //No control handled mouse if (_itemControlThatHandledMouse == null) { return(false); } //Get control type ItemControlType controlType = ItemControlTypes.TypesTable[_itemControlThatHandledMouse.GetType()]; switch (controlType) { //LinkPoint case ItemControlType.LinkPoint: { if (ReadOnly) { return(true); } LinkingArrow arrow = Parent.CurrentLinkingArrow; MapItem srcItem = arrow.SourceItem; MapItem destItem = arrow.DestinationItem; //If no endpoint defined for the current linking arrow if (destItem == null) { //Remove linking arrow from parent arrows list Parent.RemoveLinkingArrow(arrow); //Set unselected state for the current link point srcItem.RightLinkPoint.Selected = srcItem.GetRightSideLinkedArrow() != null; } //otherwise connect current linking arrow else { bool cancelled = !Parent.LinkArrow(arrow, destItem, true); //Check if linking was cancelled if (cancelled) { //Remove linking arrow from parent arrows list Parent.RemoveLinkingArrow(arrow); //Set unselected state for the link points destItem.LeftLinkPoint.Selected = srcItem.GetLeftSideLinkedArrow() != null; srcItem.RightLinkPoint.Selected = srcItem.GetRightSideLinkedArrow() != null; } } //Repaint source, destination items and parent if (this != srcItem) { srcItem.Repaint(); } Repaint(); Parent.Repaint(); break; } } //Mouse unhandled return(true); }
private bool CheckOnSelectedItemControlHandleMouse(Point pos) { if (ControlUnderCursor != null) { //Get current control type ItemControlType controlType = ItemControlTypes.TypesTable[ControlUnderCursor.GetType()]; //Store current item control that handled mouse _itemControlThatHandledMouse = ControlUnderCursor; switch (controlType) { //LinkPoint case ItemControlType.LinkPoint: { if (ReadOnly) { return(true); } //For right-side link point if (ControlUnderCursor == RightLinkPoint) { //Add new linking arrow Parent.CreateLinkingArrow(this); //Set selected state for the current link point and repaint self _itemControlThatHandledMouse.Selected = true; Repaint(); } //For left-side link point else { LinkingArrow arrow = GetLeftSideLinkedArrow(); if (arrow != null) { Parent.UnlinkArrrow(arrow, this, true); Parent.CurrentLinkingArrow = arrow; _itemControlThatHandledMouse.Selected = GetLeftSideLinkedArrow() != null; } else { _itemControlThatHandledMouse = null; } } break; } //Image case ItemControlType.Image: { return(false); } } //Case mouse movement CheckOnSelectedItemControlMouseMove(pos); //Mouse handled return(true); } //No control under cursor return(false); }
private void CheckOnSelectedItemControlMouseMove(Point pos) { //No control handled mouse if (_itemControlThatHandledMouse == null) { return; } //Get current control type ItemControlType controlType = ItemControlTypes.TypesTable[_itemControlThatHandledMouse.GetType()]; switch (controlType) { //LinkPoint case ItemControlType.LinkPoint: { if (ReadOnly) { return; } LinkingArrow arrow = Parent.CurrentLinkingArrow; MapItem srcItem = arrow.SourceItem; //Get destionation item under mouse cursor MapItem destItem = Parent.GetItemForLinkingUnderCursor(this, srcItem, pos); //If destionation exists if (destItem != null) { //If destItem not setted yet as destination item for the current linking arrow if (destItem != arrow.DestinationItem) { //Set left link point selected destItem.LeftLinkPoint.Selected = true; arrow.DestinationItem = destItem; //Repaint self and parent Parent.Repaint(); destItem.Repaint(); } } //otherwise else { destItem = arrow.DestinationItem; if (destItem != null) { //Set left link point unselected destItem.LeftLinkPoint.Selected = false; //Repaint self destItem.Repaint(); //Drop destination item references destItem = arrow.DestinationItem = null; } //Update current linking arrow dest point according to mouse position Point point = Parent.PointToClient(PointToScreen(pos)); Parent.UpdateLinkingArrowEndPoint(arrow, point); Parent.Repaint(); } //Temporary set destination item for the current linking arrow arrow.DestinationItem = destItem; break; } } }
internal void UpdateLinkingArrowEndPoint(LinkingArrow arrow, Point endPoint) { arrow.EndPoint = endPoint; }