From 35c7a94c782333e6284eca26a901ce1226e78a02 Mon Sep 17 00:00:00 2001 From: chalwa Date: Sat, 7 Dec 2019 10:43:45 +0100 Subject: [PATCH 1/2] xml fixed --- Model/CellularAutomaton.cs | 4 ++-- Model/CurvatureExecutor.cs | 2 +- MsmGrainGrowthGui/ApplicationState.cs | 24 ++++++++++++++++--- .../CelluralAutomatonViewModel.cs | 4 +++- MsmGrainGrowthGui/MainWindow.xaml.cs | 6 ++++- MsmGrainGrowthGui/XmlFactory.cs | 2 ++ MsmGrainGrowthGui/XmlReader.cs | 13 ++++++++-- Test/GrainGrowthGui/XmlFactoryTest.cs | 11 +++++---- Test/GrainGrowthGui/XmlReaderTest.cs | 14 +++++++---- 9 files changed, 61 insertions(+), 19 deletions(-) diff --git a/Model/CellularAutomaton.cs b/Model/CellularAutomaton.cs index 14d3e61..e57cceb 100644 --- a/Model/CellularAutomaton.cs +++ b/Model/CellularAutomaton.cs @@ -54,7 +54,7 @@ public CellularAutomaton( ITransitionRule transition, INeighbourhood neighbourhood, IBoundaryCondition boundary, - int step) + int step, ISimulationExecutor executor) { if (transition == null || neighbourhood == null || @@ -78,7 +78,7 @@ public CellularAutomaton( Space = space; _lastStepSpace = space.Clone(); - _executor = new SimulationExecutor(step); + _executor = executor; } public void NextStep() diff --git a/Model/CurvatureExecutor.cs b/Model/CurvatureExecutor.cs index 73e56bd..e33ff7f 100644 --- a/Model/CurvatureExecutor.cs +++ b/Model/CurvatureExecutor.cs @@ -38,7 +38,7 @@ public void NextState(CelluralSpace space, CelluralSpace lastSpace, ITransitionR { for (int j = 0; j < space.GetYLength(); j++) { - // TODO: refactor + // TODO: refactor, injected arguments are not used !! IBoundaryCondition boun = new AbsorbingBoundary(); INeighbourhood nei = new MooreNeighbourhood(new AbsorbingBoundary()); ITransitionRule rule = new RuleOne(); diff --git a/MsmGrainGrowthGui/ApplicationState.cs b/MsmGrainGrowthGui/ApplicationState.cs index 3072724..bf39e3e 100644 --- a/MsmGrainGrowthGui/ApplicationState.cs +++ b/MsmGrainGrowthGui/ApplicationState.cs @@ -17,6 +17,7 @@ public class ApplicationState public IBoundaryCondition boundary; public bool isAutomatonGenerated; public bool isSaved; + public ISimulationExecutor executor; public ApplicationState( CellularAutomaton automaton, @@ -29,7 +30,8 @@ public ApplicationState( INeighbourhood neighbourhood, IBoundaryCondition boundary, bool isGenerated, - bool isSaved + bool isSaved, + ISimulationExecutor executor ){ this.automaton = automaton; this.spaceSize = spaceSize; @@ -42,7 +44,8 @@ bool isSaved this.boundary = boundary; this.isAutomatonGenerated = isGenerated; this.isSaved = isSaved; - } + this.executor = executor; + } public static IBoundaryCondition GetBoundaryByName(string name) @@ -77,11 +80,26 @@ public static ITransitionRule GetTransitionByName(string name) { switch(name) { - case "Model.GrainGrowthRule": + case "Model.Transition.GrainGrowthRule": return new GrainGrowthRule(); default: throw new ArgumentException(); } } + + public static ISimulationExecutor GetExecutorByName(string name, int step = 0) + { + switch (name) + { + case "Model.SimulationExecutor": + + return new SimulationExecutor(step); + case "Model.CurvatureExecutor": + return new CurvatureExecutor(step); + + default: throw new ArgumentException(); + } + } + } } diff --git a/MsmGrainGrowthGui/CelluralAutomatonViewModel.cs b/MsmGrainGrowthGui/CelluralAutomatonViewModel.cs index 569785e..0c4ec99 100644 --- a/MsmGrainGrowthGui/CelluralAutomatonViewModel.cs +++ b/MsmGrainGrowthGui/CelluralAutomatonViewModel.cs @@ -385,6 +385,7 @@ void OpenExecute() _boundary = state.boundary; IsGenerated = state.isAutomatonGenerated; _isSaved = state.isSaved; + _executor = state.executor; //IsGenerated = true; @@ -434,7 +435,8 @@ void SaveAsExecute() _neighbourhood, _boundary, _isAutomatonGenerated, - _isSaved + _isSaved, + _executor ); var factory = new XmlFactory(); var doc = factory.GetXDocument(state); diff --git a/MsmGrainGrowthGui/MainWindow.xaml.cs b/MsmGrainGrowthGui/MainWindow.xaml.cs index 9de4e1f..fa924e0 100644 --- a/MsmGrainGrowthGui/MainWindow.xaml.cs +++ b/MsmGrainGrowthGui/MainWindow.xaml.cs @@ -1,5 +1,7 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Windows; +using System.Windows.Data; using System.Windows.Media.Imaging; @@ -65,5 +67,7 @@ private void PropertyChangedHandler(object sender, PropertyChangedEventArgs e) } } + + } } diff --git a/MsmGrainGrowthGui/XmlFactory.cs b/MsmGrainGrowthGui/XmlFactory.cs index 20be461..a252348 100644 --- a/MsmGrainGrowthGui/XmlFactory.cs +++ b/MsmGrainGrowthGui/XmlFactory.cs @@ -35,6 +35,8 @@ private static void AddVariables(ApplicationState state, XDocument doc) widowVariables.Add(new XAttribute("Boundary", state.boundary.GetType())); widowVariables.Add(new XAttribute("IsGenerated", state.isAutomatonGenerated)); widowVariables.Add(new XAttribute("IsSaved", state.isSaved)); + widowVariables.Add(new XAttribute("Step", state.automaton.Step)); + widowVariables.Add(new XAttribute("Executor", state.executor.GetType())); doc.Root.Add(widowVariables); } diff --git a/MsmGrainGrowthGui/XmlReader.cs b/MsmGrainGrowthGui/XmlReader.cs index b686634..f513eaa 100644 --- a/MsmGrainGrowthGui/XmlReader.cs +++ b/MsmGrainGrowthGui/XmlReader.cs @@ -6,6 +6,7 @@ using System.Xml.Linq; using Model; using System.Drawing; +using MsmGrainGrowthGui; namespace GrainGrowthGui { @@ -25,6 +26,7 @@ public class XmlReader private List _grains; private List _inclusions; private int _step; // TODO: Add step + private ISimulationExecutor _executor; public ApplicationState Read(XDocument doc) @@ -92,7 +94,8 @@ public ApplicationState Read(XDocument doc) _transition, _neighbourhood, _boundary, - _step + _step, + _executor ); @@ -108,7 +111,8 @@ public ApplicationState Read(XDocument doc) _neighbourhood, _boundary, _isAutomatonGenerated, - _isSaved + _isSaved, + _executor ); } @@ -180,6 +184,11 @@ private void ReadWindowVariables(XDocument doc) _isSaved = GetValueFromElement(doc, "IsSaved") == "true" ? true : false; _isAutomatonGenerated = GetValueFromElement(doc, "IsGenerated") == "true" ? true : false; + + _step = Convert.ToInt32(GetValueFromElement(doc, "Step")); + + string executorName = (GetValueFromElement(doc, "Executor")); + _executor = ApplicationState.GetExecutorByName(executorName, _step); } catch (Exception e) { diff --git a/Test/GrainGrowthGui/XmlFactoryTest.cs b/Test/GrainGrowthGui/XmlFactoryTest.cs index 42e3200..382fe72 100644 --- a/Test/GrainGrowthGui/XmlFactoryTest.cs +++ b/Test/GrainGrowthGui/XmlFactoryTest.cs @@ -17,9 +17,9 @@ public class XmlFactoryTest public void BasicTest() { #region expectedXml - string expected = + string expected = @" - + @@ -61,6 +61,7 @@ public void BasicTest() ITransitionRule transition = new GrainGrowthRule(); IBoundaryCondition boundary = new AbsorbingBoundary(); INeighbourhood neighbourhood = new VonNeumanNeighbourhood(boundary); + ISimulationExecutor executor = new SimulationExecutor(); var grains = new List(); grains.Add(new Grain(0, 0, Color.FromArgb(1,2,3,4))); @@ -90,7 +91,8 @@ public void BasicTest() transition, neighbourhood, boundary, - step + step, + executor ); var state = new ApplicationState( @@ -104,7 +106,8 @@ public void BasicTest() neighbourhood, boundary, isGenerated, - isSaved + isSaved, + executor ); var document = factory.GetXDocument(state); diff --git a/Test/GrainGrowthGui/XmlReaderTest.cs b/Test/GrainGrowthGui/XmlReaderTest.cs index 8a97615..98c60f3 100644 --- a/Test/GrainGrowthGui/XmlReaderTest.cs +++ b/Test/GrainGrowthGui/XmlReaderTest.cs @@ -32,7 +32,8 @@ public void BasicTest() Assert.Equal(expected.maxRadius, result.maxRadius); Assert.Equal(expected.minRadius, result.minRadius); Assert.Equal(expected.spaceSize, result.spaceSize); - + Assert.Equal(expected.executor.GetType(), result.executor.GetType()); + int i = 0; foreach(var grain in expected.automaton.Grains) { @@ -96,6 +97,7 @@ private ApplicationState BuildMockState() ITransitionRule transition = new GrainGrowthRule(); IBoundaryCondition boundary = new AbsorbingBoundary(); INeighbourhood neighbourhood = new VonNeumanNeighbourhood(boundary); + ISimulationExecutor executor = new SimulationExecutor(); var grains = new List(); grains.Add(new Grain(0, 0, Color.FromArgb(1,2,3,4))); @@ -125,7 +127,8 @@ private ApplicationState BuildMockState() transition, neighbourhood, boundary, - step + step, + executor ); return new ApplicationState( @@ -139,15 +142,16 @@ private ApplicationState BuildMockState() neighbourhood, boundary, isGenerated, - isSaved + isSaved, + executor ); } private XDocument BuildMockInput() { - string xmlState = + string xmlState = @" - + From 77d7af8e80d67e7bcc5d364b8652c300df5bdcd8 Mon Sep 17 00:00:00 2001 From: chalwa Date: Sat, 7 Dec 2019 10:53:35 +0100 Subject: [PATCH 2/2] Icons removed --- MsmGrainGrowthGui/GrainGrowthGui.csproj | 14 -------- MsmGrainGrowthGui/MainWindow.xaml | 4 --- .../Properties/Resources.Designer.cs | 34 +++++++----------- MsmGrainGrowthGui/Properties/Resources.resx | 4 --- MsmGrainGrowthGui/icons/diskette.png | Bin 466 -> 0 bytes MsmGrainGrowthGui/icons/excel.png | Bin 510 -> 0 bytes MsmGrainGrowthGui/icons/folder.png | Bin 473 -> 0 bytes MsmGrainGrowthGui/icons/picture.png | Bin 528 -> 0 bytes 8 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 MsmGrainGrowthGui/icons/diskette.png delete mode 100644 MsmGrainGrowthGui/icons/excel.png delete mode 100644 MsmGrainGrowthGui/icons/folder.png delete mode 100644 MsmGrainGrowthGui/icons/picture.png diff --git a/MsmGrainGrowthGui/GrainGrowthGui.csproj b/MsmGrainGrowthGui/GrainGrowthGui.csproj index 8d223a3..682ceb5 100644 --- a/MsmGrainGrowthGui/GrainGrowthGui.csproj +++ b/MsmGrainGrowthGui/GrainGrowthGui.csproj @@ -6,25 +6,11 @@ true - - - - - - - - - - - - - - True diff --git a/MsmGrainGrowthGui/MainWindow.xaml b/MsmGrainGrowthGui/MainWindow.xaml index c4d0f45..a002cf7 100644 --- a/MsmGrainGrowthGui/MainWindow.xaml +++ b/MsmGrainGrowthGui/MainWindow.xaml @@ -18,13 +18,11 @@ @@ -32,13 +30,11 @@ diff --git a/MsmGrainGrowthGui/Properties/Resources.Designer.cs b/MsmGrainGrowthGui/Properties/Resources.Designer.cs index 30ffe02..191e94c 100644 --- a/MsmGrainGrowthGui/Properties/Resources.Designer.cs +++ b/MsmGrainGrowthGui/Properties/Resources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// Ten kod został wygenerowany przez narzędzie. -// Wersja wykonawcza:4.0.30319.42000 +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // -// Zmiany w tym pliku mogą spowodować nieprawidłowe zachowanie i zostaną utracone, jeśli -// kod zostanie ponownie wygenerowany. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -13,12 +13,12 @@ namespace GrainGrowthGui.Properties { /// - /// Klasa zasobu wymagająca zdefiniowania typu do wyszukiwania zlokalizowanych ciągów itd. + /// A strongly-typed resource class, for looking up localized strings, etc. /// - // Ta klasa została automatycznie wygenerowana za pomocą klasy StronglyTypedResourceBuilder - // przez narzędzie, takie jak ResGen lub Visual Studio. - // Aby dodać lub usunąć składową, edytuj plik ResX, a następnie ponownie uruchom narzędzie ResGen - // z opcją /str lub ponownie utwórz projekt VS. + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -33,7 +33,7 @@ internal Resources() { } /// - /// Zwraca buforowane wystąpienie ResourceManager używane przez tę klasę. + /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ internal Resources() { } /// - /// Przesłania właściwość CurrentUICulture bieżącego wątku dla wszystkich - /// przypadków przeszukiwania zasobów za pomocą tej klasy zasobów wymagającej zdefiniowania typu. + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { @@ -59,15 +59,5 @@ internal Resources() { resourceCulture = value; } } - - /// - /// Wyszukuje zlokalizowany zasób typu System.Byte[]. - /// - internal static byte[] diskette { - get { - object obj = ResourceManager.GetObject("diskette", resourceCulture); - return ((byte[])(obj)); - } - } } } diff --git a/MsmGrainGrowthGui/Properties/Resources.resx b/MsmGrainGrowthGui/Properties/Resources.resx index 187501d..1af7de1 100644 --- a/MsmGrainGrowthGui/Properties/Resources.resx +++ b/MsmGrainGrowthGui/Properties/Resources.resx @@ -117,8 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ..\icons\diskette.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - \ No newline at end of file diff --git a/MsmGrainGrowthGui/icons/diskette.png b/MsmGrainGrowthGui/icons/diskette.png deleted file mode 100644 index c1d7ae94c53e8c5865163c383b2e42879d560e64..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 466 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1OBOz`%C|gc+x5^GO2**-JcqUD+RVbBk#U^zU>J1_~|kba4#PIDht{E!QCjfwqV0 z{~DGm+&jQs!C1{Leb8FM+FvQ`+cZI*B*n6M9y-d78$FUdL~?3p&y?L)D_O?OUT#np ze5tg|^t;L_cURf27A2ot)96<`Z_XT$n|;h(VdIo1f8*AheED3xM&Q}s#U?sh^S)~u z>+~*}dcf!Q(Ooy}zV%83rg<1%T)C#|%p6|(AMFl5Cmny^=%BNdErHKHUXu_V>t*I;7bhncr0V4trO$q6BLyoc5!lIL8@MUQTpt6Hc~)E44$rjF6*2U FngAKGuOR>c diff --git a/MsmGrainGrowthGui/icons/folder.png b/MsmGrainGrowthGui/icons/folder.png deleted file mode 100644 index 4659b32feda652b67dcec65418ef4ba3a1942cf5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 473 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1OBOz`%C|gc+x5^GO2**-JcqUD+RV^YEJsaXz@60u);A>EaloaenUwTR)~m3D<|| zF3TNr)^>JEdPgyrl-=0GVC6mC!T8DIV&0HFVtI{CI~c5mVmmn(&TN@~QPcA3*|VB? zd2Qj&`(MRGRz5y9eZ!Ye?VlKn`!h6qvz#VyCSTaLVXLjsJ6?|em#6EQY`m5$R>1b~ zlfv_5?^5>No%QDRlK7=F(?2{}p2a34>&fBz^@PihFA6P7ii>jQUUPi6b6cj=9PPc@ zeWzu)0_9vn4tak7I$5>EHKHUXu_VKYn_7@As{npzoJXd4(< z85s0+8Lvjskei>9nO2Eg!~g5u;y?|OARB`7(@M${i&7cN%ggmL^RkPR6AM!H@{7`E Tzq647Dq`?-^>bP0l+XkK)b*cW diff --git a/MsmGrainGrowthGui/icons/picture.png b/MsmGrainGrowthGui/icons/picture.png deleted file mode 100644 index 8e08b0248483da2e9416b662e4d1fc30c0179dbd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 528 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1OBOz`%C|gc+x5^GO2**-JcqUD+RV^YB}k#FRRP0fp{)x;TbtoNv9T@9kVDa_nRO z=ceYw@=XsSghW^cd79WJFL0cpf57OSw8R# zyvO%~06*KSRr^BERI%%BTyLQC{-AK(o$qe*v{(-<+Wsz*Erh4>hiK%c6XxJHzuB$lLFB^RXvDF!10LrYylLtR6o5JOWdQ!^`5 zBW(i%D+2@9_M0*&8glbfGSez?YcRQ$xB#d@5@bVgep*R+Vo@qXd3m{BW?pu2a$-TM XUVc&f>~}U&Kt&9mu6{1-oD!M<@E5ab