Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Diagram creation is solid
Browse files Browse the repository at this point in the history
  • Loading branch information
msawczyn committed Apr 9, 2020
1 parent f28d4bd commit 71fc0a7
Show file tree
Hide file tree
Showing 23 changed files with 579 additions and 495 deletions.
2 changes: 2 additions & 0 deletions src/Dsl/CustomCode/Partials/ClassShape.cs
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

using Sawczyn.EFDesigner.EFModel.Extensions;

Expand Down Expand Up @@ -370,5 +371,6 @@ public override void OnDoubleClick(DiagramPointEventArgs e)
ErrorDisplay.Show($"Can't open generated file for {modelClass.Name}");
}
}

}
}
79 changes: 77 additions & 2 deletions src/Dsl/CustomCode/Partials/EFModelDiagram.cs
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Windows.Forms;

using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.Modeling.Diagrams.GraphObject;

Expand All @@ -16,7 +17,7 @@ public partial class EFModelDiagram: IHasStore
public override void OnInitialize()
{
base.OnInitialize();
ModelRoot modelRoot = Store.GetAll<ModelRoot>().FirstOrDefault();
ModelRoot modelRoot = Store.ModelRoot();

// because we can hide elements, line routing looks odd when it thinks it's jumping over lines
// that really aren't visible. Since replacing the routing algorithm is too hard (impossible?)
Expand All @@ -28,6 +29,18 @@ public override void OnInitialize()
GridColor = modelRoot?.GridColor ?? Color.Gainsboro;
SnapToGrid = modelRoot?.SnapToGrid ?? true;
GridSize = modelRoot?.GridSize ?? 0.125;

}

/// <summary>
/// Called during view fixup to ask the parent whether a shape should be created for the given child element.
/// </summary>
/// <remarks>
/// Always return true, since we assume there is only one diagram per model file for DSL scenarios.
/// </remarks>
protected override bool ShouldAddShapeForElement(ModelElement element)
{
return base.ShouldAddShapeForElement(element) || NestedChildShapes.Any(s => s.ModelElement == element);
}

public static bool IsDropping { get; private set; }
Expand All @@ -36,8 +49,15 @@ public override void OnDragOver(DiagramDragEventArgs diagramDragEventArgs)
{
base.OnDragOver(diagramDragEventArgs);

if (diagramDragEventArgs.Effect == DragDropEffects.None && IsAcceptableDropItem(diagramDragEventArgs))
if (diagramDragEventArgs.Handled)
return;

if (diagramDragEventArgs.Data.GetData(typeof(ModelElement)) is ModelElement)
diagramDragEventArgs.Effect = DragDropEffects.Move;
else if (IsAcceptableDropItem(diagramDragEventArgs))
diagramDragEventArgs.Effect = DragDropEffects.Copy;
else
diagramDragEventArgs.Effect = DragDropEffects.None;
}

private bool IsAcceptableDropItem(DiagramDragEventArgs diagramDragEventArgs)
Expand All @@ -48,16 +68,30 @@ private bool IsAcceptableDropItem(DiagramDragEventArgs diagramDragEventArgs)
return IsDropping;
}

