public void NewRelation(UmlRelation rel) { GuiClass c1 = FindClass(rel.src), c2 = FindClass(rel.dest); if (c1 != null && c2 != null) { int ux1 = 1, ux2 = 3; float uy1 = .5f, uy2 = .5f; if (rel.type == UmlRelationType.Association) { ux1 = 0; uy1 = c1.get_empty_point_on_edge(ux1); ux2 = 2; uy2 = c2.get_empty_point_on_edge(ux2); } else if (rel.type == UmlRelationType.Realization || rel.type == UmlRelationType.Inheritance) { uy2 = c2.get_empty_point_on_edge(ux2); } GuiConnection c = new GuiConnection(new GuiConnectionPoint(c1, ux1, uy1, 0), new GuiConnectionPoint(c2, ux2, uy2, 1), rel.type, this, rel.type == UmlRelationType.Attachment ? GuiConnectionStyle.Line : MouseAgent.conn_style); if (rel.type == UmlRelationType.Association) { c.nav = GuiConnectionNavigation.Left; } c.relation_id = rel.ID; c.first.UpdatePosition(true); c.second.UpdatePosition(true); c.DoCreationFixup(); c.ConnectionCreated(this, rel.src_role, rel.dest_role, rel.name, rel.stereo); Undo.Push(new CreateOperation(c), false); } }
private bool MouseMoveAction(int x, int y, MouseButtons b) { switch (action) { case MouseAction.Select: if (selrect != Rectangle.Empty) { parent.cview.InvalidatePage(selrect); } selrect.X = Math.Min(x, selx); selrect.Y = Math.Min(y, sely); selrect.Width = Math.Abs(x - selx); selrect.Height = Math.Abs(y - sely); parent.cview.InvalidatePage(selrect); break; case MouseAction.Move: // on first move if (first_move) { if (original_selected != null) { parent.SelectedObjects.Remove(original_selected); original_selected = null; } if (moveitem != null) { if (moveitem is IStateObject) { movestates[moveitem] = (moveitem as IStateObject).GetState(); } if (!(moveitem as GuiObject).selected) { parent.SelectedObjects.Clear(); parent.SelectedObjects.Add(moveitem as GuiObject); } } else { parent.SelectedObjects.Clear(); foreach (GuiObject t in movelist) { parent.SelectedObjects.Add(t); } foreach (GuiObject t in movelist) { if (t is IStateObject) { movestates[t] = (t as IStateObject).GetState(); } } } AddAssociatedObjects(); first_move = false; } // usual move if (moveitem != null) { moveitem.Moving(x, y, ref moveux, ref moveuy); } else { foreach (IMoveMultiple i in movelist) { i.ShiftShape(x - selx, y - sely); } selx = x; sely = y; } break; case MouseAction.Scroll: parent.cview.AdjustPageCoords(selx - x, sely - y); first_move = false; break; case MouseAction.CreateConnection: conn.Invalidate(); conn.InvalidateTemporary(); conn.second.item = parent.FindItem(x, y, out moveux, out moveuy, true) as IAcceptConnection; if (conn.second.item == null || conn.second.item == conn.first.item) { conn.second.x = x; conn.second.y = y; conn.second.item = null; } else { conn.second.item.coord_nearest(x, y, out conn.second.ux, out conn.second.uy); conn.second.UpdatePosition(true); } conn.DoCreationFixup(); conn.InvalidateTemporary(); conn.Invalidate(); break; } return(action != MouseAction.Scroll); }
public override void MouseDown(int x, int y, MouseButtons b, Keys modif, int realx, int realy) { // Left mouse button if (action != MouseAction.None) { return; } if (b == MouseButtons.Left) { if (current_operation == MouseOperation.DrawComment || current_operation == MouseOperation.DrawPackage) { switch (current_operation) { case MouseOperation.DrawComment: moveitem = GuiElementFactory.CreateMemo(parent, x, y); break; case MouseOperation.DrawPackage: moveitem = GuiElementFactory.CreatePackage(parent, x, y); break; } first_move = true; moveux = 0; moveuy = 0; action = MouseAction.Move; } else if ((modif & Keys.Control) == Keys.Control || current_operation == MouseOperation.DrawConnection) { conn_item = parent.FindItem(x, y, out moveux, out moveuy, true) as IAcceptConnection; if (conn_item == null) { action = MouseAction.Scroll; selx = x; sely = y; return; } int ux; float uy; conn_item.coord_nearest(x, y, out ux, out uy); action = MouseAction.CreateConnection; conn = new GuiConnection(new GuiConnectionPoint(conn_item, ux, uy, 0), new GuiConnectionPoint(x, y, 1), conn_type, parent, conn_type == UmlRelationType.Attachment ? GuiConnectionStyle.Line : conn_style); conn.first.item.coord_nearest(x, y, out conn.first.ux, out conn.first.uy); conn.first.UpdatePosition(true); conn.DoCreationFixup(); conn.InvalidateTemporary(); conn.Invalidate(); } else if ((modif & Keys.Shift) == Keys.Shift) { GuiObject obj = parent.FindItem(x, y, false); if (obj != null) { parent.SelectedObjects.Add(obj); obj.Invalidate(); } } else { // Left button click: // select // move, move multiple GuiObject s = parent.FindItem(x, y, out moveux, out moveuy, false); if (s == null) { parent.SelectedObjects.Clear(); action = MouseAction.Select; selx = x; sely = y; return; } if (!s.selected) { parent.SelectedObjects.Clear(); parent.SelectedObjects.Add(s); } // deciding: to move, or not ... moveitem = null; movelist = null; movestates.Clear(); original_selected = null; GuiObject t = parent.FindItem(x, y, out moveux, out moveuy, true); if (t != null) { if (t is IMoveRedirect) { if (t.selected) { original_selected = t; } moveitem = (t as IMoveRedirect).MoveRedirect(ref moveux, ref moveuy); } else if (t is IMoveMultiple && (t as IMoveMultiple).CanMoveInGroup) { movelist = new ArrayList(); if (!t.selected) { movelist.Add(t); } foreach (GuiObject o in parent.SelectedObjects) { if (o is IMoveMultiple && (o as IMoveMultiple).CanMoveInGroup) { movelist.Add(o); } } selx = x; sely = y; } else if (t is IMoveable && (t as IMoveable).IsMoveable(x, y)) { moveitem = t as IMoveable; } if (moveitem != null || movelist != null) { first_move = true; action = MouseAction.Move; } else if (t is IClickable) { (t as IClickable).LeftClick(false, x, y); } } } } else if (b == MouseButtons.Right) { ISelectable obj = parent.FindItem(x, y, true) as ISelectable; if (obj != null) { if (obj is IDropMenu) { parent.SelectedObjects.Clear(); parent.SelectedObjects.Add(obj as GuiObject); System.Windows.Forms.ContextMenu m = new ContextMenu(); (obj as IDropMenu).AddMenuItems(m, x, y); if (m.MenuItems.Count > 0) { m.Show(parent.cview, new Point(realx, realy)); } } } else { action = MouseAction.Scroll; Cursor.Current = Cursors.Hand; selx = x; sely = y; menurealx = realx; menurealy = realy; first_move = true; } } }