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)); }
DiagramEntityViewModel GetMouseOverEntity() { Point currentPosition = MouseUtilities.GetMousePosition(this); DiagramViewModel diagramView = DataContext as DiagramViewModel; foreach (DiagramEntityViewModel entity in diagramView.Items.OfType <DiagramEntityViewModel>()) { EntityDiagramControl entityControl = VisualItemHelper.FindChild <EntityDiagramControl>(this, entity); if (entityControl != null) { if (entity.X < currentPosition.X && currentPosition.X < (entity.X + entityControl.ActualWidth) && entity.Y < currentPosition.Y && currentPosition.Y < (entity.Y + entityControl.ActualHeight)) { return(entity); } } } return(null); }
///-------------------------------------------------------------------------------- /// <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; } }