Example #1
0
        /// <summary>
        /// bad dynahotkey impl
        /// </summary>
        /// <param name="HitKey"></param>
        private void Window_HandleCategorySystemDynaHotkeys(Key HitKey)
        {
            CategorySystem CurrentCategorySystem = GlobalState.CategoryManager.CurrentCategorySystem;

            foreach (Category Cat in CurrentCategorySystem.Categories)
            {
                if (Cat.Hotkey != null)
                {
                    // needs a refactoring to be done properly
                    int MinIntensity = Cat.LowerBound;

                    Storm CurrentStorm = CurrentProject.SelectedBasin.GetCurrentStorm();

                    Debug.Assert(Cat.Hotkey.Keys.Count > 0);

                    // yeah
                    if (Cat.Hotkey.Keys[0] == HitKey)
                    {
                        // temp
                        if (CurrentStorm != null)
                        {
                            Node CNa = new Node()
                            {
                                Intensity = MinIntensity,
                                NodeType  = ST2Manager.GetStormTypeWithName("Tropical"),
                                Position  = new RelativePosition(0, 0)
                            };

                            CurrentStorm.LastNode = CNa;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Elimina la ultima categoría del arbol de ruta y reescibe la ruta que es consumida por la vista
        /// </summary>
        private void RemoveCategory()
        {
            int count = categoriesSelected.Count;

            Categories.Clear();

            categoriesSelected.RemoveAt(count - 1);
            count--;

            WriteRoute();

            if (count == 0)
            {
                foreach (Category c in CategorySystem.RecoveryMainCategory())
                {
                    Categories.Add(c);
                }
            }
            else
            {
                Category lastCategory = categoriesSelected[count - 1];
                foreach (Category c in CategorySystem.RecoverySubcategories(lastCategory))
                {
                    Categories.Add(c);
                }
            }

            ReloadTransactions();
        }
        /// <summary>
        /// Agrega la categoría seleccionada al listado con la ruta de transacciones a seguir y
        /// luego actualiza el listado de categorías para que sean las subcategorias de la ultima seleccion
        /// </summary>
        private void AddCategory()
        {
            Category actualCategory = CategorySelected;

            categoriesSelected.Add(CategorySelected);
            Categories.Clear();
            WriteRoute();
            ReloadTransactions();

            foreach (Category c in CategorySystem.RecoverySubcategories(actualCategory))
            {
                Categories.Add(c);
            }
        }
Example #4
0
        /// <summary>
        /// Este metodo consulta a la base de datos todas las categorías que esta contiene y las
        /// recarga en las listas que la vista utiliza, dependiend del usuario
        /// </summary>
        private void ReloadCategories()
        {
            allCategories.Clear();
            allMainCategories.Clear();
            allSubcategories.Clear();
            allAvailableCategories.Clear();

            if (UserSelected != null)
            {
                CategorySystem.DefineParameter(UserSelected.ID);
                allMainCategories = CategorySystem.RecoveryMainCategory();
            }

            MainCategoryName      = null;       //Al ponerlo en null debe actualizar la lista MainCategories
            SubcategoryName       = null;       //Al darle valor null debe actualizar la lista de subcategorias
            AvailableCategoryName = null;       //Al darle valor null debe actualizar la lista de AvailableCategories
        }
Example #5
0
        /// <summary>
        /// Este metodo va construyendo las listas de relaciones entre las distintas categorias
        /// </summary>
        private void RecoveryRelationList()
        {
            int             fatherClass = 1;
            List <Category> categories  = null;
            Category        father      = null;

            //Se limpian las listas
            allSubcategories.Clear();
            allAvailableCategories.Clear();

            if (categoryRoute.Count > 0)
            {
                fatherClass      = categoryRoute.Count;
                father           = categoryRoute[fatherClass - 1];
                allSubcategories = CategorySystem.RecoverySubcategories(father);

                categories = CategorySystem.RecoveryCategoryByClass(fatherClass + 1);

                for (int indexTemporal = 0; indexTemporal < categories.Count; indexTemporal++)
                {
                    bool     relacionado = false;
                    Category c           = categories[indexTemporal];

                    for (int indexSubcat = 0; indexSubcat < allSubcategories.Count; indexSubcat++)
                    {
                        if (c.ID == allSubcategories[indexSubcat].ID)
                        {
                            relacionado = true;
                            break;
                        }
                    }

                    if (!relacionado)
                    {
                        allAvailableCategories.Add(categories[indexTemporal]);
                    }
                }
            }


            SubcategoryName       = null;
            AvailableCategoryName = null;
        }//Fin del metodo
Example #6
0
        private bool ValidateCreateNewSubcategory()
        {
            ErrorInNewSubcategoryName = null;
            if (string.IsNullOrEmpty(NewSubcategoryName) || string.IsNullOrWhiteSpace(NewSubcategoryName))
            {
                ErrorInNewSubcategoryName = "Este campo es obligatorio";
                return(false);
            }

            bool uniqueName = CategorySystem.ValidateCategoryName(NewSubcategoryName, CurrentClass);

            if (!uniqueName)
            {
                ErrorInNewSubcategoryName = "Este nombre ya está en uso";
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Recarga las categorias y limpia las listas
        /// </summary>
        private void LoadCategories()
        {
            categoriesSelected.Clear();
            Categories.Clear();

            if (actualUser != null)
            {
                CategorySystem.DefineParameter(actualUser.ID);
                foreach (Category c in CategorySystem.GetFatherCategories())
                {
                    Categories.Add(c);
                }
            }
            else
            {
                CategorySystem.DefineParameter(null);
            }

            WriteRoute();
        }
Example #8
0
        /// <summary>
        /// Needs to be majorly updated and refactored for v2
        /// </summary>
        /// <param name="basin"></param>
        /// <returns></returns>
        public bool ExportCore(Project Project, string FileName)
        {
            Directory.CreateDirectory(FileName);

            Basin SelBasin = Project.SelectedBasin;

            // create a file for each storm
            foreach (Storm Storm in SelBasin.GetFlatListOfStorms())
            {
                if (Storm.Name.Length > 12)
                {
                    // Woah, calm it (Priscilla 442)
                    Error.Throw("Error", "This format, the ATCF BestTrack format, has several limitations (and is obsolete to begin with). Exporting to this format is not recommended. \n\nLimitations:\n\n- It does not support storms with names with a length above twelve characters.\n- It does not support abbreviated character names of lengths more than three characters.\n- It uses exceedingly bizarre spelling.\nIt is from the 1980s.\n\n- There is no documentation on the Internet, despite extensive efforts to acquire some.", ErrorSeverity.Error, 131);
                    return(false);
                }

                string StormFileName = Path.Combine(FileName, $@"{Storm.Name}.dat");
                // Create a new file for each storm.
                using (StreamWriter SW = new StreamWriter(new FileStream(StormFileName, FileMode.Create)))
                {
                    // For each node.
                    foreach (Node Node in Storm.NodeList)
                    {
                        if (!Node.IsRealType())
                        {
                            Error.Throw("Error", "Custom storm types are not supported when exporting to ATCF/HURDAT2 format.", ErrorSeverity.Error, 248);
                            return(false);
                        }

                        if (SelBasin.Abbreviation != null)
                        {
                            SW.Write($"{SelBasin.Abbreviation}, ");
                        }
                        else
                        {
                            SW.Write($"{SelBasin.Name}, ");
                        }

                        // Pad with a zero if <10 and write storm id.
                        SW.Write($"{Utilities.PadZero(Storm.Id + 1)}, ");

                        // Get the node date
                        DateTime NodeDate = Storm.GetNodeDate(Node.Id);

                        SW.Write($"{NodeDate.ToString("yyyyMMdd")}{Utilities.PadZero(NodeDate.Hour)}");

                        // Some weird padding shit (It's actually time since system formation. Who knew???)
                        SW.Write(",   , ");

                        // Best marker, more useless padding
                        SW.Write("BEST,   ");

                        // God knows what this does
                        SW.Write("0, ");

                        // Node position.

                        Category Cat = Storm.GetNodeCategory(Node, GlobalState.CategoryManager.CurrentCategorySystem);

                        Coordinate X = Project.SelectedBasin.FromNodePositionToCoordinate(Node.Position, VolatileApplicationSettings.WindowSize);

                        SW.Write($"{X.Coordinates.X}{X.Directions[0]},  {X.Coordinates.Y}{X.Directions[1]},  ");

                        // Intensity.

                        for (int i = 0; i < 4 - Node.Intensity.ToString().Length; i++)
                        {
                            SW.Write(" ");
                        }

                        // Convert to KT (DANO: MOVE TO DEDICATED HurricaneConversions CLASS)

                        double Intensity = Utilities.RoundNearest(Node.Intensity / 1.151, 5);

                        SW.Write($"{Intensity}, ");

                        // Pressure. We don't do this until dano and even then it will be optional. Just put 1000mbars
                        SW.Write($"{Node.Pressure}, ");

                        // Write the category and a WHOLE bunch of information that we don't need or use yet - environmental pressure etc - I don't know what most of these are tbh

                        CategorySystem CurrentCategorySystem = GlobalState.CategoryManager.CurrentCategorySystem;

                        Category Ct = Storm.GetNodeCategory(Node, CurrentCategorySystem);

                        // v610: fix crash when exporting projects with invalid categories (i.e. storm too intense) iris: add palceholder
                        if (Ct == null)
                        {
                            Ct = CurrentCategorySystem.GetHighestCategory();
                        }

                        string CatString = null;

                        if (Ct.Abbreviation == null)
                        {
                            int SplitLength = CatString.Split(' ').Length;
                            CatString = Cat.GetAbbreviatedCategoryName(CatString, SplitLength, 0, 1, true);
                        }
                        else
                        {
                            CatString = Ct.Abbreviation;
                        }

                        Debug.Assert(CatString != null);

                        if (CatString.Length > 3)
                        {
                            MessageBox.Show("Due to the limitations of the ATCF format, category names cannot be longer than 3 characters abbreviated.");
                            return(false);
                        }

                        // Placeholder information
                        for (int i = 0; i < 3 - CatString.Length; i++)
                        {
                            SW.Write(" ");
                        }

                        SW.Write($"{CatString},  "); // todo: abbreviate (dano)

                        // Aforementioned information
                        SW.Write($"x,   0,    ,    0,    0,    0,    0, 1014,   90,  60,   0,   0,   L,   0,    ,   0,   0, ");

                        // Shit Format
                        for (int i = 0; i < (12 - Storm.Name.Length); i++)
                        {
                            SW.Write(" ");
                        }

                        SW.Write(Storm.Name);

                        // More pointless and irrelevant data.
                        SW.Write(", M,  0,    ,    0,    0,    0,    0, ");

                        // Why does this exist
                        SW.Write("genesis-num, ");
                        SW.Write(Utilities.PadZero(Storm.Id + 1, 2));
                        SW.Write(", \n"); // Write newline

                        // on success
                        GlobalState.SetCurrentOpenFile(FileName);
                    }
                }
            }


            return(true);
        }