void OpenProject(string filename) { if (!stopped) { Stop(); } NBTag taskData = NBTag.ReadFile(filename); State = new TaskState(taskData); BackColor = State.ProjectOptions.BackColor; if (filename.EndsWith(".autosave.sie")) { State.ProjectFileName = filename.Substring(0, filename.Length - 13); } else { State.ProjectFileName = filename; } Text = Path.GetFileName(State.ProjectFileName) + " | SuperImageEvolver"; nVertices.Value = State.Vertices; nPolygons.Value = State.Shapes; SetImage(State.OriginalImage); if (taskData.Contains("Presentation")) { NBTag presentationTag = taskData["Presentation"]; picOriginal.Visible = presentationTag.GetBool("OriginalVisible", picOriginal.Visible); OriginalZoom = presentationTag.GetFloat("OriginalZoom", OriginalZoom); picBestMatch.Visible = presentationTag.GetBool("BestMatchVisible", picBestMatch.Visible); picBestMatch.Zoom = presentationTag.GetFloat("BestMatchZoom", picBestMatch.Zoom); picBestMatch.Wireframe = presentationTag.GetBool("BestMatchWireframe", picBestMatch.Wireframe); picBestMatch.ShowLastChange = presentationTag.GetBool("BestMatchShowLastChange", picBestMatch.ShowLastChange); picDiff.Visible = presentationTag.GetBool("DiffVisible", picDiff.Visible); picDiff.Invert = presentationTag.GetBool("DiffInvert", picDiff.Invert); picDiff.Exaggerate = presentationTag.GetBool("DiffExaggerate", picDiff.Exaggerate); picDiff.ShowColor = presentationTag.GetBool("DiffShowColor", picDiff.ShowColor); picDiff.Zoom = presentationTag.GetFloat("DiffZoom", picDiff.Zoom); picDiff.ShowLastChange = presentationTag.GetBool("DiffShowLastChange", picDiff.ShowLastChange); } State.SetEvaluator(State.Evaluator); UpdateTick(); picDiff.Invalidate(); picBestMatch.Invalidate(); State.HasChangedSinceSave = false; bStart.Enabled = true; bRestart.Enabled = true; bSaveProject.Enabled = true; bSaveProjectAs.Enabled = true; menuExport.Enabled = true; }
public static void ReadModuleProperties(IModule module, NBTag tag) { IModuleFactory factory = GetFactoryByType(module.GetType()); foreach (PropertyInfo p in factory.ModuleType.GetProperties()) { if (!tag.Contains(p.Name)) { continue; } if (p.PropertyType == typeof(byte)) { p.SetValue(module, tag.GetByte(), null); } else if (p.PropertyType == typeof(short)) { p.SetValue(module, tag.GetShort(), null); } else if (p.PropertyType == typeof(int)) { p.SetValue(module, tag.GetInt(), null); } else if (p.PropertyType == typeof(long)) { p.SetValue(module, tag.GetLong(), null); } else if (p.PropertyType == typeof(float)) { p.SetValue(module, tag.GetFloat(), null); } else if (p.PropertyType == typeof(double)) { p.SetValue(module, tag.GetDouble(), null); } else if (p.PropertyType == typeof(byte[])) { p.SetValue(module, tag.GetBytes(), null); } else if (p.PropertyType == typeof(string)) { p.SetValue(module, tag.GetString(), null); } else if (p.PropertyType == typeof(bool)) { p.SetValue(module, tag.GetBool(), null); } else if (p.PropertyType == typeof(Color)) { p.SetValue(module, tag.GetColor(), null); } else if (p.PropertyType == typeof(Point)) { p.SetValue(module, tag.GetBool(), null); } else if (p.PropertyType == typeof(PointF)) { p.SetValue(module, tag.GetPointF(), null); } else { throw new NotSupportedException("Unknown property type."); } } }