Skip to content

Commit

Permalink
Updating the colors of the ports according to the Function State (#12826
Browse files Browse the repository at this point in the history
)

* Checking if it's a python node

* checking the results of the node instead of IsPartiallyApplied

* Creating a flag that checks is a function node

* Adding IsPartiallyApplied in the logic and const string in the CoreUtils

* Renaming constants
  • Loading branch information
filipeotero authored May 3, 2022
1 parent 63d2d65 commit c64c66b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
36 changes: 28 additions & 8 deletions src/DynamoCoreWpf/ViewModels/Core/InPortViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Dynamo.Models;
using Dynamo.UI;
using Dynamo.UI.Commands;
using ProtoCore.Utils;

namespace Dynamo.ViewModels
{
Expand All @@ -22,10 +23,11 @@ public partial class InPortViewModel : PortViewModel
private SolidColorBrush portValueMarkerColor = new SolidColorBrush(Color.FromArgb(255, 204, 204, 204));

private bool portDefaultValueMarkerVisible;
private bool isFunctionNode;

private static SolidColorBrush PortValueMarkerBlue = new SolidColorBrush(Color.FromRgb(106, 192, 231));
private static SolidColorBrush PortValueMarkerRed = new SolidColorBrush(Color.FromRgb(235, 85, 85));
private static SolidColorBrush PortValueMarkerGrey = new SolidColorBrush(Color.FromRgb(153, 153, 153));
private static SolidColorBrush PortValueMarkerGrey = new SolidColorBrush(Color.FromRgb(153, 153, 153));

private static readonly SolidColorBrush PortBackgroundColorKeepListStructure = new SolidColorBrush(Color.FromRgb(83, 126, 145));
private static readonly SolidColorBrush PortBorderBrushColorKeepListStructure = new SolidColorBrush(Color.FromRgb(168, 181, 187));
Expand Down Expand Up @@ -151,18 +153,31 @@ public bool PortDefaultValueMarkerVisible
public InPortViewModel(NodeViewModel node, PortModel port) : base(node, port)
{
port.PropertyChanged += PortPropertyChanged;
node.NodeModel.PropertyChanged += NodeModel_PropertyChanged;

RefreshPortDefaultValueMarkerVisible();
}

private void NodeModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(node.NodeModel.CachedValue):
RefreshPortColors();
break;
}
}

public override void Dispose()
{
port.PropertyChanged -= PortPropertyChanged;
node.NodeModel.PropertyChanged -= NodeModel_PropertyChanged;

base.Dispose();
}

internal override PortViewModel CreateProxyPortViewModel(PortModel portModel)
{
{
portModel.IsProxyPort = true;
return new InPortViewModel(node, portModel);
}
Expand Down Expand Up @@ -211,7 +226,7 @@ private void UseLevel(object parameter)
var useLevel = (bool)parameter;
var command = new DynamoModel.UpdateModelValueCommand(
Guid.Empty, node.NodeLogic.GUID, "UseLevels", string.Format("{0}:{1}", port.Index, useLevel));

node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
RaisePropertyChanged(nameof(UseLevelSpinnerVisible));
}
Expand All @@ -233,7 +248,7 @@ private void KeepListStructure(object parameter)
var keepListStructure = (bool)parameter;
var command = new DynamoModel.UpdateModelValueCommand(
Guid.Empty, node.NodeLogic.GUID, "KeepListStructure", string.Format("{0}:{1}", port.Index, keepListStructure));

node.WorkspaceViewModel.DynamoViewModel.ExecuteCommand(command);
}

