public void InitBasin(Basin Bs, bool SelectNow = false) { #if DANO // ATTN: You can write anything you want if it's not covered by the currently defined ifdefs Bs.SeasonHemisphere = Hemisphere; Bs.SeasonType = Type; #endif // load function goes here // Create a background layer Layer BgLayer = new Layer(); BgLayer.Name = "Background"; if (SelectNow) { Bs.IsOpen = true; Bs.IsSelected = true; } Bs.Layers.Add(BgLayer); Bs.SelectLayerWithName(BgLayer.Name); #if PRISCILLA MainWindow MnWindow = (MainWindow)Application.Current.MainWindow; #endif OpenBasins.Add(Bs); SelectedBasin = Bs; }
/// <summary> /// Initialise a basin after project initialisation /// </summary> /// <param name="Bs"></param> private void InitBasin(Basin Bs) { #if DANO // ATTN: You can write anything you want if it's not covered by the currently defined ifdefs Bs.SeasonHemisphere = Hemisphere; Bs.SeasonType = Type; #endif // load function goes here // Create a background layer Layer BgLayer = new Layer(); BgLayer.Name = "Background"; Bs.Layers.Add(BgLayer); Bs.SelectLayerWithName(BgLayer.Name); OpenBasins.Add(Bs); SelectedBasin = Bs; }
/// <summary> /// 2020-11-27 /// /// Iris: replace with deserialisation /// </summary> public static void LoadBasins() { try { InitBasinList(); XmlDocument XmlDocument = new XmlDocument(); XmlDocument.Load(@"Data\Basins.xml"); // maybe change? XmlNode XmlRootNode = XmlDocument.FirstChild; while (XmlRootNode.Name != "Basins") { if (XmlRootNode.NextSibling == null) { Error.Throw("Fatal Error!", "Basins.xml is corrupted or malformed. The Track Maker will now exit.", ErrorSeverity.FatalError, 1); } XmlRootNode = XmlRootNode.NextSibling; //figure out what happens if the basin node doesn't exist. } XmlNodeList XmlNodes = XmlRootNode.ChildNodes; //abduct the kids of the basins node foreach (XmlNode XmlNode in XmlNodes) { Basin Basin = new Basin(); // create a new basin. if (XmlNode.Name.Contains('#')) { continue; } if (XmlNode.Name != "Basin") { // change this? Error.Throw("Fatal Error!", "Attempted to load non-basin node, discarding basin!", ErrorSeverity.Error, 2); return; } XmlAttributeCollection XmlAttributes = XmlNode.Attributes; foreach (XmlAttribute XmlAttribute in XmlAttributes) { switch (XmlAttribute.Name) // go through all the attributes { case "Abbreviation": case "Acronym": case "BasinCode": Basin.Abbreviation = XmlAttribute.Value; continue; case "bgimage": // basin image path case "Bgimage": case "bgImage": case "BgImage": Basin.ImagePath = XmlAttribute.Value; //set the basin image path to the value continue; // yeah case "coordstopleft": case "Coordstopleft": case "coordsTopleft": case "coordsTopLeft": case "CoordsTopLeft": // Conversion Basin.CoordsLower = Coordinate.FromString(XmlAttribute.InnerText, CoordinateFormat.TrackMaker); continue; case "coordsbottomright": case "Coordsbottomright": case "CoordsBottomright": case "coordsBottomRight": case "CoordsBottomRight": // Conversion Basin.CoordsHigher = Coordinate.FromString(XmlAttribute.InnerText, CoordinateFormat.TrackMaker); continue; case "name": // basin name case "Name": Basin.Name = XmlAttribute.Value; continue; } } if (Basin.Name == null) { Error.Throw("Fatal Error!", "Fatal Error: Cannot load basin with no name!", ErrorSeverity.FatalError, 240); } if (Basin.Abbreviation == null) { Basin.Abbreviation = "NA"; } Debug.Assert(Basin.Name != null && Basin.Abbreviation != null); Logging.Log($"Successfully loaded basin {Basin.Name} with image {Basin.ImagePath}"); OpenBasins.Add(Basin); } } catch (XmlException err) { //todo create fatalerror method #if DEBUG Error.Throw("Fatal Error!", $"Basins.xml is corrupt or invalid!\n\n{err}", ErrorSeverity.FatalError, 203); #else Error.Throw("Fatal Error!", "Basins.xml is corrupt or invalid!", ErrorSeverity.FatalError, 203); #endif Environment.Exit(203); } }