public Connector GetBestConnector(EntityDiagramControl otherControl, bool isSinkConnector) { DiagramEntityViewModel view = DataContext as DiagramEntityViewModel; DiagramEntityViewModel otherView = otherControl.DataContext as DiagramEntityViewModel; if (view != null && otherView != null) { double deltaX = otherView.X - view.X; double deltaY = otherView.Y - view.Y; bool deltaYBigger = Math.Abs(deltaY) > Math.Abs(deltaX); if (isSinkConnector == true) { // weight the sink connector towards the left/right side deltaYBigger = Math.Abs(deltaY) > 2 * Math.Abs(deltaX); } if (deltaYBigger == true) { // item is to the top or bottom if (deltaY > 0) { // item is to the bottom return(GetConnector(BottomPanel, otherView.X, otherView.Y)); } else { // item is to the top return(GetConnector(TopPanel, otherView.X, otherView.Y)); } } else { // item is to the left or right if (deltaX > 0) { // item is to the right return(GetConnector(RightPanel, otherView.X, otherView.Y)); } else { // item is to the left return(GetConnector(LeftPanel, otherView.X, otherView.Y)); } } } return(GetConnector(LeftPanel, otherView.X, otherView.Y)); }
public void HandleCustomDrop() { // handle "drop" of relationship in custom drag/drop approach with arc drawing adorner if (DragItem is DiagramRelationshipViewModel) { DiagramViewModel diagramView = DataContext as DiagramViewModel; DiagramEntityViewModel diagramEntityView = GetMouseOverEntity(); DiagramRelationshipViewModel dragRelationship = DragItem as DiagramRelationshipViewModel; Point currentPosition = MouseUtilities.GetMousePosition(this); if (dragRelationship != null && diagramEntityView != null) { dragRelationship.SinkDiagramEntityViewModel = diagramEntityView; dragRelationship.Diagram = diagramView; dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 650 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new RelationshipDialogControl(); Relationship newRelationship = new Relationship(); newRelationship.RelationshipID = Guid.NewGuid(); newRelationship.Solution = dragRelationship.Solution; newRelationship.ReferencedEntity = dragRelationship.SinkDiagramEntityViewModel.DiagramEntity.Entity; newRelationship.Entity = dragRelationship.SourceDiagramEntityViewModel.DiagramEntity.Entity; RelationshipViewModel newRelationshipView = new RelationshipViewModel(newRelationship, dragRelationship.Solution); dialog.DataContext = newRelationshipView; dialog.Title = newRelationshipView.Title; newRelationshipView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newRelationshipView.IsOK == true) { dragRelationship.RelationshipViewModel = newRelationshipView; diagramView.CreateRelationship(dragRelationship); } dialog.Close(); dialog = null; } } IsDragging = false; DragItem = null; }
protected override void OnMouseUp(MouseButtonEventArgs e) { if (HitConnector != null) { DiagramEntityViewModel sourceView = sourceConnector.DataContext as DiagramEntityViewModel; DiagramEntityViewModel sinkView = HitConnector.DataContext as DiagramEntityViewModel; if (DiagramViewModel != null && sourceView != null && sinkView != null) { Relationship relationship = new Relationship(); relationship.RelationshipID = Guid.NewGuid(); relationship.EntityID = sourceView.EntityID; relationship.ReferencedEntityID = sinkView.EntityID; // TODO: bring up dialog to set up new entity relationship properties RelationshipViewModel relationshipViewModel = new RelationshipViewModel(relationship, sourceView.Solution); DiagramRelationshipViewModel dropDiagramRelationship = new DiagramRelationshipViewModel(sourceView, sinkView, sourceView.Diagram, relationshipViewModel); dropDiagramRelationship.ZIndex = 0; DiagramViewModel.DiagramRelationships.Add(dropDiagramRelationship); DiagramViewModel.ClearSelectedItems(); dropDiagramRelationship.IsSelected = true; DiagramViewModel.Refresh(true); } } if (HitDesignerItem != null) { this.HitDesignerItem.IsDragConnectionOver = false; } if (this.IsMouseCaptured) { this.ReleaseMouseCapture(); } AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.designerCanvas); if (adornerLayer != null) { adornerLayer.Remove(this); } }
///-------------------------------------------------------------------------------- /// <summary>This method handles the execution of the new command.</summary> /// /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> ///-------------------------------------------------------------------------------- private void NewExecuted(object sender, ExecutedRoutedEventArgs e) { Point currentPosition = MouseUtilities.GetMousePosition(this); PropertiesViewModel items = DataContext as PropertiesViewModel; EntityDiagramControl diagram = VisualItemHelper.VisualUpwardSearch <EntityDiagramControl>(this) as EntityDiagramControl; DiagramEntityViewModel diagramEntityView = diagram.DataContext as DiagramEntityViewModel; if (items != null && diagramEntityView != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new PropertyDialogControl(); Property newItem = new Property(); newItem.PropertyID = Guid.NewGuid(); newItem.Solution = items.Solution; newItem.Entity = items.Entity; //newItem.ReferenceEntity = diagramEntityView.DiagramEntity.Entity; PropertyViewModel newItemView = new PropertyViewModel(newItem, items.Solution); newItemView.IsFreeDialog = true; dialog.DataContext = newItemView; dialog.Title = newItemView.Title; newItemView.RequestClose += new EventHandler(Item_RequestClose); #region protected dialog.Width = 600 * UserSettingsHelper.Instance.ControlSize; #endregion protected dialog.ShowDialog(); if (newItemView.IsOK == true) { items.AddProperty(newItemView); } dialog.Close(); dialog = null; e.Handled = true; return; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); Point currentPosition = MouseUtilities.GetMousePosition(this); DiagramViewModel diagramView = ParentCanvas.DataContext as DiagramViewModel; DiagramEntityViewModel diagramEntityView = DataContext as DiagramEntityViewModel; if (diagramView != null && diagramEntityView != null) { // try drop as diagram relationship DiagramRelationshipViewModel dragRelationship = e.Data.GetData(typeof(DiagramRelationshipViewModel)) as DiagramRelationshipViewModel; if (dragRelationship != null) { dragRelationship.SinkDiagramEntityViewModel = diagramEntityView; dragRelationship.Diagram = diagramView; dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 650 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new RelationshipDialogControl(); Relationship newRelationship = new Relationship(); newRelationship.RelationshipID = Guid.NewGuid(); newRelationship.Solution = dragRelationship.Solution; newRelationship.ReferencedEntity = dragRelationship.SinkDiagramEntityViewModel.DiagramEntity.Entity; newRelationship.Entity = dragRelationship.SourceDiagramEntityViewModel.DiagramEntity.Entity; RelationshipViewModel newRelationshipView = new RelationshipViewModel(newRelationship, dragRelationship.Solution); dialog.DataContext = newRelationshipView; dialog.Title = newRelationshipView.Title; newRelationshipView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newRelationshipView.IsOK == true) { dragRelationship.RelationshipViewModel = newRelationshipView; diagramView.CreateRelationship(dragRelationship); } dialog.Close(); dialog = null; e.Handled = true; return; } // try drop as collection CollectionsViewModel dragCollections = e.Data.GetData(typeof(CollectionsViewModel)) as CollectionsViewModel; if (dragCollections != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new CollectionDialogControl(); Collection newProperty = new Collection(); newProperty.PropertyID = Guid.NewGuid(); newProperty.Solution = dragCollections.Solution; newProperty.Entity = dragCollections.Entity; newProperty.ReferencedEntity = diagramEntityView.DiagramEntity.Entity; CollectionViewModel newPropertyView = new CollectionViewModel(newProperty, dragCollections.Solution); dialog.DataContext = newPropertyView; dialog.Title = newPropertyView.Title; newPropertyView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newPropertyView.IsOK == true) { dragCollections.AddCollection(newPropertyView); } dialog.Close(); dialog = null; e.Handled = true; return; } // try drop as property reference PropertyReferencesViewModel dragPropertyReferences = e.Data.GetData(typeof(PropertyReferencesViewModel)) as PropertyReferencesViewModel; if (dragPropertyReferences != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new PropertyReferenceDialogControl(); PropertyReference newProperty = new PropertyReference(); newProperty.PropertyID = Guid.NewGuid(); newProperty.Solution = dragPropertyReferences.Solution; newProperty.Entity = dragPropertyReferences.Entity; PropertyReferenceViewModel newPropertyView = new PropertyReferenceViewModel(newProperty, dragPropertyReferences.Solution); newPropertyView.ReferencedEntityID = diagramEntityView.EntityViewModel.EntityID; newPropertyView.RefreshProperties(); dialog.DataContext = newPropertyView; dialog.Title = newPropertyView.Title; newPropertyView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newPropertyView.IsOK == true) { dragPropertyReferences.AddPropertyReference(newPropertyView); } dialog.Close(); dialog = null; e.Handled = true; return; } // try drop as entity reference EntityReferencesViewModel dragEntityReferences = e.Data.GetData(typeof(EntityReferencesViewModel)) as EntityReferencesViewModel; if (dragEntityReferences != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new EntityReferenceDialogControl(); EntityReference newProperty = new EntityReference(); newProperty.PropertyID = Guid.NewGuid(); newProperty.Solution = dragEntityReferences.Solution; newProperty.Entity = dragEntityReferences.Entity; newProperty.ReferencedEntity = diagramEntityView.DiagramEntity.Entity; EntityReferenceViewModel newPropertyView = new EntityReferenceViewModel(newProperty, dragEntityReferences.Solution); dialog.DataContext = newPropertyView; dialog.Title = newPropertyView.Title; newPropertyView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newPropertyView.IsOK == true) { dragEntityReferences.AddEntityReference(newPropertyView); } dialog.Close(); dialog = null; e.Handled = true; return; } } }