Expand Down Expand Up @@ -276,8 +291,12 @@ private void RefreshPortDefaultValueMarkerVisible()
/// </summary>
protected override void RefreshPortColors()
{
//Is in function state
if (node.NodeModel.IsPartiallyApplied)
//This variable checks if the node is a function class
isFunctionNode = node.NodeModel.IsPartiallyApplied &&
node.NodeModel.CachedValue != null &&
node.NodeModel.CachedValue.IsFunction;

if (isFunctionNode)
{
if (node.NodeModel.AreAllOutputsConnected)
{
Expand All @@ -304,7 +323,7 @@ internal void RefreshInputPortsByOutputConnectionChanged(bool isOutputConnected)
{
PortValueMarkerColor = PortValueMarkerGrey;
}
else
else
{
SetupDefaultPortColorValues();
}
Expand All @@ -313,6 +332,7 @@ internal void RefreshInputPortsByOutputConnectionChanged(bool isOutputConnected)

private void SetupDefaultPortColorValues()
{

// Special case for keeping list structure visual appearance
if (port.UseLevels && port.KeepListStructure && port.IsConnected)
{
Expand All @@ -321,7 +341,7 @@ private void SetupDefaultPortColorValues()
PortBorderBrushColor = PortBorderBrushColorKeepListStructure;
}
// Port has a default value, shows blue marker
else if (UsingDefaultValue && DefaultValueEnabled)
else if ((UsingDefaultValue && DefaultValueEnabled) || !isFunctionNode)
{
PortValueMarkerColor = PortValueMarkerBlue;
PortBackgroundColor = PortBackgroundColorDefault;
Expand Down
33 changes: 26 additions & 7 deletions src/DynamoCoreWpf/ViewModels/Core/OutPortViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Dynamo.Logging;
using Dynamo.UI;
using Dynamo.UI.Commands;
using ProtoCore.Utils;

namespace Dynamo.ViewModels
{
Expand Down Expand Up @@ -87,7 +88,7 @@ internal bool AreConnectorsHidden
get => areConnectorsHidden;
set
{
areConnectorsHidden = value;
areConnectorsHidden = value;
RaisePropertyChanged(nameof(AreConnectorsHidden));
}
}
Expand All @@ -100,7 +101,7 @@ public bool HideWiresButtonEnabled
get => hideWiresButtonEnabled;
set
{
hideWiresButtonEnabled = value;
hideWiresButtonEnabled = value;
RaisePropertyChanged(nameof(HideWiresButtonEnabled));
}
}
Expand All @@ -119,7 +120,7 @@ public SolidColorBrush PortValueMarkerColor
}


public bool PortDefaultValueMarkerVisible
public bool PortDefaultValueMarkerVisible
{
get => portDefaultValueMarkerVisible;
set
Expand Down Expand Up @@ -151,16 +152,29 @@ internal void RefreshHideWiresState()
public OutPortViewModel(NodeViewModel node, PortModel port) :base(node, port)
{
port.PropertyChanged += PortPropertyChanged;
node.NodeModel.PropertyChanged += NodeModel_PropertyChanged;

RefreshHideWiresState();
}

public override void Dispose()
{
port.PropertyChanged -= PortPropertyChanged;
port.PropertyChanged -= PortPropertyChanged;
node.NodeModel.PropertyChanged -= NodeModel_PropertyChanged;

base.Dispose();
}

private void NodeModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(node.NodeModel.CachedValue):
RefreshPortColors();
break;
}
}

private void PortPropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand Down Expand Up @@ -228,7 +242,7 @@ private void BreakConnections(object parameter)
}

connectorViewModel.BreakConnectionCommand.Execute(null);
}
}
}

/// <summary>
Expand Down Expand Up @@ -294,8 +308,13 @@ private void OnMouseLeftButtonDownOnContext(object parameter)
}

protected override void RefreshPortColors()
{
if (node.NodeModel.IsPartiallyApplied)
{
//This variable checks if the node is a function class
bool isFunctionNode = node.NodeModel.IsPartiallyApplied &&
node.NodeModel.CachedValue != null &&
node.NodeModel.CachedValue.IsFunction;

if (node.NodeModel.IsPartiallyApplied && isFunctionNode)
{
PortDefaultValueMarkerVisible = true;
portValueMarkerColor = PortValueMarkerGrey;
Expand Down
8 changes: 8 additions & 0 deletions src/Engine/ProtoCore/Reflection/Mirror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ public string Alias

private LibraryMirror libraryMirror = null;

internal LibraryMirror LibraryMirror
{
get
{
return libraryMirror;
}
}

private ClassNode classNode = null;
private ClassNode ClassNode
{
Expand Down
8 changes: 8 additions & 0 deletions src/Engine/ProtoCore/Reflection/MirrorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public class MirrorData
/// </summary>
private StackValue svData;

public bool IsFunction
{
get
{
return IsPointer && Class.Name.Equals(CoreUtils.FunctionObjectClass) && Class.LibraryMirror.Name.Equals(CoreUtils.FunctionObjectLibrary);
}
}


//
// Comment Jun:
Expand Down
3 changes: 3 additions & 0 deletions src/Engine/ProtoCore/Utils/CoreUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace ProtoCore.Utils
{
public static class CoreUtils
{
public static readonly string FunctionObjectClass = "Function";
public static readonly string FunctionObjectLibrary = "FunctionObject.ds";

public static void InsertPredefinedAndBuiltinMethods(Core core, CodeBlockNode root)
{
if (DSASM.InterpreterMode.Normal == core.Options.RunMode)
Expand Down

0 comments on commit c64c66b

Please sign in to comment.