Skip to content

Commit

Permalink
Добавил OR_8 и AND_8 вентили.
Browse files Browse the repository at this point in the history
Сильно переписал определение минимальных размеров элементов схемы.
Дописал VirtualizationMode="None" к каждому ListBox'у в качестве багофикса явного бага авалонии: AvaloniaUI/Avalonia#4265 Разумеется своим умом до такого решения я бы впринципе никогда в жизни бы не дошёл, без жёстких навыков дизассемблерщика кншн XD
  • Loading branch information
Ivann03 committed May 11, 2023
1 parent fb9d015 commit 108e685
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 10 deletions.
6 changes: 6 additions & 0 deletions LogicSimulator/LogicSimulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<Compile Update="Views\LauncherWindow.axaml.cs">
<DependentUpon>LauncherWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Shapes\AND_8.axaml.cs">
<DependentUpon>AND_8.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Shapes\NAND_2.axaml.cs">
<DependentUpon>NAND_2.axaml</DependentUpon>
</Compile>
Expand All @@ -44,6 +47,9 @@
<Compile Update="Views\Shapes\LightBulb.axaml.cs">
<DependentUpon>LightBulb.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Shapes\OR_8.axaml.cs">
<DependentUpon>OR_8.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Shapes\Switch.axaml.cs">
<DependentUpon>Switch.axaml</DependentUpon>
</Compile>
Expand Down
4 changes: 3 additions & 1 deletion LogicSimulator/Models/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ private static IGate CreateItem(int n) {
7 => new LightBulb(),
8 => new NAND_2(),
9 => new FlipFlop(),
10 => new OR_8(),
11 => new AND_8(),
_ => new AND_2(),
};
}

public IGate[] item_types = Enumerable.Range(0, 10).Select(CreateItem).ToArray();
public IGate[] item_types = Enumerable.Range(0, 12).Select(CreateItem).ToArray();

public IGate GenSelectedItem() => CreateItem(selected_item);

Expand Down
4 changes: 2 additions & 2 deletions LogicSimulator/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<TextBlock Text="{Binding Logg}" Background="AliceBlue"/>
<Canvas Tag="Scene" Name="Canvas" Background="#0000"/>
</Panel>
<ListBox Items="{Binding ItemTypes}" SelectedIndex="{Binding SelectedItem}" Name="Gates">
<ListBox Items="{Binding ItemTypes}" SelectedIndex="{Binding SelectedItem}" Name="Gates" VirtualizationMode="None">
<ListBox.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}"/>
Expand All @@ -67,7 +67,7 @@
</Button>
</Grid>
</Border>
<ListBox Grid.Row="1" Padding="10 4 0 0" Items="{Binding Schemes}">
<ListBox Grid.Row="1" Padding="10 4 0 0" Items="{Binding Schemes}" VirtualizationMode="None">
<ListBox.ItemTemplate>
<DataTemplate>
<Border Classes="b">
Expand Down
18 changes: 18 additions & 0 deletions LogicSimulator/Views/Shapes/AND_8.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="{Binding UC_Width}" d:DesignHeight="{Binding UC_Height}"
Width="{Binding UC_Width}" Height="{Binding UC_Height}"
x:Class="LogicSimulator.Views.Shapes.AND_8"
Tag="Gate">

<Canvas Tag="Gate">
<Border Tag="Body" Margin="{Binding BodyMargin}" Background="#08c" BorderThickness="{Binding BodyStrokeSize}" BorderBrush="#4cf" Width="{Binding BodyWidth}" Height="{Binding BodyHeight}" CornerRadius="{Binding BodyRadius}">
<Panel>
<TextBlock Tag="Body" FontSize="{Binding FontSizze}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White">AND</TextBlock>
<Image Tag="Resizer" Width="{Binding ImageSize}" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="{Binding ImageMargins}" Height="{Binding ImageSize}" Source="avares://LogicSimulator/Assets/Resizer.png"/>
</Panel>
</Border>
</Canvas>
</UserControl>
25 changes: 25 additions & 0 deletions LogicSimulator/Views/Shapes/AND_8.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Avalonia.Controls;
using System.ComponentModel;

namespace LogicSimulator.Views.Shapes {
public partial class AND_8: GateBase, IGate, INotifyPropertyChanged {
public override int TypeId => 11;

public override UserControl GetSelf() => this;
protected override IGate GetSelfI => this;
protected override int[][] Sides => new int[][] {
System.Array.Empty<int>(),
new int[] { 0, 0, 0, 0, 0, 0, 0, 0 },
new int[] { 1 },
System.Array.Empty<int>()
};

protected override void Init() => InitializeComponent();

/*
* Мозги
*/

public void Brain(ref bool[] ins, ref bool[] outs) => outs[0] = ins[0] && ins[1] && ins[2] && ins[3] && ins[3] && ins[5] && ins[6] && ins[7];
}
}
14 changes: 9 additions & 5 deletions LogicSimulator/Views/Shapes/GateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ public GateBase() {
CountIns = ins;
CountOuts = outs + ios;

double sizer = sides.Select(x => x.Length).Max();
width = height = 30 * (2 + sizer / 2);
/* double sizer = sides.Select(x => x.Length).Max();
double vert_sizer = Math.Max(Math.Max(sides[0].Length, sides[3].Length), 3);
width = 30 * (2 + Math.Min(sizer, vert_sizer) / 2);
height = Math.Max(30 * (2 + sizer / 2), (9 + 32) * 2 / 3 * (1.5 + 0.75 * CountIns.Max(CountOuts)));*/
width = MinW; height = MinH;
// AvaloniaXamlLoader.Load(GetSelf()); // InitializeComponent(); Не вышло :///
// А так от Init бы полностью отказался бы ;'-} Принцип Подскановки Лископ бы просто пылал от этого, хоть абстрактному классу и положено зависеть от потомка ;'-}
DataContext = GetSelf();
Expand Down Expand Up @@ -91,10 +94,11 @@ public void Move(Point pos, bool global = false) {
UpdateJoins(global);
}

private double MinW => BodyRadius.TopLeft * 2 + (EllipseSize + BaseFraction * 2) * (Sides[0].Length.Max(Sides[3].Length).Max(2) - 0.8);
private double MinH => BodyRadius.TopLeft * 2 + (EllipseSize + BaseFraction * 2) * (Sides[1].Length.Max(Sides[2].Length).Max(2) - 0.8);
public void Resize(Size size, bool global = false) {
double limit = (9 + 32) * 2 * (base_size / 25);
width = size.Width.Max(limit / 3 * (CountIns == 0 || CountOuts == 0 ? 2.25 : 3));
height = size.Height.Max(limit / 3 * (1.5 + 0.75 * CountIns.Max(CountOuts)));
width = size.Width.Max(MinW);
height = size.Height.Max(MinH);
RecalcSizes();
UpdateJoins(global);
}
Expand Down
18 changes: 18 additions & 0 deletions LogicSimulator/Views/Shapes/OR_8.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="{Binding UC_Width}" d:DesignHeight="{Binding UC_Height}"
Width="{Binding UC_Width}" Height="{Binding UC_Height}"
x:Class="LogicSimulator.Views.Shapes.OR_8"
Tag="Gate">

<Canvas Tag="Gate">
<Border Tag="Body" Margin="{Binding BodyMargin}" Background="#08c" BorderThickness="{Binding BodyStrokeSize}" BorderBrush="#4cf" Width="{Binding BodyWidth}" Height="{Binding BodyHeight}" CornerRadius="{Binding BodyRadius}">
<Panel>
<TextBlock Tag="Body" FontSize="{Binding FontSizze}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White">OR</TextBlock>
<Image Tag="Resizer" Width="{Binding ImageSize}" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="{Binding ImageMargins}" Height="{Binding ImageSize}" Source="avares://LogicSimulator/Assets/Resizer.png"/>
</Panel>
</Border>
</Canvas>
</UserControl>
25 changes: 25 additions & 0 deletions LogicSimulator/Views/Shapes/OR_8.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Avalonia.Controls;
using System.ComponentModel;

namespace LogicSimulator.Views.Shapes {
public partial class OR_8: GateBase, IGate, INotifyPropertyChanged {
public override int TypeId => 10;

public override UserControl GetSelf() => this;
protected override IGate GetSelfI => this;
protected override int[][] Sides => new int[][] {
System.Array.Empty<int>(),
new int[] { 0, 0, 0, 0, 0, 0, 0, 0 },
new int[] { 1 },
System.Array.Empty<int>()
};

protected override void Init() => InitializeComponent();

/*
* Мозги
*/

public void Brain(ref bool[] ins, ref bool[] outs) => outs[0] = ins[0] || ins[1] || ins[2] || ins[3] || ins[4] || ins[5] || ins[6] || ins[7];
}
}
2 changes: 1 addition & 1 deletion LogicSimulator/for_test.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name": "Для тестирования", "created": 1683838621, "modified": 1683839324, "items": [{"id": 5, "pos": "$p$149,242", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 5, "pos": "$p$153,330", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 5, "pos": "$p$152,414", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 5, "pos": "$p$149,497", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 9, "pos": "$p$587,328", "size": "$s$105,105", "base_size": 25, "state": "0.1.0.1.0.0"}, {"id": 3, "pos": "$p$339,236", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$348,336", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$352,444", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$355,546", "size": "$s$90,90", "base_size": 25}, {"id": 9, "pos": "$p$594,460", "size": "$s$105,105", "base_size": 25, "state": "0.0.1.0.0.0"}, {"id": 3, "pos": "$p$591,182", "size": "$s$90,90", "base_size": 25}, {"id": 7, "pos": "$p$749,199", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$750,276", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$751,354", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$751,430", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$752,506", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$755,584", "size": "$s$75,75", "base_size": 25}, {"id": 1, "pos": "$p$592,596", "size": "$s$90,90", "base_size": 25}], "joins": [[0, 0, "Out", 5, 0, "In"], [1, 0, "Out", 6, 0, "In"], [2, 0, "Out", 7, 0, "In"], [3, 0, "Out", 8, 0, "In"], [4, 3, "Out", 6, 1, "In"], [11, 0, "In", 4, 3, "Out"], [4, 4, "Out", 10, 0, "In"], [12, 0, "In", 4, 4, "Out"], [13, 0, "In", 4, 5, "Out"], [4, 5, "Out", 17, 0, "In"], [4, 0, "In", 5, 2, "Out"], [6, 2, "Out", 4, 1, "In"], [6, 2, "Out", 9, 2, "In"], [7, 2, "Out", 4, 2, "In"], [7, 2, "Out", 9, 1, "In"], [8, 2, "Out", 9, 0, "In"], [9, 3, "Out", 10, 1, "In"], [14, 0, "In", 9, 3, "Out"], [15, 0, "In", 9, 4, "Out"], [9, 4, "Out", 17, 1, "In"], [16, 0, "In", 9, 5, "Out"], [9, 5, "Out", 7, 1, "In"], [10, 2, "Out", 5, 1, "In"], [17, 2, "Out", 8, 1, "In"]], "states": "00000100010000000000000"}
{"name": "Для тестирования #2", "created": 1683843280, "modified": 1683846735, "items": [{"id": 3, "pos": "$p$6127,2377", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 3, "pos": "$p$6127,3058", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 3, "pos": "$p$6136,3747", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 3, "pos": "$p$6172,4437", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 7, "pos": "$p$9064,2637", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 7, "pos": "$p$7829,2583", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 7, "pos": "$p$8438,1911", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 7, "pos": "$p$8420,3273", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 7, "pos": "$p$7739,3917", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 7, "pos": "$p$8420,4544", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 7, "pos": "$p$9199,3917", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 3, "pos": "$p$6208,5153", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 3, "pos": "$p$6127,1679", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 3, "pos": "$p$6127,989", "size": "$s$720,685", "base_size": 185.00624860645544}, {"id": 10, "pos": "$p$4108,933", "size": "$s$366,861", "base_size": 104.43120423539197}, {"id": 10, "pos": "$p$4121,1805", "size": "$s$366,861", "base_size": 104.43120423539197}, {"id": 10, "pos": "$p$4133,2675", "size": "$s$366,861", "base_size": 104.43120423539197}, {"id": 10, "pos": "$p$4141,3552", "size": "$s$366,861", "base_size": 104.43120423539197}, {"id": 10, "pos": "$p$4141,4438", "size": "$s$366,861", "base_size": 104.43120423539197}, {"id": 10, "pos": "$p$4158,5303", "size": "$s$366,861", "base_size": 104.43120423539197}, {"id": 10, "pos": "$p$4145,6180", "size": "$s$366,861", "base_size": 104.43120423539197}, {"id": 5, "pos": "$p$-1385,804", "size": "$s$714,702", "base_size": 203.50687346710035, "state": false}, {"id": 5, "pos": "$p$-1369,1537", "size": "$s$714,702", "base_size": 203.50687346710035, "state": false}, {"id": 5, "pos": "$p$-1353,2310", "size": "$s$714,702", "base_size": 203.50687346710035, "state": false}, {"id": 5, "pos": "$p$-1353,3075", "size": "$s$714,702", "base_size": 203.50687346710035, "state": false}, {"id": 5, "pos": "$p$-1412,5012", "size": "$s$714,702", "base_size": 203.50687346710035, "state": false}, {"id": 2, "pos": "$p$-746,1138", "size": "$s$333,327", "base_size": 94.93745839581057}, {"id": 2, "pos": "$p$-700,1878", "size": "$s$333,327", "base_size": 94.93745839581057}, {"id": 2, "pos": "$p$-712,2672", "size": "$s$333,327", "base_size": 94.93745839581057}, {"id": 2, "pos": "$p$-719,3477", "size": "$s$333,327", "base_size": 94.93745839581057}, {"id": 11, "pos": "$p$755,1028", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$784,1715", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$762,353", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$771,-315", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$787,2386", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$787,3035", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$781,3713", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$778,4369", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$759,-997", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$759,-1665", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$769,5053", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$756,5753", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$753,-2355", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$789,6438", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$785,7094", "size": "$s$275,647", "base_size": 78.46070941802523}, {"id": 11, "pos": "$p$791,7752", "size": "$s$275,647", "base_size": 78.46070941802516}, {"id": 2, "pos": "$p$403,-2225", "size": "$s$87,86", "base_size": 25}, {"id": 2, "pos": "$p$432,-1544", "size": "$s$87,86", "base_size": 25}, {"id": 2, "pos": "$p$422,-880", "size": "$s$87,86", "base_size": 25}, {"id": 2, "pos": "$p$423,-194", "size": "$s$83,83", "base_size": 25}, {"id": 2, "pos": "$p$417,467", "size": "$s$83,83", "base_size": 25}], "joins": [[4, 0, "In", 0, 2, "Out"], [7, 0, "In", 1, 2, "Out"], [8, 0, "In", 2, 2, "Out"], [10, 0, "In", 3, 2, "Out"], [9, 0, "In", 11, 2, "Out"], [5, 0, "In", 12, 2, "Out"], [6, 0, "In", 13, 2, "Out"], [14, 8, "Out", 13, 0, "In"], [15, 8, "Out", 12, 0, "In"], [16, 8, "Out", 0, 0, "In"], [17, 8, "Out", 1, 0, "In"], [18, 8, "Out", 2, 0, "In"], [19, 8, "Out", 3, 0, "In"], [20, 8, "Out", 11, 0, "In"], [26, 0, "In", 21, 0, "Out"], [27, 0, "In", 22, 0, "Out"], [28, 0, "In", 23, 0, "Out"], [29, 0, "In", 24, 0, "Out"], [46, 1, "Out", 42, 4, "In"], [46, 1, "Out", 42, 5, "In"], [46, 1, "Out", 42, 6, "In"], [46, 1, "Out", 42, 7, "In"], [47, 1, "Out", 39, 4, "In"], [39, 5, "In", 47, 1, "Out"], [47, 1, "Out", 39, 6, "In"], [39, 7, "In", 47, 1, "Out"], [48, 1, "Out", 38, 4, "In"], [48, 1, "Out", 38, 5, "In"], [48, 1, "Out", 38, 6, "In"], [48, 1, "Out", 38, 7, "In"], [49, 1, "Out", 33, 4, "In"], [49, 1, "Out", 33, 5, "In"], [49, 1, "Out", 33, 6, "In"], [49, 1, "Out", 33, 7, "In"], [50, 1, "Out", 32, 4, "In"], [50, 1, "Out", 32, 5, "In"], [50, 1, "Out", 32, 6, "In"], [50, 1, "Out", 32, 7, "In"]], "states": "000000000000000000000000000000011000001111111000000000000000000000000011111"}
2 changes: 1 addition & 1 deletion build.num
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1089
1107

0 comments on commit 108e685

Please sign in to comment.