From 2c00cbffed3ee025533323ab76111bf14ebe04a5 Mon Sep 17 00:00:00 2001 From: AndrewF001 <42306036+AndrewF001@users.noreply.github.com> Date: Wed, 8 Jan 2020 13:30:16 +0000 Subject: [PATCH 1/4] the showdialog is solved Hopefully this branch doesn't break everything else. --- .../A level course work Logic Gate.sln | 25 + .../A level course work Logic Gate.csproj | 149 ++++++ .../A level course work Logic Gate/App.config | 7 + .../A level course work Logic Gate/App.xaml | 20 + .../App.xaml.cs | 24 + .../Canvas_Class.cs | 376 +++++++++++++++ .../Gate_Class.cs | 125 +++++ .../Input_Button.cs | 61 +++ .../Input_Class.cs | 57 +++ .../Line_Class.cs | 60 +++ .../MainWindow.xaml | 57 +++ .../MainWindow.xaml.cs | 440 ++++++++++++++++++ .../Output_Circle.cs | 65 +++ .../Output_Class.cs | 48 ++ .../Progress_Bar_Window.xaml | 14 + .../Progress_Bar_Window.xaml.cs | 47 ++ .../Properties/AssemblyInfo.cs | 55 +++ .../Properties/Resources.Designer.cs | 63 +++ .../Properties/Resources.resx | 117 +++++ .../Properties/Settings.Designer.cs | 26 ++ .../Properties/Settings.settings | 7 + .../Resource/And_Gate_F.xaml | 49 ++ .../Resource/Nand_Gate_F.xaml | 55 +++ .../Resource/Nor_Gate_F.xaml | 54 +++ .../Resource/Not_Gate_F.xaml | 34 ++ .../Resource/Or_Gate_F.xaml | 48 ++ .../Resource/Transformer.xaml | 56 +++ .../Resource/Xnor_Gate_F.xaml | 50 ++ .../Resource/Xor_Gate_F.xaml | 44 ++ .../Debug/A level course work Logic Gate.exe | Bin 0 -> 68096 bytes .../A level course work Logic Gate.exe.config | 7 + .../Debug/A level course work Logic Gate.pdb | Bin 0 -> 95744 bytes .../A level course work Logic Gate.vshost.exe | Bin 0 -> 22696 bytes ...l course work Logic Gate.vshost.exe.config | 7 + ...course work Logic Gate.vshost.exe.manifest | 11 + ...ork Logic Gate.csproj.FileListAbsolute.txt | 25 + ...k Logic Gate.csproj.GenerateResource.Cache | Bin 0 -> 918 bytes ... Gate.csprojResolveAssemblyReference.cache | Bin 0 -> 2529 bytes .../Debug/A level course work Logic Gate.exe | Bin 0 -> 68096 bytes ...A level course work Logic Gate.g.resources | Bin 0 -> 32815 bytes .../Debug/A level course work Logic Gate.pdb | Bin 0 -> 95744 bytes ...course work Logic Gate_MarkupCompile.cache | 20 + ...urse work Logic Gate_MarkupCompile.i.cache | 20 + ...ourse work Logic Gate_MarkupCompile.i.lref | 5 + ... course work Logic Gate_MarkupCompile.lref | 5 + ..._Logic_Gate.Properties.Resources.resources | Bin 0 -> 180 bytes .../obj/Debug/App.baml | Bin 0 -> 1357 bytes .../obj/Debug/App.g.cs | 83 ++++ .../obj/Debug/App.g.i.cs | 83 ++++ .../DesignTimeResolveAssemblyReferences.cache | Bin 0 -> 1034 bytes ...gnTimeResolveAssemblyReferencesInput.cache | Bin 0 -> 7468 bytes .../obj/Debug/MainWindow.baml | Bin 0 -> 4306 bytes .../obj/Debug/MainWindow.g.cs | 354 ++++++++++++++ .../obj/Debug/MainWindow.g.i.cs | 354 ++++++++++++++ .../obj/Debug/Progress_Bar_Window.baml | Bin 0 -> 1501 bytes .../obj/Debug/Progress_Bar_Window.g.cs | 97 ++++ .../obj/Debug/Progress_Bar_Window.g.i.cs | 97 ++++ .../obj/Debug/Resource/And_Gate_F.baml | Bin 0 -> 2648 bytes .../obj/Debug/Resource/Nand_Gate_F.baml | Bin 0 -> 3177 bytes .../obj/Debug/Resource/Nor_Gate_F.baml | Bin 0 -> 3771 bytes .../obj/Debug/Resource/Not_Gate_F.baml | Bin 0 -> 2458 bytes .../obj/Debug/Resource/Or_Gate_F.baml | Bin 0 -> 3251 bytes .../obj/Debug/Resource/Transformer.baml | Bin 0 -> 2051 bytes .../obj/Debug/Resource/Xnor_Gate_F.baml | Bin 0 -> 3960 bytes .../obj/Debug/Resource/Xor_Gate_F.baml | Bin 0 -> 3475 bytes .../Properties.Resources.Designer.cs.dll | Bin 0 -> 3584 bytes 66 files changed, 3401 insertions(+) create mode 100644 CourseWork-master/A level course work Logic Gate.sln create mode 100644 CourseWork-master/A level course work Logic Gate/A level course work Logic Gate.csproj create mode 100644 CourseWork-master/A level course work Logic Gate/App.config create mode 100644 CourseWork-master/A level course work Logic Gate/App.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/App.xaml.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Canvas_Class.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Gate_Class.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Input_Button.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Input_Class.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Line_Class.cs create mode 100644 CourseWork-master/A level course work Logic Gate/MainWindow.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/MainWindow.xaml.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Output_Circle.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Output_Class.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Progress_Bar_Window.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Progress_Bar_Window.xaml.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Properties/AssemblyInfo.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Properties/Resources.Designer.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Properties/Resources.resx create mode 100644 CourseWork-master/A level course work Logic Gate/Properties/Settings.Designer.cs create mode 100644 CourseWork-master/A level course work Logic Gate/Properties/Settings.settings create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/And_Gate_F.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/Nand_Gate_F.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/Nor_Gate_F.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/Not_Gate_F.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/Or_Gate_F.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/Transformer.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/Xnor_Gate_F.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/Resource/Xor_Gate_F.xaml create mode 100644 CourseWork-master/A level course work Logic Gate/bin/Debug/A level course work Logic Gate.exe create mode 100644 CourseWork-master/A level course work Logic Gate/bin/Debug/A level course work Logic Gate.exe.config create mode 100644 CourseWork-master/A level course work Logic Gate/bin/Debug/A level course work Logic Gate.pdb create mode 100644 CourseWork-master/A level course work Logic Gate/bin/Debug/A level course work Logic Gate.vshost.exe create mode 100644 CourseWork-master/A level course work Logic Gate/bin/Debug/A level course work Logic Gate.vshost.exe.config create mode 100644 CourseWork-master/A level course work Logic Gate/bin/Debug/A level course work Logic Gate.vshost.exe.manifest create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate.csproj.FileListAbsolute.txt create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate.csproj.GenerateResource.Cache create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate.csprojResolveAssemblyReference.cache create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate.exe create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate.g.resources create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate.pdb create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate_MarkupCompile.cache create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate_MarkupCompile.i.cache create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate_MarkupCompile.i.lref create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A level course work Logic Gate_MarkupCompile.lref create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/A_level_course_work_Logic_Gate.Properties.Resources.resources create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/App.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/App.g.cs create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/App.g.i.cs create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/DesignTimeResolveAssemblyReferences.cache create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/MainWindow.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/MainWindow.g.cs create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/MainWindow.g.i.cs create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Progress_Bar_Window.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Progress_Bar_Window.g.cs create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Progress_Bar_Window.g.i.cs create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/And_Gate_F.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/Nand_Gate_F.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/Nor_Gate_F.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/Not_Gate_F.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/Or_Gate_F.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/Transformer.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/Xnor_Gate_F.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/Resource/Xor_Gate_F.baml create mode 100644 CourseWork-master/A level course work Logic Gate/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll diff --git a/CourseWork-master/A level course work Logic Gate.sln b/CourseWork-master/A level course work Logic Gate.sln new file mode 100644 index 0000000..5299214 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.352 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A level course work Logic Gate", "A level course work Logic Gate\A level course work Logic Gate.csproj", "{F6B37528-1F7F-43CA-ACD1-BEF929DAF16F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F6B37528-1F7F-43CA-ACD1-BEF929DAF16F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6B37528-1F7F-43CA-ACD1-BEF929DAF16F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6B37528-1F7F-43CA-ACD1-BEF929DAF16F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6B37528-1F7F-43CA-ACD1-BEF929DAF16F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E55E48FD-5E1B-4C05-A1C5-8232982E668F} + EndGlobalSection +EndGlobal diff --git a/CourseWork-master/A level course work Logic Gate/A level course work Logic Gate.csproj b/CourseWork-master/A level course work Logic Gate/A level course work Logic Gate.csproj new file mode 100644 index 0000000..14eef9d --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/A level course work Logic Gate.csproj @@ -0,0 +1,149 @@ + + + + + Debug + AnyCPU + {F6B37528-1F7F-43CA-ACD1-BEF929DAF16F} + Exe + A_level_course_work_Logic_Gate + A level course work Logic Gate + v4.5.2 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + + + + + + + MainWindow.xaml + Code + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + + Progress_Bar_Window.xaml + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + \ No newline at end of file diff --git a/CourseWork-master/A level course work Logic Gate/App.config b/CourseWork-master/A level course work Logic Gate/App.config new file mode 100644 index 0000000..efc3ffd --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/App.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/CourseWork-master/A level course work Logic Gate/App.xaml b/CourseWork-master/A level course work Logic Gate/App.xaml new file mode 100644 index 0000000..9f30b70 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/App.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + diff --git a/CourseWork-master/A level course work Logic Gate/App.xaml.cs b/CourseWork-master/A level course work Logic Gate/App.xaml.cs new file mode 100644 index 0000000..12b5dd9 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/App.xaml.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace A_level_course_work_Logic_Gate +{ + /// + /// Interaction logic for App.xaml + /// + /// + + public partial class App : Application + { + public App() + { + ShutdownMode = ShutdownMode.OnExplicitShutdown; + } + } + +} diff --git a/CourseWork-master/A level course work Logic Gate/Canvas_Class.cs b/CourseWork-master/A level course work Logic Gate/Canvas_Class.cs new file mode 100644 index 0000000..d134adb --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/Canvas_Class.cs @@ -0,0 +1,376 @@ +using System; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +namespace A_level_course_work_Logic_Gate +{ + public class Canvas_Class : Canvas + { + public Point Old_Pos { get; set; } = new Point(); + public double Scale_Factor { get; set; } = 1; + public Point Old_Rect { get; set; } = new Point(); + + + public MainWindow _MainWind { get; set; } + + public TranslateTransform Translate_Action { get; set; } + public ScaleTransform Scale_Action { get; set; } + + public TransformGroup Transforms_Group { get; set; } + + + public bool MovingCanvas { get; set; } = false; + + public Canvas_Class(MainWindow MainWind) + { + _MainWind = MainWind; + Background = Brushes.Gray; + + Translate_Action = new TranslateTransform(0, 0); + Scale_Action = new ScaleTransform(1, 1, 0, 0); + Transforms_Group = new TransformGroup(); + + Transforms_Group.Children.Add(Translate_Action); + Transforms_Group.Children.Add(Scale_Action); + + RenderTransform = Transforms_Group; + } + //Move canvas event + protected override void OnMouseMove(MouseEventArgs e) + { + int hold = Rect_detection(0, 0, -1); + if (hold != _MainWind.Last_ID_For_Rect && hold !=-1) + { + _MainWind.Last_ID_For_Rect = hold; + _MainWind.Gate_List[hold].Output_Rect_Status(hold); + } + + + if (MovingCanvas) + { + Translate_Action.X += (e.GetPosition(this).X - Old_Pos.X); + Translate_Action.Y += (e.GetPosition(this).Y - Old_Pos.Y); + } + Old_Pos = e.GetPosition(this); + } + + + //zoom event + protected override void OnMouseWheel(MouseWheelEventArgs e) + { + bool change = false; + Point Pos = Mouse.GetPosition(_MainWind.Canvas_Border); + if (e.Delta > 0) + { + if (Scale_Factor != 0.0625) + { + Scale_Factor -= 0.0625; + change = true; + } + } + else if (e.Delta < 0) + { + if (Scale_Factor != 2) + { + Scale_Factor += 0.0625; + change = true; + } + } + + if (change) + { + Scale_Action.ScaleX = Scale_Factor; + Scale_Action.ScaleY = Scale_Factor; + Scale_Action.CenterX = Pos.X; + Scale_Action.CenterY = Pos.Y; + } + } + //Re-drag pick up + protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) + { + int detected = Rect_detection(0, 0, -1); + + //if(!_mainwind.drag) then switch + + if(!_MainWind.Drag&&detected==-1) + { + Old_Pos = e.GetPosition(this); + MovingCanvas = true; + } + + if (!_MainWind.Drag && !_MainWind.Link) + { + if (detected != -1) + { + _MainWind.Drag_Num = detected; + _MainWind.Drag_Mode = Drag_State.Sub_Can; + Old_Rect = new Point(Convert.ToDouble(Canvas.GetLeft(_MainWind.Gate_List[_MainWind.Drag_Num].Rect)), Convert.ToDouble(Canvas.GetTop(_MainWind.Gate_List[_MainWind.Drag_Num].Rect))); + } + } + else if (!_MainWind.Drag && _MainWind.Link && detected!=-1) + { + _MainWind.Linking_ID = detected; + _MainWind.Drag_Num = _MainWind.Line_List.Count(); + _MainWind.Line_List.Add(new Line_Class(detected,_MainWind)); + _MainWind.Line_List.Last().Track_Mouse(); + _MainWind.Line_List.Last().Input_ID=detected; + _MainWind.Line_List.Last().Output_Num = Link_Output_Vaildation(detected); + //if X == -2 then there was no aviable output for the new link to be made(already deleted the last line) + if (_MainWind.Line_List.Last().Output_Num != -2) + { + _MainWind.Drag_Mode = Drag_State.Link_Mode_Sub; + _MainWind.Gate_List[detected].Output[_MainWind.Line_List.Last().Output_Num].Line_ID = _MainWind.Drag_Num; + _MainWind.Line_List[_MainWind.Drag_Num].Link_Output_Aline_Line(_MainWind.Gate_List[detected]); + } + else + { + Children.Remove(_MainWind.Line_List[_MainWind.Drag_Num].UI_Line); + _MainWind.Line_List.RemoveAt(_MainWind.Drag_Num); + } + + } + } + //Re-drag drop + protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) + { + MovingCanvas = false; + if (_MainWind.Drag && !_MainWind.Link) + { + _MainWind.Drag_Mode = Drag_State.Null; + if(Rect_detection(_MainWind.Gate_List[_MainWind.Drag_Num].Rect.Width, _MainWind.Gate_List[_MainWind.Drag_Num].Rect.Height, _MainWind.Drag_Num) !=-1) + { + SetLeft(_MainWind.Gate_List[_MainWind.Drag_Num].Rect, Old_Rect.X); + SetTop(_MainWind.Gate_List[_MainWind.Drag_Num].Rect,Old_Rect.Y); + _MainWind.Gate_List[_MainWind.Drag_Num].Move_IO(); + } + } + else if(_MainWind.Drag && _MainWind.Link) + { + int X = -1; + int detection = Rect_detection(0, 0, -1); + _MainWind.Drag_Mode = Drag_State.Null; + if (detection != -1 && detection != _MainWind.Linking_ID) + { + X = Link_Input_Vaildation(detection); + } + + if (X!=-1) + { + + _MainWind.Line_List[_MainWind.Drag_Num].Input_ID = detection; + _MainWind.Line_List[_MainWind.Drag_Num].Input_Num = X; + _MainWind.Line_List[_MainWind.Drag_Num].Link_Input_Aline_Line(_MainWind.Gate_List[detection]); + _MainWind.Gate_List[detection].Input[X].Input_Type = IO_Type.Gate; + _MainWind.Gate_List[detection].Input[X].Input_ID = _MainWind.Linking_ID; + _MainWind.Gate_List[detection].Input[X].Line_ID = _MainWind.Drag_Num; + _MainWind.Gate_List[_MainWind.Linking_ID].Output[_MainWind.Line_List.Last().Output_Num].Output_ID = detection; + _MainWind.Gate_List[_MainWind.Linking_ID].Output[_MainWind.Line_List.Last().Output_Num].Output_Type = IO_Type.Gate; + } + else if(X==-1) + { + Children.Remove(_MainWind.Line_List[_MainWind.Drag_Num].UI_Line); + _MainWind.Line_List.RemoveAt(_MainWind.Drag_Num); + } + } + } + + public int Rect_detection(double Width, double Height,int Drag_Num) + { + int Detected = -1; + Point Pos_Sub = Mouse.GetPosition(this); + for (int i = 0; i < _MainWind.Gate_List.Count(); i++) + { + Gate_Class Rect = _MainWind.Gate_List[i]; + double Rect_X = Canvas.GetLeft(_MainWind.Gate_List[i].Rect); + double Rect_Y = Canvas.GetTop(_MainWind.Gate_List[i].Rect); + if (Pos_Sub.X+Width > Rect_X && Pos_Sub.X < Rect_X + Rect.Rect.Width && Pos_Sub.Y+Height > Rect_Y && Pos_Sub.Y < Rect_Y + Rect.Rect.Height&&i!=Drag_Num && Rect.Alive) + Detected = i; + } + return Detected; + } + + public int Link_Output_Vaildation(int Clicked) + { + int Output_pos = Output_Slot(Clicked); + if (_MainWind.Gate_List[Clicked].Type == 7) + { + if (_MainWind.Gate_List[Clicked].Output[Output_pos].Output_ID != -1) + { + Output_pos = -2; + } + //if the above failed then it will enter this if statement + if (Output_pos == -2) + { + //this will check each output and try and find a available output + if(_MainWind.Gate_List[Clicked].Output[0].Output_ID == -1) + Output_pos = 0; + else if (_MainWind.Gate_List[Clicked].Output[1].Output_ID == -1) + Output_pos = 1; + else if (_MainWind.Gate_List[Clicked].Output[2].Output_ID == -1) + Output_pos = 2; + } + } + else + { + if (_MainWind.Gate_List[Clicked].Output[0].Output_ID != -1) + { + Output_pos = -2; + } + } + + return Output_pos; + } + + public int Output_Slot(int Clicked) + { + int Output = 0; + Point Pos = Mouse.GetPosition(this); + if (_MainWind.Gate_List[Clicked].Type == 7) + { + if (Pos.Y < GetTop(_MainWind.Gate_List[Clicked].Rect) + 29) + Output = 0; + else if (Pos.Y > GetTop(_MainWind.Gate_List[Clicked].Rect) + 29 && Pos.Y < GetTop(_MainWind.Gate_List[Clicked].Rect) + 43) + Output = 1; + else if (Pos.Y > GetTop(_MainWind.Gate_List[Clicked].Rect) + 43) + Output = 2; + } + else + { + Output = 0; + } + return Output; + } + + public int Link_Input_Vaildation(int Clicked) + { + int Output = Input_Slot(Clicked); + Point Pos = Mouse.GetPosition(this); + if(_MainWind.Gate_List[Clicked].Type==2|| _MainWind.Gate_List[Clicked].Type == 7) + { + if(_MainWind.Gate_List[Clicked].Input[0].Input_ID!=-1) + { + Output = -1; + } + } + else + { + if (_MainWind.Gate_List[Clicked].Input[Output].Input_ID != -1) + { + Output = -1; + } + + if (Output == -1) + { + if(_MainWind.Gate_List[Clicked].Input[0].Input_ID == -1) + { + Output = 0; + } + else if (_MainWind.Gate_List[Clicked].Input[1].Input_ID == -1) + { + Output = 1; + } + + } + } + + return Output; + } + + public int Input_Slot(int Clicked) + { + int Input_Slot = -1; + Point Pos = Mouse.GetPosition(this); + if (_MainWind.Gate_List[Clicked].Type == 2 || _MainWind.Gate_List[Clicked].Type == 7) + { + Input_Slot = 0; + } + else + { + if (Pos.Y < GetTop(_MainWind.Gate_List[Clicked].Rect) + 37) + { + Input_Slot = 0; + } + else + { + Input_Slot = 1; + } + } + + return Input_Slot; + } + + protected override void OnMouseRightButtonUp(MouseButtonEventArgs e) + { + //checks you're not dragging + if(!_MainWind.Drag) + { + //sees if you acutally right click on something + int detection = Rect_detection(0, 0, -1); + if (detection!=-1) + { //see which mode of the program you're in because each one will have a different action + if(!_MainWind.Link) + { //completely romoves the gate. + _MainWind.Gate_List[detection].Alive = false; + Children.Remove(_MainWind.Gate_List[detection].Rect); + for (int i = 0; i < 3; i++) //this is for each output of the gate after it's been removed + { + if(_MainWind.Gate_List[detection].Output[i].Output_Type == IO_Type.Gate) + { //removes the line "connecting" the 2 gates. + _MainWind.Sub_Canvas.Children.Remove(_MainWind.Line_List[_MainWind.Gate_List[detection].Output[i].Line_ID].UI_Line); + for (int x = 0; x < 2; x++) // this is to determin which input the gate is connected to + { + if (_MainWind.Gate_List[_MainWind.Gate_List[detection].Output[i].Output_ID].Input[x].Input_ID == detection && _MainWind.Gate_List[_MainWind.Gate_List[detection].Output[i].Output_ID].Input[x].Input_Type == IO_Type.Gate) + { //changes the state of the gate it's connected to too null so that it can accept another input. + _MainWind.Gate_List[_MainWind.Gate_List[detection].Output[i].Output_ID].Input[x].Input_Type = IO_Type.Null; + } + } + } + else if(_MainWind.Gate_List[detection].Output[i].Output_Type == IO_Type.IO) + { + //remove the ellipses from the canvas in the output_Circle list with the ID in the + } + } + for (int i = 0; i < 2; i++) //does the same but for input + { + if (_MainWind.Gate_List[detection].Input[i].Input_Type == IO_Type.Gate) + { + _MainWind.Sub_Canvas.Children.Remove(_MainWind.Line_List[_MainWind.Gate_List[detection].Input[i].Line_ID].UI_Line); + for (int x = 0; x < 3; x++) + { + if (_MainWind.Gate_List[_MainWind.Gate_List[detection].Input[i].Input_ID].Output[x].Output_ID == detection) + { + _MainWind.Gate_List[_MainWind.Gate_List[detection].Input[i].Input_ID].Output[x].Output_Type = IO_Type.Null; + } + } + } + else if (_MainWind.Gate_List[detection].Input[i].Input_Type == IO_Type.IO) + { + //remove the button from the canvas in the input_button list with the ID in the + } + } + } + else if(_MainWind.Link) //if in linked mode then it should act as tho you're doing the oppersite of adding a connection. + { + int Output_Num = Output_Slot(detection); + if (_MainWind.Gate_List[detection].Output[Output_Num].Output_ID != -1) + { + for (int i = 0; i < 2; i++) + { + if(_MainWind.Gate_List[_MainWind.Gate_List[detection].Output[Output_Num].Output_ID].Input[i].Input_ID==detection) + { + _MainWind.Gate_List[_MainWind.Gate_List[detection].Output[Output_Num].Output_ID].Input[i].Input_Type = IO_Type.Null; + } + } + _MainWind.Sub_Canvas.Children.Remove(_MainWind.Line_List[_MainWind.Gate_List[detection].Output[Output_Num].Line_ID].UI_Line); + _MainWind.Gate_List[detection].Output[Output_Num].Output_Type = IO_Type.Null; + } + } + + } + } + } + } +} diff --git a/CourseWork-master/A level course work Logic Gate/Gate_Class.cs b/CourseWork-master/A level course work Logic Gate/Gate_Class.cs new file mode 100644 index 0000000..ef30767 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/Gate_Class.cs @@ -0,0 +1,125 @@ +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Shapes; +using System.Windows; +using System.Windows.Input; +using System.Collections.Generic; +using System; + +namespace A_level_course_work_Logic_Gate +{ + public class Gate_Class + { + //public int ID { get; set; } + public int Type { get; set; } + public Rectangle Rect { get; set; } + public bool Alive { get; set; } = true; + public MainWindow _MainWind { get; set; } + + //data storages for the input and output + + public Input_Class[] Input { get; set; } = new Input_Class[] { new Input_Class(), new Input_Class() }; + + //Gate output Bit + public bool Gate_Bit { get; set; } = false; + + public Output_Class[] Output { get; set; } = new Output_Class[] { new Output_Class(), new Output_Class(), new Output_Class() }; + + + + public Gate_Class(string Tag,MainWindow MainWind,double _Scale_Factor) + { + _MainWind = MainWind; + Setup(Tag,_Scale_Factor); + _MainWind.Main_Canvas.Children.Add(Rect); + Rect_Move(Mouse.GetPosition(MainWind.Main_Grid)); + } + //Basically the constructor + public void Setup(string _Tag,double _Scale_Factor) + { + //scale factor + Rect = new Rectangle { Height = 75*_Scale_Factor, Width = 115*_Scale_Factor, Stroke = Brushes.Black, Fill = Application.Current.Resources[_Tag] as Brush }; + //Calc Tag + switch(_Tag) + { + case ("And_Gate_L"): + Type = 0; + break; + case ("Nand_Gate_L"): + Type = 1; + break; + case ("Not_Gate_L"): + Type = 2; + break; + case ("Or_Gate_L"): + Type = 3; + break; + case ("Nor_Gate_L"): + Type = 4; + break; + case ("Xor_Gate_L"): + Type = 5; + break; + case ("Xnor_Gate_L"): + Type = 6; + break; + case ("Transformer"): + Type = 7; + //scale factor + Rect.Width = 85; + break; + } + } + + //change Rectangle location. + public void Rect_Move(Point Pos) + { + Canvas.SetLeft(Rect, Pos.X); + Canvas.SetTop(Rect, Pos.Y); + } + + + public void Move_IO() + { + for (int i = 0; i < 3; i++) + { + if(Output[i].Output_Type == IO_Type.Gate) + { + _MainWind.Line_List[Output[i].Line_ID].Link_Output_Aline_Line(this); + } + else if(Output[i].Output_Type == IO_Type.IO) + { + _MainWind.Output_Circle_List[Output[i].Output_ID].Aline_Circle(this); + } + } + for (int i = 0; i < 2; i++) + { + if (Input[i].Input_Type==IO_Type.Gate) + { + _MainWind.Line_List[Input[i].Line_ID].Link_Input_Aline_Line(this); + } + else if(Input[i].Input_Type == IO_Type.IO) + { + _MainWind.Input_Button_List[Input[i].Input_ID].Aline_Box(this); + } + } + } + + //delete + public void Output_Rect_Status(int ID) + { + Console.WriteLine("Rect ID : {0}\nType : {1}\nAlive : {2}\nGate Bit : {3}", ID,Type,Alive,Gate_Bit); + Console.WriteLine("\n Input 0"); + Input[0].Output_Status(); + Console.WriteLine("\n Input 1"); + Input[1].Output_Status(); + Console.WriteLine("\n Output 0"); + Output[0].Output_Status(); + Console.WriteLine("\n Output 1"); + Output[1].Output_Status(); + Console.WriteLine("\n Output 2"); + Output[2].Output_Status(); + Console.WriteLine("\n\n\n\n"); + } + } +} diff --git a/CourseWork-master/A level course work Logic Gate/Input_Button.cs b/CourseWork-master/A level course work Logic Gate/Input_Button.cs new file mode 100644 index 0000000..bceb941 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/Input_Button.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Media; + +namespace A_level_course_work_Logic_Gate +{ + public class Input_Button : Button + { + public bool Bit { get; set; } = false; + public int Input_ID { get;} + public int Input_Port; + public MainWindow _MainWind { get; set; } + public Input_Button(MainWindow MainWind,int ID, int Port_Num) + { + _MainWind = MainWind; + Input_ID = ID; + Input_Port = Port_Num; + _MainWind.Sub_Canvas.Children.Add(this); + Background = Brushes.Black; + Content = 1; + Foreground = Brushes.White; + Height = 20; + Width = 20; + + } + + protected override void OnClick() + { + if (!Bit) + { + Background = Brushes.White; + Bit = true; + Content = 0; + Foreground = Brushes.Black; + } + else + { + Background = Brushes.Black; + Bit = false; + Content = 1; + Foreground = Brushes.White; + } + } + + public void Aline_Box(Gate_Class Gate) + { + double[] hold = _MainWind.Link_Input_Aline(Gate, Input_Port); + Change_X_Y(hold[0], hold[1]); + } + + public void Change_X_Y(double x, double y) + { + Canvas.SetLeft(this, x-20); + Canvas.SetTop(this, y-10); + } + } +} diff --git a/CourseWork-master/A level course work Logic Gate/Input_Class.cs b/CourseWork-master/A level course work Logic Gate/Input_Class.cs new file mode 100644 index 0000000..ce89ec3 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/Input_Class.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace A_level_course_work_Logic_Gate +{ + public class Input_Class + { + private bool _input_bit = false; + private int _input_ID = -1; + private IO_Type _input_Type = IO_Type.Null; + private int _line_ID = -1; + public bool Input_bit { + get { return _input_bit; } + set { _input_bit = value; } + } + public int Input_ID { + get { return _input_ID; } + set { _input_ID = value; } } + public IO_Type Input_Type + { + get { return _input_Type; } + set { + switch(value) + { + case (IO_Type.Null): + _input_ID = -1; + _line_ID = -1; + break; + case (IO_Type.Gate): + _input_bit = false; + break; + case (IO_Type.IO): + _line_ID = -1; + _input_bit = false; + break; + } + _input_Type = value; + } + } + public int Line_ID { + get { return _line_ID; } + set { _line_ID = value; } } + + public Input_Class() + { + Input_Type = IO_Type.Null; + } + //delete + public void Output_Status() + { + Console.WriteLine("Input Bit : {0}\nInput ID : {1}\nInput Type : {2}\nLine ID : {3}", Input_bit, Input_ID, Input_Type, Line_ID); + } + } +} diff --git a/CourseWork-master/A level course work Logic Gate/Line_Class.cs b/CourseWork-master/A level course work Logic Gate/Line_Class.cs new file mode 100644 index 0000000..1bd7789 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/Line_Class.cs @@ -0,0 +1,60 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Shapes; + +namespace A_level_course_work_Logic_Gate +{ + public class Line_Class + { + public Line UI_Line { get; set; } = new Line { StrokeThickness = 4, Stroke = Brushes.Red }; + public int Output_ID { get; set; } = -1; + public int Output_Num { get; set; } = 1; //this should only change if the gate type is the multiple output(type 7) + public int Input_ID { get; set; } = -1; + public int Input_Num { get; set; } = -1; + public MainWindow _MainWind { get; set; } + + public Canvas_Class _Sub_Canvas { get; set; } + public Line_Class(int _Output_ID, MainWindow MainWind) + { + _MainWind = MainWind; + _Sub_Canvas = _MainWind.Sub_Canvas; + _Sub_Canvas.Children.Add(UI_Line); + Output_ID = _Output_ID; + } + + public void Track_Mouse() + { + Point Pos = Mouse.GetPosition(_Sub_Canvas); + UI_Line.X2 = Pos.X; + UI_Line.Y2 = Pos.Y; + } + + public void Change_X1_Y1(double X, double Y) + { + UI_Line.X1 = X; + UI_Line.Y1 = Y; + } + public void Change_X2_Y2(double X, double Y) + { + UI_Line.X2 = X; + UI_Line.Y2 = Y; + } + + + //change this so that the values are generic and then just have it so that the X and Y coords are changed directly and don't need the method to do it.(A lot of work :( + public void Link_Input_Aline_Line(Gate_Class Gate) + { + UI_Line.Stroke = Brushes.Black; + double[] hold = _MainWind.Link_Input_Aline(Gate, Input_Num); + Change_X2_Y2(hold[0], hold[1]); + } + + public void Link_Output_Aline_Line(Gate_Class Gate) + { + double[] hold = _MainWind.Link_Output_Aline(Gate, Output_Num); + Change_X1_Y1(hold[0], hold[1]); + } + } +} diff --git a/CourseWork-master/A level course work Logic Gate/MainWindow.xaml b/CourseWork-master/A level course work Logic Gate/MainWindow.xaml new file mode 100644 index 0000000..8b41eb9 --- /dev/null +++ b/CourseWork-master/A level course work Logic Gate/MainWindow.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +