Пример #1
0
        public void OKHit(object sender, DanoEventArgs DEA)
        {
            Debug.Assert(DEA.DanoParameters.Count == 4);

#if DANO
            Basin CBasin = GlobalState.GetCurrentBasin(); // only valid when project valid
            Storm Sto = CBasin.GetCurrentStorm();
#else
            MainWindow MnWindow = (MainWindow)Application.Current.MainWindow;
            Storm Sto = MnWindow.CurrentProject.SelectedBasin.GetCurrentStorm();

            try
            {
                int Intensity = (int)DEA.DanoParameters[0];
                string Type = (string)DEA.DanoParameters[1];
                Point Position = (Point)DEA.DanoParameters[2];
                int Pressure = (int)DEA.DanoParameters[3];

                Sto.AddNode(Intensity, Type, Position, Pressure, MnWindow.ST2Manager);
                Close();
            }
            catch (InvalidCastException err)
            {
#if DEBUG
                Error.Throw("Warning!", $"Internal error: Cannot convert DanoParameters to their actual types.\n\n{err}", ErrorSeverity.Warning, 403);
#else
                Error.Throw("Warning!", "Internal error: Cannot convert DanoParameters to their actual types.\n\n{err}", ErrorSeverity.Warning, 403); 
#endif
#endif
            }

        }
Пример #2
0
        public ImportResult ImportCore(string SelectedPath)
        {
            ImportResult IR = new ImportResult();

            Project Proj = new Project();

            Proj.FileName = $@"{SelectedPath}\*.*";

            if (!ATCFHelperMethods.Export_CheckDirectoryValidForImport(SelectedPath, CoordinateFormat.HURDAT2))
            {
                IR.Status = ExportResults.Error;
                return(IR);
            }
            else
            {
                List <string> FileList = Directory.EnumerateFiles(SelectedPath).ToList();

                Basin Bas = new Basin();

                for (int i = 0; i < FileList.Count; i++)
                {
                    string FileName = FileList[i];

                    List <string> Hurdat2Strings = File.ReadAllLines(FileName).ToList();

                    Storm Sto = new Storm();

                    for (int j = 0; j < Hurdat2Strings.Count(); j++)
                    {
                        string HD2String = Hurdat2Strings[j];

                        Node CN = new Node();

                        // non-header
                        if (j != 0)
                        {
                            List <string> Components = HD2String.Split(',').ToList();

                            // HURDAT2 Format components
                            // 20151020, 0600,  , TD, 13.4N,  94.0W,  25, 1007,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
                            // 0 = date (YYYYMMDD)
                            // 1 = time (YYYYMMDD) ignore this until iris when we will explictly store node dates
                            // 2 = reserved, unused
                            // 3 = category
                            // 4 = latitude
                            // 5 = longitude
                            // 6 = wind speed
                            // 7 = pressure
                            // rest are wind radii 34/50/64kt
                            // Currently we only care about 0, 1, 3, 4, 5, and 6

                            string _Date      = Components[0];
                            string _Time      = Components[1];
                            string _Category  = Components[4];
                            string _Latitude  = Components[5];
                            string _Longitude = Components[6];
                            string _WindSpeed = Components[7];
                            string _Pressure  = Components[8];

                            // Trim everything.
                            _Date      = _Date.Trim();
                            _Time      = _Time.Trim();
                            _Category  = _Category.Trim();
                            _Latitude  = _Latitude.Trim();
                            _Longitude = _Longitude.Trim();
                            _WindSpeed = _WindSpeed.Trim();
                            _Pressure  = _Pressure.Trim();

                            // first real information
                            if (j == 1)
                            {
                                string DateString = $"{_Date}, {_Time}";
                                Sto.FormationDate = ParsingUtil.ParseATCFDateTime(DateString, CoordinateFormat.HURDAT2);
                            }

                            CN.Id = j;
                            RealStormType RST = ATCFHelperMethods.Export_IdentifyRealType(_Category);

                            CN.Intensity = Convert.ToInt32(_WindSpeed);
                            CN.NodeType  = ATCFHelperMethods.Export_GetStormType(_Category);

                            if (CN.NodeType == null)
                            {
                                Error.Throw("Error!", "Invalid or unknown stormtype detected!", ErrorSeverity.Error, 322);
                                IR.Status = ExportResults.Error;
                                return(IR);
                            }

                            Coordinate Coordinate = Coordinate.FromSplitCoordinate(_Longitude, _Latitude, CoordinateFormat.HURDAT2);

                            // TEMP: MOVE WINDOW SIZE TO TRACKMAKER.CORE VOLATILESETTINGS CLASS

                            MainWindow MnWindow = (MainWindow)Application.Current.MainWindow;

                            CN.Position = Bas.FromCoordinateToRelativeNodePosition(Coordinate, new Point(MnWindow.Width, MnWindow.Height));

                            CN.Pressure = Convert.ToInt32(_Pressure);
                            Sto.AddNode(CN);
                        }
                        // this can and will be refactored
                        else
                        {
                            // HURDAT2 Format Header
                            string HD2Header = HD2String;

                            List <string> HD2HeaderComponents = HD2Header.Split(',').ToList();

                            string HD2ID            = HD2HeaderComponents[0];
                            string HD2Name          = HD2HeaderComponents[1];
                            string HD2AdvisoryCount = HD2HeaderComponents[2]; // we don't use this

                            if (HD2ID.Length != 8)
                            {
                                Error.Throw("Error!", "Invalid ID field in HURDAT2 storm header.", ErrorSeverity.Error, 323);
                                IR.Status = ExportResults.Error;
                                return(IR);
                            }

                            string BasinAbbreviation = HD2ID.Substring(0, 2);

                            // set up the basin if this is the first node of the first file

                            if (i == 0)
                            {
                                Bas = Proj.GetBasinWithAbbreviation(BasinAbbreviation);

                                if (Bas.CoordsLower == null || Bas.CoordsHigher == null)
                                {
                                    Error.Throw("Error!", "This basin is not supported by the HURDAT2 format as it does not have defined boundaries in Basins.xml.", ErrorSeverity.Error, 326);
                                    IR.Status = ExportResults.Error;
                                    return(IR);
                                }

                                // sets up a background layer for us so we do not need to create one manually
                                Proj.InitBasin(Bas);
                            }

                            Sto.Name = HD2Name;
                            continue;
                        }

                        Sto.AddNode(CN);

                        // set up the storm if this is the first node of any file (TERRIBLE SHIT NO GOOD)
                    }

                    Bas.AddStorm(Sto);
                }

                Proj.AddBasin(Bas);
            }

            IR.Project = Proj;
            IR.Status  = ExportResults.OK;
            return(IR);
        }
Пример #3
0
        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);
                }
            }
        }
Пример #4
0
        // 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);
        }