private void SaveDefinedRoute(DefinedRoute selectedDefinedRoute)
        {
            var msg = MessageBox.Show(
                @"You have selected a new route not saved on the database, do you want to save it now?",
                null, MessageBoxButtons.YesNo);

            if (msg == DialogResult.Yes)
            {
                var initialPath = Path.Combine(Application.StartupPath, "assets", "planetes");

                var fileDialog = new OpenFileDialog
                {
                    InitialDirectory = initialPath,
                    CheckFileExists  = true,
                    Filter           = @"*.png|*.jpg",
                    Title            = @"Select an image tied to this route"
                };

                selectedDefinedRoute.Map = fileDialog.ShowDialog() == DialogResult.OK
                    ? fileDialog.SafeFileName
                    : null;
            }

            Task.Run(() => AddDefinedRoute(_dbFilePath, selectedDefinedRoute));
            _definedRoutes.Add(selectedDefinedRoute);
        }
        private static void AddDefinedRoute(string dbPath, DefinedRoute definedRoute)
        {
            var doc = new XmlDocument();

            doc.Load(dbPath);

            var defineRoute = doc.CreateElement("defineRoute");

            var orDes = doc.CreateElement("OrDes");

            orDes.InnerText = $@"{definedRoute.Origin}-{definedRoute.Destination}";
            defineRoute.AppendChild(orDes);

            var selectedRoute = doc.CreateElement("selectedRoute");

            selectedRoute.InnerText = string.Join("-", definedRoute.Routes);
            defineRoute.AppendChild(selectedRoute);

            if (definedRoute.Map != null)
            {
                var map = doc.CreateElement("map");
                map.InnerText = definedRoute.Map;
                defineRoute.AppendChild(map);
            }

            var parent = doc.SelectSingleNode("//definedRoutes");

            parent?.AppendChild(defineRoute);
            doc.Save(dbPath);
        }
        private void CalculateCoordinates()
        {
            var selectedDefinedRoute = new DefinedRoute
            {
                Origin      = _selectedOriginPlanet.Name,
                Destination = _selectedDestinationPlanet.Name,
                Routes      = _selectedOriginPlanet
                              .HyperspaceRoutes.Concat(_selectedDestinationPlanet.HyperspaceRoutes)
            };

            var isDefinedRouteExist = _definedRoutes.Any(x =>
                                                         x.Origin.Equals(selectedDefinedRoute.Origin) && x.Destination.Equals(
                                                             selectedDefinedRoute.Destination) &&
                                                         x.Routes.SequenceEqual(selectedDefinedRoute.Routes));


            var originVector      = Hyperspace.CalculateVector(_selectedOriginPlanet.Situation);
            var destinationVector = Hyperspace.CalculateVector();

            if (originVector == null)
            {
                MessageBox.Show(
                    @"No s'ha trobat cap ruta segura per per a apropar-se al planeta de destí");
                return;
            }

            if (!isDefinedRouteExist)
            {
                SaveDefinedRoute(selectedDefinedRoute);
            }

            foreach (Control control in panel_selectplanet.Controls)
            {
                control.Visible = false;
            }

            mapa1.ApproachVector    = originVector;
            mapa1.DestinationVector = destinationVector;
            mapa1.DestinationPlanet = _selectedDestinationPlanet.Name;

            mapa1.Init();
            mapa1.Visible = true;
            mapa1.BringToFront();
        }