Skip to content

Commit

Permalink
Merge pull request #62 from wieslawsoltes/fix_11_1
Browse files Browse the repository at this point in the history
Fixes after 11.1 update
  • Loading branch information
wieslawsoltes authored Sep 28, 2024
2 parents 4a5b2f9 + 16bfdd2 commit a9544a0
Show file tree
Hide file tree
Showing 46 changed files with 703 additions and 486 deletions.
29 changes: 17 additions & 12 deletions samples/NodeEditor.Base/Services/Demo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ internal static class Demo
{
public static IDrawingNode CreateDemoDrawing()
{
var drawing = new DrawingNodeViewModel
var settings = new DrawingNodeSettingsViewModel
{
X = 0,
Y = 0,
Width = 900,
Height = 600,
Nodes = new ObservableCollection<INode>(),
Connectors = new ObservableCollection<IConnector>(),
EnableMultiplePinConnections = true,
EnableSnap = true,
SnapX = 15.0,
SnapY = 15.0,
EnableGrid = true,
GridCellWidth = 15.0,
GridCellHeight = 15.0,
GridCellHeight = 15.0
};

var drawing = new DrawingNodeViewModel
{
Settings = settings,
X = 0,
Y = 0,
Width = 900,
Height = 600,
Nodes = new ObservableCollection<INode>(),
Connectors = new ObservableCollection<IConnector>()
};

var rectangle0 = NodeFactory.CreateRectangle(30, 30, 60, 60, "rect0");
Expand All @@ -33,7 +38,7 @@ public static IDrawingNode CreateDemoDrawing()
rectangle1.Parent = drawing;
drawing.Nodes.Add(rectangle1);

if (rectangle0.Pins?[1] is { } && rectangle1.Pins?[0] is { })
if (rectangle0.Pins?[1] is not null && rectangle1.Pins?[0] is not null)
{
var connector0 = NodeFactory.CreateConnector(rectangle0.Pins[1], rectangle1.Pins[0]);
connector0.Parent = drawing;
Expand Down Expand Up @@ -64,21 +69,21 @@ public static IDrawingNode CreateDemoDrawing()
orGate0.Parent = drawing;
drawing.Nodes.Add(orGate0);

if (signal0.Pins?[1] is { } && orGate0.Pins?[2] is { })
if (signal0.Pins?[1] is not null && orGate0.Pins?[2] is not null)
{
var connector0 = NodeFactory.CreateConnector(signal0.Pins[1], orGate0.Pins[2]);
connector0.Parent = drawing;
drawing.Connectors.Add(connector0);
}

if (signal1.Pins?[1] is { } && orGate0.Pins?[0] is { })
if (signal1.Pins?[1] is not null && orGate0.Pins?[0] is not null)
{
var connector0 = NodeFactory.CreateConnector(signal1.Pins[1], orGate0.Pins[0]);
connector0.Parent = drawing;
drawing.Connectors.Add(connector0);
}

if (orGate0.Pins?[1] is { } && signal2.Pins?[0] is { })
if (orGate0.Pins?[1] is not null && signal2.Pins?[0] is not null)
{
var connector1 = NodeFactory.CreateConnector(orGate0.Pins[1], signal2.Pins[0]);
connector1.Parent = drawing;
Expand Down
4 changes: 2 additions & 2 deletions samples/NodeEditor.Base/Services/ExportRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ private static void Render(Control target, SKCanvas canvas, double dpi = 96)
{
using var drawingContextImpl = DrawingContextHelper.WrapSkiaCanvas(canvas, new Vector(dpi, dpi));
var platformDrawingContextType = typeof(DrawingContext).Assembly.GetType("Avalonia.Media.PlatformDrawingContext");
if (platformDrawingContextType is { })
if (platformDrawingContextType is not null)
{
var drawingContext = (DrawingContext?)Activator.CreateInstance(
platformDrawingContextType,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
new object?[] { drawingContextImpl, true },
null);
if (drawingContext is { })
if (drawingContext is not null)
{
// TODO: ImmediateRenderer.Render(target, drawingContext);
}
Expand Down
19 changes: 12 additions & 7 deletions samples/NodeEditor.Base/Services/NodeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,27 @@ internal static IConnector CreateConnector(IPin? start, IPin? end)

public IDrawingNode CreateDrawing(string? name = null)
{
var settings = new DrawingNodeSettingsViewModel()
{
EnableMultiplePinConnections = true,
EnableSnap = true,
SnapX = 15.0,
SnapY = 15.0,
EnableGrid = true,
GridCellWidth = 15.0,
GridCellHeight = 15.0
};

var drawing = new DrawingNodeViewModel
{
Settings = settings,
Name = name,
X = 0,
Y = 0,
Width = 900,
Height = 600,
Nodes = new ObservableCollection<INode>(),
Connectors = new ObservableCollection<IConnector>(),
EnableMultiplePinConnections = true,
EnableSnap = true,
SnapX = 15.0,
SnapY = 15.0,
EnableGrid = true,
GridCellWidth = 15.0,
GridCellHeight = 15.0,
};

return drawing;
Expand Down
10 changes: 6 additions & 4 deletions samples/NodeEditor.Base/ViewModels/MainViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void About()
[RelayCommand]
private void New()
{
if (Editor?.Factory is { })
if (Editor?.Factory is not null)
{
Editor.Drawing = Editor.Factory.CreateDrawing();
Editor.Drawing.SetSerializer(Editor.Serializer);
Expand Down Expand Up @@ -118,7 +118,7 @@ private async Task Open()
using var reader = new StreamReader(stream);
var json = await reader.ReadToEndAsync();
var drawing = Editor.Serializer.Deserialize<DrawingNodeViewModel?>(json);
if (drawing is { })
if (drawing is not null)
{
Editor.Drawing = drawing;
Editor.Drawing.SetSerializer(Editor.Serializer);
Expand Down Expand Up @@ -201,10 +201,12 @@ public async Task Export()
{
var control = new DrawingNode
{
DataContext = Editor.Drawing
DrawingSource = Editor.Drawing,
Width = Editor.Drawing.Width,
Height = Editor.Drawing.Height,
};

var root = new ExportRoot()
var root = new ExportRoot
{
Width = Editor.Drawing.Width,
Height = Editor.Drawing.Height,
Expand Down
7 changes: 4 additions & 3 deletions samples/NodeEditor.Base/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
</UserControl.KeyBindings>
<DockPanel>
<views:MenuView ZoomControl="{Binding #EditorControl.ZoomControl}"
DrawingNode="{Binding #EditorControl.DrawingNode}"
x:CompileBindings="False"
DockPanel.Dock="Top" />
<Separator IsVisible="False" Classes="horizontal" DockPanel.Dock="Top" />
Expand All @@ -91,11 +90,13 @@
<DockPanel Grid.Column="0"
IsVisible="{Binding IsToolboxVisible}">
<Separator Classes="vertical" DockPanel.Dock="Right" />
<editor:Toolbox DataContext="{Binding Editor}" Name="ToolboxView" />
<editor:Toolbox TemplatesSource="{Binding Editor.Templates}"
Name="ToolboxView" />
</DockPanel>
<ThemeVariantScope RequestedThemeVariant="Light"
Grid.Column="1" Grid.ColumnSpan="2">
<editor:Editor Name="EditorControl" DataContext="{Binding Editor.Drawing}" />
<editor:Editor Name="EditorControl"
DrawingSource="{Binding Editor.Drawing, FallbackValue={x:Null}}" />
</ThemeVariantScope>
<GridSplitter Grid.Column="1" Background="Transparent" />
</Grid>
Expand Down
13 changes: 11 additions & 2 deletions samples/NodeEditor.Base/Views/MenuView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<DockPanel VerticalAlignment="Top">

<!-- Settings -->

<Button Margin="0"
Padding="6,7,6,7"
Background="Transparent"
Expand All @@ -27,7 +27,16 @@
DockPanel.Dock="Right">
<Button.Flyout>
<Flyout ShowMode="TransientWithDismissOnPointerMoveAway" Placement="BottomEdgeAlignedRight">
<editor:DrawingNodeProperties DataContext="{Binding Editor.Drawing, FallbackValue={x:Null}}"/>
<editor:DrawingNodeProperties
DataContext="{Binding Editor.Drawing, FallbackValue={x:Null}}"
EnableSnap="{Binding Settings.EnableSnap, FallbackValue={x:False}}"
SnapX="{Binding Settings.SnapX, FallbackValue='1.0'}"
SnapY="{Binding Settings.SnapY, FallbackValue='1.0'}"
EnableGrid="{Binding Settings.EnableGrid, FallbackValue={x:False}}"
GridCellWidth="{Binding Settings.GridCellWidth, FallbackValue='1.0'}"
GridCellHeight="{Binding Settings.GridCellHeight, FallbackValue={x:False}}"
DrawingWidth="{Binding Width, FallbackValue=''}"
DrawingHeight="{Binding Height, FallbackValue=''}" />
</Flyout>
</Button.Flyout>
<PathIcon Width="16" Height="16"
Expand Down
11 changes: 1 addition & 10 deletions samples/NodeEditor.Base/Views/MenuView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ public partial class MenuView : UserControl
{
public static readonly StyledProperty<NodeZoomBorder?> ZoomControlProperty =
AvaloniaProperty.Register<MenuView, NodeZoomBorder?>(nameof(ZoomControl));

public static readonly StyledProperty<DrawingNode?> DrawingNodeProperty =
AvaloniaProperty.Register<MenuView, DrawingNode?>(nameof(DrawingNode));


public MenuView()
{
InitializeComponent();
Expand All @@ -22,10 +19,4 @@ public NodeZoomBorder? ZoomControl
get => GetValue(ZoomControlProperty);
set => SetValue(ZoomControlProperty, value);
}

public DrawingNode? DrawingNode
{
get => GetValue(DrawingNodeProperty);
set => SetValue(DrawingNodeProperty, value);
}
}
24 changes: 12 additions & 12 deletions src/NodeEditorAvalonia.Model/DrawingNodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public DrawingNodeEditor(IDrawingNode node, IDrawingNodeFactory factory)

public bool IsPinConnected(IPin pin)
{
if (_node.Connectors is { })
if (_node.Connectors is not null)
{
foreach (var connector in _node.Connectors)
{
Expand All @@ -55,7 +55,7 @@ public bool IsPinConnected(IPin pin)

public bool IsConnectorMoving()
{
if (_connector is { })
if (_connector is not null)
{
return true;
}
Expand All @@ -65,9 +65,9 @@ public bool IsConnectorMoving()

public void CancelConnector()
{
if (_connector is { })
if (_connector is not null)
{
if (_node.Connectors is { })
if (_node.Connectors is not null)
{
_node.Connectors.Remove(_connector);
}
Expand All @@ -78,7 +78,7 @@ public void CancelConnector()

public bool CanSelectNodes()
{
if (_connector is { })
if (_connector is not null)
{
return false;
}
Expand All @@ -88,7 +88,7 @@ public bool CanSelectNodes()

public bool CanSelectConnectors()
{
if (_connector is { })
if (_connector is not null)
{
return false;
}
Expand All @@ -98,7 +98,7 @@ public bool CanSelectConnectors()

public bool CanConnectPin(IPin pin)
{
if (!_node.EnableMultiplePinConnections)
if (!_node.Settings.EnableMultiplePinConnections)
{
if (IsPinConnected(pin))
{
Expand All @@ -111,7 +111,7 @@ public bool CanConnectPin(IPin pin)

private void NotifyPinsRemoved(INode node)
{
if (node.Pins is { })
if (node.Pins is not null)
{
foreach (var pin in node.Pins)
{
Expand Down Expand Up @@ -156,7 +156,7 @@ public void ConnectorLeftPressed(IPin pin, bool showWhenMoving)
var x = pin.X;
var y = pin.Y;

if (pin.Parent is { })
if (pin.Parent is not null)
{
x += pin.Parent.X;
y += pin.Parent.Y;
Expand Down Expand Up @@ -208,7 +208,7 @@ public void ConnectorLeftPressed(IPin pin, bool showWhenMoving)

public void ConnectorMove(double x, double y)
{
if (_connector is { End: { } })
if (_connector is { End: not null })
{
_connector.End.X = x;
_connector.End.Y = y;
Expand Down Expand Up @@ -240,7 +240,7 @@ public void CutNodes()

_clipboard = serializer.Serialize(clipboard);

if (clipboard.SelectedNodes is { })
if (clipboard.SelectedNodes is not null)
{
foreach (var node in clipboard.SelectedNodes)
{
Expand All @@ -253,7 +253,7 @@ public void CutNodes()
}
}

if (clipboard.SelectedConnectors is { })
if (clipboard.SelectedConnectors is not null)
{
foreach (var connector in clipboard.SelectedConnectors)
{
Expand Down
15 changes: 10 additions & 5 deletions src/NodeEditorAvalonia.Model/IDrawingNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ namespace NodeEditor.Model;

public delegate void SelectionChangedEventHandler(object? sender, EventArgs e);

public interface IDrawingNode : INode
public interface IDrawingNodeSettings
{
public event SelectionChangedEventHandler? SelectionChanged;
IList<INode>? Nodes { get; set; }
IList<IConnector>? Connectors { get; set; }
ISet<INode>? GetSelectedNodes();
bool EnableMultiplePinConnections { get; set; }
bool EnableSnap { get; set; }
double SnapX { get; set; }
double SnapY { get; set; }
bool EnableGrid { get; set; }
double GridCellWidth { get; set; }
double GridCellHeight { get; set; }
}

public interface IDrawingNode : INode
{
public event SelectionChangedEventHandler? SelectionChanged;
IList<INode>? Nodes { get; set; }
IList<IConnector>? Connectors { get; set; }
IDrawingNodeSettings Settings { get; set; }
ISet<INode>? GetSelectedNodes();
ICommand CutNodesCommand { get; }
ICommand CopyNodesCommand { get; }
ICommand PasteNodesCommand { get; }
Expand Down
Loading

0 comments on commit a9544a0

Please sign in to comment.