public static StormType2 Export_GetStormType(string NodeType) { RealStormType RST = ATCFHelperMethods.Export_IdentifyRealType(NodeType); #if PRISCILLA MainWindow MnWindow = (MainWindow)Application.Current.MainWindow; StormTypeManager STM = MnWindow.ST2Manager; #else StormTypeManager STM = MnWindow.GetST2Manager(); #endif StormType2 ST2 = STM.GetStormTypeWithRealStormTypeName(RST); return(ST2); }
private void Init_InitGlobalState() { // doesn't init globalstate rn // Initialise the category manager. Logging.Log("Initialising category manager..."); GlobalState.CategoryManager = new CategoryManager(); Logging.Log("Loading categories..."); GlobalState.CategoryManager.InitCategories(); // Initialise the storm type manager. Logging.Log("Initialising storm type manager..."); ST2Manager = new StormTypeManager(); ST2Manager.Init(); Logging.Log("Initialising DynaHotkey manager..."); // Initialise the DynaHotkey manager. (MAINWINDOW ONLY) DHotkeyManager = new DynaHotkeyManager(); Logging.Log("Setting current category system..."); Init_SetCurrentCategorySystem(); Logging.Log("Setting up DynaHotkey hotkeys from current category system..."); Init_InitGlobalState_SetUpDynaHotkey(); }
private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e) { Storm Sto = CurrentProject.SelectedBasin.GetCurrentStorm(); if (Sto != null) { if (Sto.LastNode != null) { Node LastNode = Sto.LastNode; RelativePositionConverter RPC = new RelativePositionConverter(); RelativePosition RP = (RelativePosition)RPC.Convert(e.GetPosition(HurricaneBasin), typeof(RelativePosition), null, null); LastNode.Position = RP; Sto.AddNode(LastNode); LastNode = null; } } else { // left mouse button clicked (no zoom) if (e.LeftButton == MouseButtonState.Pressed) { Project CurProj = CurrentProject; // fix retardation if (CurProj != null && CurProj.SelectedBasin != null && CurProj.SelectedBasin.CurrentLayer != null) { // if we have no storms, ask the user to create a storm instead of add a track point. if (Sto == null) { AddNewStormHost Addstwindow = new AddNewStormHost(CurProj.SelectedBasin.SeasonStartTime); Addstwindow.Owner = this; Addstwindow.Show(); return; } else { // build 524 #if PRISCILLA StormTypeManager ST2M = ST2Manager; #else StormTypeManager ST2Manager = GlobalState.GetST2Manager(); #endif Storm SelectedStorm = CurProj.SelectedBasin.GetCurrentStorm(); int NodeCount = SelectedStorm.NodeList.Count - 1; // build 547: implement season start time on window feature AddTrackPointHost ATPHost = new AddTrackPointHost(ST2M.GetListOfStormTypeNames(), e.GetPosition(HurricaneBasin), SelectedStorm.GetNodeDate(NodeCount)); ATPHost.Owner = this; ATPHost.Show(); } } } else if (e.RightButton == MouseButtonState.Pressed) { // temporary code // this should be a matrix transformation but /shrug // not best practice LastRightMouseClickPos = e.GetPosition(HurricaneBasin); } } }
private protected NodeImportResult ImportNodes(XmlNode XNN) { NodeImportResult NIR = new NodeImportResult(); // get globalstate structures in Dano, use MainWindow for Priscilla #if DANO StormTypeManager ST2Manager = GlobalState.GetST2Manager(); #else MainWindow MnWindow = (MainWindow)Application.Current.MainWindow; StormTypeManager ST2Manager = MnWindow.ST2Manager; #endif if (!XNN.HasChildNodes) { NIR.Successful = true; NIR.Empty = true; return(NIR); } else { foreach (XmlNode XNNChild in XNN.ChildNodes) { Node NewNode = new Node(); if (!XNNChild.HasChildNodes) { Error.Throw("Error!", "Empty node detected!", ErrorSeverity.Error, 222); } else { foreach (XmlNode NodeInformationNode in XNNChild.ChildNodes) { switch (NodeInformationNode.Name) { case "Intensity": NewNode.Intensity = Convert.ToInt32(NodeInformationNode.InnerText); continue; case "Position": Point Npos = NodeInformationNode.InnerText.SplitXY(); RelativePositionConverter RPC = new RelativePositionConverter(); RelativePosition RP = (RelativePosition)RPC.Convert(Npos, typeof(RelativePosition), null, null); NewNode.Position = RP; continue; case "Type": NewNode.NodeType = ST2Manager.GetStormTypeWithName(NodeInformationNode.InnerText); continue; } } } NIR.Nodes.Add(NewNode); } NIR.Successful = true; NIR.Empty = false; return(NIR); } }
public ImportResult Import() { try { ImportResult IR = new ImportResult(); System.Windows.Forms.FolderBrowserDialog OFD = new System.Windows.Forms.FolderBrowserDialog() { Description = $"Open {GetName()} format folder", }; #if DANO StormTypeManager ST2Manager = GlobalState.GetST2Manager(); #else MainWindow MnWindow = (MainWindow)Application.Current.MainWindow; StormTypeManager ST2Manager = MnWindow.ST2Manager; #endif if (OFD.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (OFD.SelectedPath == "") { return(null); } // check the directory if (!ATCFHelperMethods.Export_CheckDirectoryValidForImport(OFD.SelectedPath)) { IR.Status = ExportResults.Error; return(IR); } Project Proj = ImportCore(ST2Manager, OFD.SelectedPath); if (Proj == null) { IR.Status = ExportResults.Error; return(IR); } else { IR.Project = Proj; IR.Status = ExportResults.OK; return(IR); } } else { //temp IR.Status = ExportResults.Cancelled; return(IR); } } catch (DirectoryNotFoundException) { Error.Throw("Fatal Error", "Attempted to import a nonexistent ATCF DatFolder", ErrorSeverity.Error, 241); return(null); } catch (PathTooLongException) { Error.Throw("Error", "The path to the file is longer than 260 characters. Please shorten it.", ErrorSeverity.Error, 150); return(null); } catch (FormatException) { Error.Throw("Error", "Attempted to import a node with invalid pressure or intensity!", ErrorSeverity.Error, 401); return(null); } catch (OverflowException) { Error.Throw("Error", "Attempted to import a node with invalid pressure or intensity!", ErrorSeverity.Error, 402); return(null); } }
// pre-globalstate...refactor this in Dano to not have that passed to it // this code is terrible public Project ImportCore(StormTypeManager ST2M, string FolderName) { // this is one of the worst f*****g file formats I have ever laid my f*****g eyes on, NOAA are a bunch of f*****g wanker twats, nobody should use this pile of crap string[] Storms = Directory.GetFiles(FolderName); // this is terrible design Project Proj = new Project(); Proj.FileName = $"{FolderName}/*.*"; Basin Bas = new Basin(); // this is still a mess for now // not foreach as we can use it for setting up the basin for (int i = 0; i < Storms.Count(); i++) { string StormFileName = Storms[i]; string[] ATCFLines = File.ReadAllLines(StormFileName); // holy f*****g shit i hate the ATCF format so f*****g muc Layer Lyr = new Layer(); Storm Sto = new Storm(); StormType2 StormType = new StormType2(); DateTime StormFormationDT = new DateTime(1959, 3, 10); // XML OR JSON OR F*****G ANYTHING PLS // not foreach because it makes it slightly easier to set the date for (int j = 0; j < ATCFLines.Length; j++) { string ATCFLine = ATCFLines[j]; string[] Components = ATCFLine.Split(','); string _StrAbbreviation = Components[0]; // get the stuff we actually need string _StrId = Components[1]; string _StrTime = Components[2]; string _StrTimeSinceFormation = Components[3]; string _StrCoordX = Components[6]; string _StrCoordY = Components[7]; string _StrIntensity = Components[8]; string _StrPressure = Components[9]; string _StrCategory = Components[10]; string _StrName = Components[28]; // bleh // trim it _StrAbbreviation = _StrAbbreviation.Trim(); _StrId = _StrId.Trim(); _StrTime = _StrTime.Trim(); _StrTimeSinceFormation = _StrTimeSinceFormation.Trim(); _StrPressure = _StrPressure.Trim(); _StrCoordX = _StrCoordX.Trim(); _StrCoordY = _StrCoordY.Trim(); _StrIntensity = _StrIntensity.Trim(); _StrCategory = _StrCategory.Trim(); _StrName = _StrName.Trim(); // initialise the basin with the abbreviation loaded from XML // we just use the name if there is no abbreviation specified in XML int Intensity = 0; // first iteration... if (j == 0) { if (i == 0) { Bas = Proj.GetBasinWithAbbreviation(_StrAbbreviation); if (Bas.CoordsHigher == null || Bas.CoordsLower == null) { Error.Throw("Error!", "This basin is not supported by the ATCF format as it does not have defined borders in Basins.xml.", ErrorSeverity.Error, 249); return(null); } } Lyr.Name = _StrName; } Intensity = Convert.ToInt32(_StrIntensity); Sto.FormationDate = ParsingUtil.ParseATCFDateTime(_StrTime, CoordinateFormat.ATCF); if (_StrName == null) { Error.Throw("Error!", "Attempted to load storm with an invalid name!", ErrorSeverity.Error, 245); return(null); } else { Sto.Name = _StrName; } int Id = Convert.ToInt32(_StrId); Coordinate Coord = Coordinate.FromSplitCoordinate(_StrCoordX, _StrCoordY); // create a node and add it Node Nod = new Node(); Nod.Id = Id; Nod.Intensity = Intensity; Nod.Position = Bas.FromCoordinateToRelativeNodePosition(Coord, new Point(MnWindow.Width, MnWindow.Height)); Nod.NodeType = ATCFHelperMethods.Export_GetStormType(_StrCategory); Nod.Pressure = Convert.ToInt32(_StrPressure); Sto.AddNode(Nod); } Lyr.AddStorm(Sto); Bas.AddLayer(Lyr); } Proj.AddBasin(Bas); return(Proj); }