/* Handle mouse move moving an Entity around with the right button. * and the highlighting process */ private void Form1_MouseMove(object sender, MouseEventArgs e) { // if it is over an entity var tempEnt = myChart.FindEntity(e.Location); highlightedEntity = (Entity)ProcessHighLighting(tempEnt, highlightedEntity); // if it is over an attribute var tempAttribute = tempEnt?.FindAttribute(e.Location); highlightedAttribute = (Attribute)ProcessHighLighting(tempAttribute, highlightedAttribute); //if it is over a link var tempLink = myChart.FindLink(e.Location); highlightedLink = (Link)ProcessHighLighting(tempLink, highlightedLink); // moving an entity if (mousePoint != Point.Empty) { MouseMoveObject(movedEntity, e.Location); } // repaint Invalidate(true); }
// if the attribute is dropped in the backgorund then is removed // if dropped on an entity that does not have it then // is added in the position of the mouse private void frmMain_DragDrop(object sender, DragEventArgs e) { var draggedAttribute = (Attribute)e.Data.GetData(typeof(Attribute)); var dropPoint = PointToClient(new Point(e.X, e.Y)); var tempEntity = myChart.FindEntity(dropPoint); if (tempEntity == null) { selectedEntity.RemoveAttribute(draggedAttribute); myChart.DestroyLinks(); return; } // if in the same entity the reorder both attributes var tempAttribute = tempEntity.FindAttribute(dropPoint); if (selectedEntity == tempEntity) { selectedEntity.ReorderAttribute(draggedAttribute, tempAttribute); } else { // if different entities inset att and create a new default link (OnetoOne) var copiedAttrributed = new Attribute(draggedAttribute); tempEntity.AddAttributeAfter(copiedAttrributed, tempAttribute); myChart.AddLink(new Link(draggedAttribute, copiedAttrributed, Relationship.One2One)); } Invalidate(true); }
private void Form1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { // clicked on an entity movedEntity = myChart.FindEntity(e.Location); mousePoint = movedEntity != null ? e.Location : Point.Empty; } else if (e.Button == MouseButtons.Left) { mouseSelected = e.Location; // clicked on an entity var tempEntity = myChart.FindEntity(mouseSelected); selectedEntity = (Entity)ProcessSelection(tempEntity, selectedEntity); bs.Position = myChart.FindEntityPosition(selectedEntity); // clicked on a link var tempLink = myChart.FindLink(e.Location); selectedLink = (Link)ProcessSelection(tempLink, selectedLink); stbLink.Enabled = selectedLink != null; // clicked on an attribute var tempAttribute = selectedEntity?.FindAttribute(e.Location); selectedAttribute = (Attribute)ProcessSelection(tempAttribute, selectedAttribute); if (selectedAttribute != null) { DoDragDrop(selectedAttribute, DragDropEffects.Copy | DragDropEffects.Move); } // clicked on an empty space = background if ((tempLink == null) && (tempAttribute == null) && (selectedEntity == null)) { DoDragDrop(DragDropObject, DragDropEffects.Copy); } UpdateStatusBar(); } Invalidate(true); }