Exemple #1
0
 private void Init_InitProject()
 {
     // Phase 2 Init
     CurrentProject = new Project();
     // temp dumb hack
     CurrentProject.AddBasin("Atlantic");
     //ImagePath = CurrentProject.SelectedBasin.ImagePath;
 }
        // Event Handler for    Dano UI BasinSwitcher UserControl Closed event

        public void UC_Closed(object sender, DanoEventArgs e)
        {
            string  NewBasinName = (string)e.DanoParameters[0];
            Project Proj         = MnWindow.CurrentProject;

            // v650b: i just copied this to amke this work so lol
            // Create the basins

            // clean the UI (VERY TEMP; only use for beta - v605)
            MnWindow.Layers.ClearLayers();

            Basin NewBasin = Proj.GetBasinWithName(NewBasinName);

            Proj.AddBasin(NewBasinName, true);

            // set the UI-side image path.
            MnWindow.ImagePath = NewBasin.ImagePath;

            MnWindow.CurrentProject = Proj;

            UpdateLayout();
            Close();
        }
Exemple #3
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);
        }
Exemple #4
0
        /// <summary>
        /// Imports from Tproj2.
        ///
        /// This is a disaster and terrible. It shall soon be rewritten using the "magic" of XML schemas and serialisation...
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        public XMLImportResult__DEPRECATED ImportCore(string FileName)
        {
            XMLImportResult__DEPRECATED XER = new XMLImportResult__DEPRECATED();

            XER.Successful = false;

            XmlDocument XD = new XmlDocument();

            XD.Load(FileName);

            XmlNode XDR = XD.FirstChild;

            Project Proj = new Project();

            Proj.FileName = FileName;

            Logging.Log("ALERT: Running complete disaster known as TProjv2 export code, stand by for any and all possible errors up to and including complete and utter obliteration of program state...");
#if DANO
            Proj.Basins = GlobalState.LoadedBasins;
#else
            MainWindow MnWindow = (MainWindow)Application.Current.MainWindow;
            //Proj.Basins = MnWindow.CurrentProject.Basins;
#endif
            if (!XDR.HasChildNodes)
            {
                return(XER);
            }

            List <Layer> Layers = new List <Layer>();

            foreach (XmlNode XDRA in XDR.ChildNodes)
            {
                switch (XDRA.Name)
                {
                case "Metadata":
                    // version check

                    XmlNodeList MetadataNodes = XDRA.ChildNodes;

                    // 2.1 was the earliest TProj2 format version that worked, although it was 2.2c? / 2.3 for import
                    int FileMajorFormatVersion = 2;
                    int FileMinorFormatVersion = 1;

                    foreach (XmlNode MetadataNode in MetadataNodes)
                    {
                        switch (MetadataNode.Name)
                        {
                        case "FormatVersionMajor":
                            FileMajorFormatVersion = Convert.ToInt32(MetadataNode.InnerText);
                            continue;

                        case "FormatVersionMinor":
                            FileMinorFormatVersion = Convert.ToInt32(MetadataNode.InnerText);
                            continue;
                        }
                    }

                    string VersionString        = $"{FileMajorFormatVersion}.{FileMinorFormatVersion}";
                    string CurrentVersionString = $"{FormatVersionMajor}.{FormatVersionMinor}";

                    // when new code is ready move this
                    // switch statement? all of this is temporary
                    if (FileMajorFormatVersion < FormatVersionMajor)
                    {
                        // Major versions break compatibility
                        Error.Throw("Error!", $"This file uses version {VersionString}; the current version is {CurrentVersionString}. This project file is not compatible with this version of the Track Maker.", ErrorSeverity.Error, 405);

                        XER.Successful = false;
                        return(XER);
                    }
                    else if (FileMajorFormatVersion > FormatVersionMajor)
                    {
                        Error.Throw("Error!", $"This file uses version {VersionString}; the current version is {CurrentVersionString}. This project file was created in a future version of the Track Maker and is not compatible with this version. You may wish to update.", ErrorSeverity.Error, 405);

                        XER.Successful = false;
                        return(XER);
                    }

                    continue;

                case "Basins":

                    // Check that there are not no valid basins.
                    if (!XDRA.HasChildNodes)
                    {
                        Error.Throw("No valid basins!", "There are no valid basins!", ErrorSeverity.Error, 181);
                        return(XER);
                    }

                    XmlNodeList XDRBList = XDRA.ChildNodes;

                    foreach (XmlNode XDRACB in XDRBList)
                    {
                        // Create a new basin.
                        Basin Bas = new Basin();

                        if (!XDRACB.HasChildNodes)
                        {
                            Error.Throw("Invalid basin!", "One of the basins in this Proj2 file is corrupted!", ErrorSeverity.Error, 121);
                            return(XER);
                        }
                        else
                        {
                            XmlNodeList XDRAList = XDRACB.ChildNodes;
                            // Iterate through the child nodes of the basin.
                            foreach (XmlNode XDRAC in XDRAList)
                            {
                                switch (XDRAC.Name)
                                {
                                case "Name":         // The name of this basin. Triggers a GlobalState load.
                                    Bas = Proj.GetBasinWithName(XDRAC.InnerText);
                                    continue;

                                case "UserTag":         // The user-given name of this basin
                                    Bas.UserTag = XDRAC.InnerText;
                                    continue;

                                case "IsOpen":         // Not sure if I'll use this
                                    Bas.IsOpen = Convert.ToBoolean(XDRAC.InnerText);
                                    continue;

                                case "IsSelected":         // Not sure if I'll use this
                                    Bas.IsSelected = Convert.ToBoolean(XDRAC.InnerText);
                                    continue;

                                case "Layers":

                                    // Detect if somehow an invalid layer was created
                                    if (!XDRAC.HasChildNodes)
                                    {
                                        Error.Throw("Invalid basin!", "There are no layers!", ErrorSeverity.Error, 122);
                                        return(XER);
                                    }
                                    else
                                    {
                                        // Iterate through the layers
                                        XmlNodeList XDRACList = XDRAC.ChildNodes;

                                        foreach (XmlNode XDRACL in XDRACList)
                                        {
                                            switch (XDRACL.Name)
                                            {
                                            case "Layer":

                                                Layer Lyr = new Layer();
                                                if (!XDRACL.HasChildNodes)
                                                {
                                                    Error.Throw("Invalid basin!", "Empty layer detected!", ErrorSeverity.Error, 123);
                                                    return(XER);
                                                }
                                                else
                                                {
                                                    XmlNodeList XDRACLList = XDRACL.ChildNodes;

                                                    // Yeah
                                                    foreach (XmlNode XDRACLL in XDRACLList)
                                                    {
                                                        switch (XDRACLL.Name)
                                                        {
                                                        case "GUID":                 // GUID of this basin
                                                            Lyr.LayerId = Guid.Parse(XDRACLL.ChildNodes[0].InnerText);
                                                            continue;

                                                        case "Name":                 // Name of this basin
                                                            Lyr.Name = XDRACLL.InnerText;
                                                            continue;

                                                        case "Storms":                 // Storms of this basin

                                                            if (!XDRACLL.HasChildNodes)
                                                            {
                                                                continue;                 // empty layer
                                                            }
                                                            else
                                                            {
                                                                // Find each storm node

                                                                XmlNodeList XDRACLLSList = XDRACLL.ChildNodes;

                                                                foreach (XmlNode XDRACLLS in XDRACLLSList)
                                                                {
                                                                    Storm Sto = new Storm();
                                                                    switch (XDRACLLS.Name)
                                                                    {
                                                                    case "Storm":

                                                                        if (!XDRACLLS.HasChildNodes)
                                                                        {
                                                                            Error.Throw("Invalid basin!", "Empty layer detected!", ErrorSeverity.Error, 186);
                                                                            return(XER);
                                                                        }
                                                                        else
                                                                        {
                                                                            XmlNodeList XDRACLLSSList = XDRACLLS.ChildNodes;

                                                                            foreach (XmlNode XDRACLLSS in XDRACLLSSList)
                                                                            {
                                                                                switch (XDRACLLSS.Name)
                                                                                {
                                                                                case "FormationDate":                         // The formation date of this system.
                                                                                    Sto.FormationDate = DateTime.Parse(XDRACLLSS.ChildNodes[0].InnerText);
                                                                                    continue;

                                                                                case "ID":                         // The ID of this system.
                                                                                    Sto.Id = Convert.ToInt32(XDRACLLSS.ChildNodes[0].InnerText);
                                                                                    continue;

                                                                                case "Name":                         // Name of this system.
                                                                                    Sto.Name = XDRACLLSS.ChildNodes[0].InnerText;
                                                                                    continue;

                                                                                case "Nodes":
                                                                                    // this code is bad and will be entirely scrapped in version 2.1, fixing it in v551
                                                                                    if (!XDRACLLSS.HasChildNodes)
                                                                                    {
                                                                                        continue;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        NodeImportResult NIR = ImportNodes(XDRACLLSS);

                                                                                        if (NIR.Successful && !NIR.Empty)
                                                                                        {
                                                                                            Sto.NodeList = NIR.Nodes;
                                                                                        }
                                                                                    }

                                                                                    continue;

                                                                                case "DeletedNodes":
                                                                                    NodeImportResult DNIR = ImportNodes(XDRACLLSS);

                                                                                    if (DNIR.Successful && !DNIR.Empty)
                                                                                    {
                                                                                        Sto.NodeList_Deleted = DNIR.Nodes;
                                                                                    }

                                                                                    continue;
                                                                                }
                                                                            }
                                                                        }
                                                                        // Get the storm nodes
                                                                        Lyr.AddStorm(Sto);
                                                                        continue;
                                                                    }
                                                                }
                                                            }

                                                            continue;
                                                        }
                                                    }
                                                }


                                                if (Lyr.Name == null)
                                                {
                                                    Error.Throw("Invalid basin!", "Layer with no name!", ErrorSeverity.Error, 125);
                                                    return(XER);
                                                }
                                                else
                                                {
                                                    Layers.Add(Lyr);
                                                }

                                                continue;
                                            }
                                            continue;
                                        }
                                    }
                                    continue;
                                }


                                continue;
                            }
                        }

                        List <string> IXmlParse = XDRA.InnerXml.InnerXml_Parse();

                        // this is a complete hack,
                        // in version 2.1 this code will be thrown out and replaced with xml deserialisation as this is genuinely terrible
                        string BasinName = null;

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

                            IXmlParseString = IXmlParseString.Xaml2Cs();

                            // this should in all reasonable circumstances hit the storm first.
                            if (IXmlParseString == "Name")
                            {
                                // if we are one element before the end of the list, name is empty
                                if (i - IXmlParse.Count == 1)
                                {
                                    Error.Throw("Fatal Error!", "Invalid Proj file - no name specified for basin.", ErrorSeverity.Error, 180);
                                    return(XER);
                                }
                                else
                                {
                                    // also convert the next element

                                    string PlusOne = IXmlParse[i + 1].Xaml2Cs();
                                    BasinName = PlusOne;
                                    break;     // avoid multiple hits
                                }
                            }
                        }

                        if (BasinName != null)
                        {
                            Basin NewBasin = Proj.GetBasinWithName(BasinName);

                            // really dumb hack
                            foreach (Layer Lyrs in Layers)
                            {
                                NewBasin.AddLayer(Lyrs);
                            }

                            Proj.AddBasin(NewBasin, true);
                            Proj.SelectedBasin = NewBasin;
                        }
                    }



                    continue;
                }
            }

            XER.Successful = true;
            XER.Project    = Proj;
            return(XER);
        }
Exemple #5
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);
        }