public bool DropTarget { get; private set; }
public override void OnDragDrop(DiagramDragEventArgs diagramDragEventArgs)
{
try
{
DropTarget = true;
base.OnDragDrop(diagramDragEventArgs);
}
catch (ArgumentException)
{
// ignore. byproduct of multiple diagrams
}
finally
{
DropTarget = false;
}

// came from model explorer?
if (diagramDragEventArgs.Effect == DragDropEffects.Move && diagramDragEventArgs.Data.GetData(typeof(ModelElement)) is ModelElement element)
{
FixUpAllDiagrams.FixUp(this, Store.ModelRoot(), element);

return;
}

if (IsDropping)
{
Expand Down Expand Up @@ -106,5 +140,46 @@ public override void OnMouseUp(DiagramMouseEventArgs e)
IsDropping = false;
base.OnMouseUp(e);
}

/// <summary>
/// Called when a key is pressed when the Diagram itself has the focus.
/// </summary>
/// <param name="e">A DiagramKeyEventArgs that contains event data.</param>
public override void OnKeyDown(DiagramKeyEventArgs e)
{
//using (Transaction t = Store.TransactionManager.BeginTransaction("Diagram.OnKeyDown"))
//{

// if (e.KeyCode == Keys.Delete)
// {
// SelectedShapesCollection selection = FocusedDiagramView.Selection;

// string message = selection.Count == 1
// ? "Delete multiple elements from model? Are you sure?"
// : "Delete element from model? Are you sure?";

// if (e.Control && BooleanQuestionDisplay.Show(message) == true)
// {
// foreach (ModelElement modelElement in selection.RepresentedElements)
// modelElement.Delete();
// t.Commit();
// e.Handled = true;
// }
// else if (!e.Control)
// {
// foreach (DiagramItem diagramItem in selection)
// {
// if (diagramItem.Shape is NodeShape nodeShape)
// nodeShape.Delete();
// }

// t.Commit();
// e.Handled = true;
// }
// }
//}

base.OnKeyDown(e);
}
}
}
18 changes: 18 additions & 0 deletions src/Dsl/CustomCode/Partials/FixUpAllDiagrams.cs
@@ -0,0 +1,18 @@
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//using Microsoft.VisualStudio.Modeling;

//namespace Sawczyn.EFDesigner.EFModel
//{
// partial class FixUpAllDiagrams
// {
// protected override bool SkipFixup(ModelElement childElement)
// {
// return childElement.IsDeleted || childElement.Store.TransactionManager.CurrentTransaction.IsSerializing;
// }
// }
//}
29 changes: 15 additions & 14 deletions src/Dsl/CustomCode/Partials/UnidirectionalConnector.cs
@@ -1,16 +1,17 @@
//using Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.Modeling.Diagrams;

//namespace Sawczyn.EFDesigner.EFModel
//{
// public partial class UnidirectionalConnector
// {
// public override bool HasToolTip => true;
namespace Sawczyn.EFDesigner.EFModel
{
partial class ClassShape
{
/// <summary>Called when a key is pressed.</summary>
/// <param name="e">A DiagramKeyEventArgs that contains event data.</param>
public override void OnKeyDown(DiagramKeyEventArgs e)
{
base.OnKeyDown(e);
}
}


}

// public override string GetToolTipText(DiagramItem item)
// {
// return item.Shape.ModelElement is Association association
// ? association.GetDisplayText()
// : string.Empty;
// }
// }
//}
1 change: 1 addition & 0 deletions src/Dsl/Dsl.csproj
Expand Up @@ -139,6 +139,7 @@
<Compile Include="CustomCode\Name Providers\ModelDiagramDataNameProvider.cs" />
<Compile Include="CustomCode\Partials\AssociationConnector.cs" />
<Compile Include="CustomCode\Domain Types\Namespaces.cs" />
<Compile Include="CustomCode\Partials\FixUpAllDiagrams.cs" />
<Compile Include="CustomCode\Partials\ModelDiagramData.cs" />
<Compile Include="CustomCode\Rules\AssociationDeletingRules.cs" />
<Compile Include="CustomCode\Rules\BidirectionalAssociationAddRules.cs" />
Expand Down
8 changes: 4 additions & 4 deletions src/Dsl/GeneratedCode/Diagram.cs
Expand Up @@ -193,10 +193,10 @@ private void CompartmentItemRolePlayerOrderChanged(object sender, DslModeling::R
/// <remarks>
/// Always return true, since we assume there is only one diagram per model file for DSL scenarios.
/// </remarks>
protected override bool ShouldAddShapeForElement(DslModeling::ModelElement element)
{
return true;
}
//protected override bool ShouldAddShapeForElement(DslModeling::ModelElement element)
//{
// return true;
//}

internal bool ShouldSupport(DslModeling::ModelElement element) // HACK : MEXEDGE
{
Expand Down

0 comments on commit 71fc0a7

Please sign in to comment.