Example #1
0
        public bool MatchesQuery(Exoplanet exoplanet)
        {
            if (NameQueries.Count > 0)
            {
                bool matches = false;

                foreach (NameQuery query in NameQueries)
                {
                    string name = exoplanet.Name.ToLower();

                    if (query.QueryType == QueryTypes.StartsWith)
                    {
                        if (name.StartsWith(query.Name))
                        {
                            matches = true;
                        }
                    }
                    else if (query.QueryType == QueryTypes.EndsWith)
                    {
                        if (name.EndsWith(query.Name))
                        {
                            matches = true;
                        }
                    }
                    else if (query.QueryType == QueryTypes.Contains)
                    {
                        if (name.Contains(query.Name))
                        {
                            matches = true;
                        }
                    }
                }

                if (!matches)
                {
                    return(false);
                }
            }

            if (DetectionQueries.Count > 0)
            {
                bool matches = false;

                foreach (DetectionQuery query in DetectionQueries)
                {
                    string detection = exoplanet.DetectionType.ToLower();

                    if (query.QueryType == QueryTypes.StartsWith)
                    {
                        if (detection.StartsWith(query.Detection))
                        {
                            matches = true;
                        }
                    }
                    else if (query.QueryType == QueryTypes.EndsWith)
                    {
                        if (detection.EndsWith(query.Detection))
                        {
                            matches = true;
                        }
                    }
                    else if (query.QueryType == QueryTypes.Contains)
                    {
                        if (detection.Contains(query.Detection))
                        {
                            matches = true;
                        }
                    }
                }

                if (!matches)
                {
                    return(false);
                }
            }

            if (SpectralQueries.Count > 0)
            {
                bool matches = false;

                foreach (SpectralQuery query in SpectralQueries)
                {
                    if (Helper.IsDefined(exoplanet.Star.Property.SPType))
                    {
                        string spectual = exoplanet.Star.Property.SPType.ToLower();

                        if (query.QueryType == QueryTypes.StartsWith)
                        {
                            if (spectual.StartsWith(query.Spectral))
                            {
                                matches = true;
                            }
                        }
                        else if (query.QueryType == QueryTypes.EndsWith)
                        {
                            if (spectual.EndsWith(query.Spectral))
                            {
                                matches = true;
                            }
                        }
                        else if (query.QueryType == QueryTypes.Contains)
                        {
                            if (spectual.Contains(query.Spectral))
                            {
                                matches = true;
                            }
                        }
                    }
                }

                if (!matches)
                {
                    return(false);
                }
            }

            if (HabitabilityQueries.Count > 0)
            {
                bool matches = false;

                foreach (HabitabilityQuery query in HabitabilityQueries)
                {
                    string habitability = Habitability.GetHabitability(exoplanet).ToString().ToLower();

                    if (query.QueryType == QueryTypes.StartsWith)
                    {
                        if (habitability.StartsWith(query.Habitability))
                        {
                            matches = true;
                        }
                    }
                    else if (query.QueryType == QueryTypes.EndsWith)
                    {
                        if (habitability.EndsWith(query.Habitability))
                        {
                            matches = true;
                        }
                    }
                    else if (query.QueryType == QueryTypes.Contains)
                    {
                        if (habitability.Contains(query.Habitability))
                        {
                            matches = true;
                        }
                    }
                }

                if (!matches)
                {
                    return(false);
                }
            }

            if (BetweenQueries.Count > 0)
            {
                bool matches = false;

                foreach (BetweenQuery query in BetweenQueries)
                {
                    double value = 0.0;

                    if (Parse(exoplanet, query.PlotType, out value))
                    {
                        if (value >= query.LoValue && value <= query.HiValue)
                        {
                            matches = true;
                        }
                    }
                }

                if (!matches)
                {
                    return(false);
                }
            }

            if (LessThanQueries.Count > 0)
            {
                bool matches = false;

                foreach (LessThanQuery query in LessThanQueries)
                {
                    double value = 0.0;

                    if (Parse(exoplanet, query.PlotType, out value))
                    {
                        if (value <= query.Value)
                        {
                            matches = true;
                        }
                    }
                }

                if (!matches)
                {
                    return(false);
                }
            }

            if (GreaterThanQueries.Count > 0)
            {
                bool matches = false;

                foreach (GreaterThanQuery query in GreaterThanQueries)
                {
                    double value = 0.0;

                    if (Parse(exoplanet, query.PlotType, out value))
                    {
                        if (value >= query.Value)
                        {
                            matches = true;
                        }
                    }
                }

                if (!matches)
                {
                    return(false);
                }
            }

            return(true);
        }
        private void AddItemsToListView(ListView listView, bool addColumns, bool rebuildArray)
        {
            if (listView != null)
            {
                listView.BeginUpdate();
            }

            if (rebuildArray)
            {
                if (Exoplanets.ExoplanetsArray != null)
                {
                    Exoplanets.ExoplanetsArray.Clear();
                }

                Exoplanets.ExoplanetsArray = ReadXML.Read(XmlFileName);
            }
            else
            {
                if (ExoplanetListView != null)
                {
                    for (int index = ExoplanetListView.Items.Count - 1; index >= 0; --index)
                    {
                        ExoplanetListView.Items.RemoveAt(index);
                    }
                }
            }

            if (addColumns)
            {
                AddColumnsToListView(listView);
            }

            List <ListViewItem> items = new List <ListViewItem> ();

            if (Exoplanets.ExoplanetsArray != null)
            {
                foreach (Exoplanet exoplanet in Exoplanets.ExoplanetsArray)
                {
                    if (Queries.CurrentQueries != null)
                    {
                        if (!Queries.CurrentQueries.MatchesQuery(exoplanet))
                        {
                            continue;
                        }
                    }

                    ListViewItem item = new ListViewItem(exoplanet.Name, 0);

                    item.SubItems.Add(Helper.Format(exoplanet.DetectionType));
                    item.SubItems.Add(Helper.Format(Habitability.GetHabitability(exoplanet).ToString()));
                    item.SubItems.Add(Helper.Format(exoplanet.Mass));
                    item.SubItems.Add(Helper.Format(exoplanet.Radius));
                    item.SubItems.Add(Helper.Format(exoplanet.OrbitalPeriod));
                    item.SubItems.Add(Helper.Format(exoplanet.SemiMajorAxis));
                    item.SubItems.Add(Helper.Format(exoplanet.Eccentricity));
                    item.SubItems.Add(Helper.Format(exoplanet.AngularDistance));
                    item.SubItems.Add(Helper.Format(exoplanet.Inclination));
                    item.SubItems.Add(Helper.Format(exoplanet.Omega));
                    item.SubItems.Add(Helper.Format(exoplanet.VelocitySemiamplitude));

                    item.SubItems.Add(Helper.Format(exoplanet.Discovered));
                    item.SubItems.Add(Helper.Format(exoplanet.Updated));

                    item.SubItems.Add(Helper.Format(exoplanet.Star.Name));
                    item.SubItems.Add(Helper.Format(exoplanet.Star.Property.SPType));
                    item.SubItems.Add(Helper.Format(exoplanet.Star.Property.Mass));
                    item.SubItems.Add(Helper.Format(exoplanet.Star.Property.Radius));
                    item.SubItems.Add(Helper.Format(exoplanet.Star.Property.Distance));
                    item.SubItems.Add(Helper.Format(exoplanet.Star.Property.Age));
                    item.SubItems.Add(Helper.FormatHMS(exoplanet.Star.RightAccession));
                    item.SubItems.Add(Helper.FormatHMS(exoplanet.Star.Declination));
                    item.Tag = exoplanet;

                    items.Add(item);
                }
            }

            Text = "Exoplanet Library" + (XmlFileName.Length > 0 ? " - " + XmlFileName : string.Empty);

            if (listView != null)
            {
                listView.Items.AddRange(items.ToArray());
                listView.EndUpdate();
            }
        }