From d8e7ca11fe63cc7211ed4e11b240bdbeb9c0c278 Mon Sep 17 00:00:00 2001 From: Santiago Roca Date: Mon, 20 Aug 2018 14:23:12 -0700 Subject: [PATCH 1/3] Added Data type to input port --- src/TUM.CMS.VplControl/Core/Port.cs | 492 ++++++++++++++-------------- 1 file changed, 246 insertions(+), 246 deletions(-) diff --git a/src/TUM.CMS.VplControl/Core/Port.cs b/src/TUM.CMS.VplControl/Core/Port.cs index a9894b4..a12c115 100644 --- a/src/TUM.CMS.VplControl/Core/Port.cs +++ b/src/TUM.CMS.VplControl/Core/Port.cs @@ -1,249 +1,249 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using TUM.CMS.VplControl.Utilities; - -namespace TUM.CMS.VplControl.Core -{ - public class Port : Control - { - private readonly VplControl hostCanvas; - private object data; - - public Port(string name, Node parent, PortTypes portType, Type type) - { - ParentNode = parent; - hostCanvas = ParentNode.HostCanvas; - DataType = type; - PortType = portType; - Name = name; - Description = name; - - if (portType == PortTypes.Input) - Style = hostCanvas.FindResource("VplPortStyleLeft") as Style; - else - Style = hostCanvas.FindResource("VplPortStyleRight") as Style; - - MouseDown += Port_MouseDown; - - ParentNode.SizeChanged += ParentNode_SizeChanged; - ParentNode.PropertyChanged += ParentNode_PropertyChanged; - - ConnectedConnectors = new List(); - Origin = new BindingPoint(0, 0); - } - - public Port(string name, PortTypes portType, Type type, VplControl hostCanvas) - { - DataType = type; - PortType = portType; - Name = name; - - this.hostCanvas = hostCanvas; - - if (portType == PortTypes.Input) - Style = this.hostCanvas.FindResource("VplPortStyleLeft") as Style; - else - Style = this.hostCanvas.FindResource("VplPortStyleRight") as Style; - - MouseDown += Port_MouseDown; - - // ParentNode.SizeChanged += ParentNode_SizeChanged; - // ParentNode.PropertyChanged += ParentNode_PropertyChanged; - - ConnectedConnectors = new List(); - Origin = new BindingPoint(0, 0); +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using TUM.CMS.VplControl.Utilities; + +namespace TUM.CMS.VplControl.Core +{ + public class Port : Control + { + private readonly VplControl hostCanvas; + private object data; + + public Port(string name, Node parent, PortTypes portType, Type type) + { + ParentNode = parent; + hostCanvas = ParentNode.HostCanvas; + DataType = type; + PortType = portType; + Name = name; + Description = String.Format("{0} ({1})", name, type.Name); + + if (portType == PortTypes.Input) + Style = hostCanvas.FindResource("VplPortStyleLeft") as Style; + else + Style = hostCanvas.FindResource("VplPortStyleRight") as Style; + + MouseDown += Port_MouseDown; + + ParentNode.SizeChanged += ParentNode_SizeChanged; + ParentNode.PropertyChanged += ParentNode_PropertyChanged; + + ConnectedConnectors = new List(); + Origin = new BindingPoint(0, 0); + } + + public Port(string name, PortTypes portType, Type type, VplControl hostCanvas) + { + DataType = type; + PortType = portType; + Name = name; + + this.hostCanvas = hostCanvas; + + if (portType == PortTypes.Input) + Style = this.hostCanvas.FindResource("VplPortStyleLeft") as Style; + else + Style = this.hostCanvas.FindResource("VplPortStyleRight") as Style; + + MouseDown += Port_MouseDown; + + // ParentNode.SizeChanged += ParentNode_SizeChanged; + // ParentNode.PropertyChanged += ParentNode_PropertyChanged; + + ConnectedConnectors = new List(); + Origin = new BindingPoint(0, 0); + } + + public static readonly DependencyProperty DescriptionProperty = + DependencyProperty.Register("Description", typeof(string), typeof(Port), + new UIPropertyMetadata(string.Empty)); + + public new string Description + { + get { return (string)GetValue(DescriptionProperty); } + set { SetValue(DescriptionProperty, value); } + } + + public string Text + { + get + { + //if (Data != null) + // return Name + " : " + DataType.Name + " : " + Data; + //return Name + " : " + DataType.Name + " : null"; + + return Utilities.Utilities.DataToString(Data); + } + } + + public new string Name { get; set; } + public Node ParentNode { get; set; } + public PortTypes PortType { get; set; } + public Type DataType { get; set; } + + public object Data + { + get { return data; } + set { CalculateData(value); } + } + + public bool MultipleConnectionsAllowed { get; set; } + + public BindingPoint Origin { get; set; } + public List ConnectedConnectors { get; set; } + + public void ParentNode_SizeChanged(object sender, SizeChangedEventArgs e) + { + CalcOrigin(); + } + + public void ParentNode_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + CalcOrigin(); + } + + public void CalcOrigin() + { + Origin.X = TranslatePoint(new Point(20/2, Height/2), hostCanvas).X; + Origin.Y = TranslatePoint(new Point(20/2, Height/2), hostCanvas).Y; + } + + private void Port_MouseDown(object sender, MouseButtonEventArgs e) + { + switch (hostCanvas.SplineMode) + { + case SplineModes.Nothing: + + if (PortType== PortTypes.Input && !MultipleConnectionsAllowed && ConnectedConnectors.Count > 0) + { + Connector conn = ConnectedConnectors[0]; + conn.Delete(); + hostCanvas.TempStartPort = conn.StartPort; + } + else + { + hostCanvas.TempStartPort = this; + } + + hostCanvas.SplineMode = SplineModes.Second; + break; + case SplineModes.Second: + if ( + ( + hostCanvas.TempStartPort.DataType.IsCastableTo(DataType) && + hostCanvas.TypeSensitive && PortType == PortTypes.Output + || + DataType.IsCastableTo(hostCanvas.TempStartPort.DataType) && + hostCanvas.TypeSensitive && PortType == PortTypes.Input // data types matching + || + !hostCanvas.TypeSensitive // data types must not match + ) + && PortType != hostCanvas.TempStartPort.PortType + // is not same port type --> input to output or output to input + && !Equals(ParentNode, hostCanvas.TempStartPort.ParentNode)) // is not same node + { + Connector connector; + + if (PortType == PortTypes.Output) + { + if (hostCanvas.TempStartPort.ConnectedConnectors.Count > 0) + { + if (!hostCanvas.TempStartPort.MultipleConnectionsAllowed) + { + foreach (var tempConnector in hostCanvas.TempStartPort.ConnectedConnectors) + tempConnector.RemoveFromCanvas(); + + hostCanvas.TempStartPort.ConnectedConnectors.Clear(); + } + } + + connector = new Connector(hostCanvas, this, hostCanvas.TempStartPort); + } + else + { + if (ConnectedConnectors.Count > 0) + { + if (!MultipleConnectionsAllowed) + { + foreach (var tempConnector in ConnectedConnectors) + tempConnector.RemoveFromCanvas(); + + ConnectedConnectors.Clear(); + } + } + + connector = new Connector(hostCanvas, hostCanvas.TempStartPort, this); + } + + + connector.SynchroniseAfterZoom(); + hostCanvas.ConnectorCollection.Add(connector); + } + + + hostCanvas.SplineMode = SplineModes.Nothing; + hostCanvas.ClearTempLine(); + break; + } + + e.Handled = true; + } + + public void StartPort_DataChanged(object sender, EventArgs e) + { + CalculateData(); + } + + public event EventHandler DataChanged; + + public void OnDataChanged() + { + if (DataChanged != null) + DataChanged(this, new EventArgs()); + } + + public void CalculateData(object value = null) + { + if (PortType == PortTypes.Input) + { + if (MultipleConnectionsAllowed && ConnectedConnectors.Count > 1) + { + var listType = typeof (List<>).MakeGenericType(DataType); + var list = (IList) Activator.CreateInstance(listType); + + foreach (var conn in ConnectedConnectors) + { + list.Add(conn.StartPort.Data); + } + + data = list; + } + else if (ConnectedConnectors.Count > 0) + { + data = ConnectedConnectors[0].StartPort.Data; + } + else + { + data = null; + } + } + else + { + data = value; + } + + OnDataChanged(); } + } - public static readonly DependencyProperty DescriptionProperty = - DependencyProperty.Register("Description", typeof(string), typeof(Port), - new UIPropertyMetadata(string.Empty)); - - public new string Description - { - get { return (string)GetValue(DescriptionProperty); } - set { SetValue(DescriptionProperty, value); } - } - - public string Text - { - get - { - //if (Data != null) - // return Name + " : " + DataType.Name + " : " + Data; - //return Name + " : " + DataType.Name + " : null"; - - return Utilities.Utilities.DataToString(Data); - } - } - - public new string Name { get; set; } - public Node ParentNode { get; set; } - public PortTypes PortType { get; set; } - public Type DataType { get; set; } - - public object Data - { - get { return data; } - set { CalculateData(value); } - } - - public bool MultipleConnectionsAllowed { get; set; } - - public BindingPoint Origin { get; set; } - public List ConnectedConnectors { get; set; } - - public void ParentNode_SizeChanged(object sender, SizeChangedEventArgs e) - { - CalcOrigin(); - } - - public void ParentNode_PropertyChanged(object sender, PropertyChangedEventArgs e) - { - CalcOrigin(); - } - - public void CalcOrigin() - { - Origin.X = TranslatePoint(new Point(20/2, Height/2), hostCanvas).X; - Origin.Y = TranslatePoint(new Point(20/2, Height/2), hostCanvas).Y; - } - - private void Port_MouseDown(object sender, MouseButtonEventArgs e) - { - switch (hostCanvas.SplineMode) - { - case SplineModes.Nothing: - - if (PortType== PortTypes.Input && !MultipleConnectionsAllowed && ConnectedConnectors.Count > 0) - { - Connector conn = ConnectedConnectors[0]; - conn.Delete(); - hostCanvas.TempStartPort = conn.StartPort; - } - else - { - hostCanvas.TempStartPort = this; - } - - hostCanvas.SplineMode = SplineModes.Second; - break; - case SplineModes.Second: - if ( - ( - hostCanvas.TempStartPort.DataType.IsCastableTo(DataType) && - hostCanvas.TypeSensitive && PortType == PortTypes.Output - || - DataType.IsCastableTo(hostCanvas.TempStartPort.DataType) && - hostCanvas.TypeSensitive && PortType == PortTypes.Input // data types matching - || - !hostCanvas.TypeSensitive // data types must not match - ) - && PortType != hostCanvas.TempStartPort.PortType - // is not same port type --> input to output or output to input - && !Equals(ParentNode, hostCanvas.TempStartPort.ParentNode)) // is not same node - { - Connector connector; - - if (PortType == PortTypes.Output) - { - if (hostCanvas.TempStartPort.ConnectedConnectors.Count > 0) - { - if (!hostCanvas.TempStartPort.MultipleConnectionsAllowed) - { - foreach (var tempConnector in hostCanvas.TempStartPort.ConnectedConnectors) - tempConnector.RemoveFromCanvas(); - - hostCanvas.TempStartPort.ConnectedConnectors.Clear(); - } - } - - connector = new Connector(hostCanvas, this, hostCanvas.TempStartPort); - } - else - { - if (ConnectedConnectors.Count > 0) - { - if (!MultipleConnectionsAllowed) - { - foreach (var tempConnector in ConnectedConnectors) - tempConnector.RemoveFromCanvas(); - - ConnectedConnectors.Clear(); - } - } - - connector = new Connector(hostCanvas, hostCanvas.TempStartPort, this); - } - - - connector.SynchroniseAfterZoom(); - hostCanvas.ConnectorCollection.Add(connector); - } - - - hostCanvas.SplineMode = SplineModes.Nothing; - hostCanvas.ClearTempLine(); - break; - } - - e.Handled = true; - } - - public void StartPort_DataChanged(object sender, EventArgs e) - { - CalculateData(); - } - - public event EventHandler DataChanged; - - public void OnDataChanged() - { - if (DataChanged != null) - DataChanged(this, new EventArgs()); - } - - public void CalculateData(object value = null) - { - if (PortType == PortTypes.Input) - { - if (MultipleConnectionsAllowed && ConnectedConnectors.Count > 1) - { - var listType = typeof (List<>).MakeGenericType(DataType); - var list = (IList) Activator.CreateInstance(listType); - - foreach (var conn in ConnectedConnectors) - { - list.Add(conn.StartPort.Data); - } - - data = list; - } - else if (ConnectedConnectors.Count > 0) - { - data = ConnectedConnectors[0].StartPort.Data; - } - else - { - data = null; - } - } - else - { - data = value; - } - - OnDataChanged(); - } - } - - public enum PortTypes - { - Input, - Output - } + public enum PortTypes + { + Input, + Output + } } \ No newline at end of file From af4cfc06fbb22a1da9b434a8c2ea3f10924b3898 Mon Sep 17 00:00:00 2001 From: Santiago Roca Date: Mon, 20 Aug 2018 18:42:17 -0700 Subject: [PATCH 2/3] Zoom Fixed | WPF Generics fixed for data labels on both output and input --- src/TUM.CMS.VplControl/Core/VPLControl.cs | 20 +- src/TUM.CMS.VplControl/Themes/Generic.xaml | 1144 ++++++++++---------- 2 files changed, 586 insertions(+), 578 deletions(-) diff --git a/src/TUM.CMS.VplControl/Core/VPLControl.cs b/src/TUM.CMS.VplControl/Core/VPLControl.cs index 2677ec2..e59cc01 100644 --- a/src/TUM.CMS.VplControl/Core/VPLControl.cs +++ b/src/TUM.CMS.VplControl/Core/VPLControl.cs @@ -538,15 +538,21 @@ protected override void HandleMouseWheel(object sender, MouseWheelEventArgs e) height = path.ActualHeight; } - if (width > 0 && height > 0) - { - element.RenderTransformOrigin = new Point(position.X/width, position.Y/height); + if (e.Delta > 0) + { + Matrix m = element.RenderTransform.Value; + m.ScaleAtPrepend(1.15, 1.15, position.X, position.Y); + element.RenderTransform = new MatrixTransform(m); + } + else + { + Matrix m = element.RenderTransform.Value; + m.ScaleAtPrepend(1/1.15, 1/1.15, position.X, position.Y); + element.RenderTransform = new MatrixTransform(m); } + } - - ScaleTransform.ScaleX += zoom; - ScaleTransform.ScaleY += zoom; - + mouseMode = MouseMode.Nothing; } diff --git a/src/TUM.CMS.VplControl/Themes/Generic.xaml b/src/TUM.CMS.VplControl/Themes/Generic.xaml index 7975a54..7ec5dfb 100644 --- a/src/TUM.CMS.VplControl/Themes/Generic.xaml +++ b/src/TUM.CMS.VplControl/Themes/Generic.xaml @@ -1,573 +1,575 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - - - 20 - 1.5 - - - - - - - 2 - - - - 14 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +