예제 #1
0
        private void buttonHistory_Click(object sender, EventArgs e)
        {
            ISystem sys = SystemData.GetSystem(HistorySelection) ?? SystemData.GetSystem("sol") ?? new SystemClass {
                name = "Sol", SearchName = "sol", x = 0, y = 0, z = 0
            };

            OrientateMapAroundSystem(sys);
        }
예제 #2
0
 private void OrientateMapAroundSystem(String systemName)
 {
     if (!String.IsNullOrWhiteSpace(systemName))
     {
         ISystem system = SystemData.GetSystem(systemName.Trim());
         OrientateMapAroundSystem(system);
     }
 }
예제 #3
0
        private void buttonCenter_Click(object sender, EventArgs e)
        {
            SystemClass sys = SystemData.GetSystem(textboxFrom.Text);

            OrientateMapAroundSystem(sys);

            ResetCamera();
        }
예제 #4
0
        private void buttonHome_Click(object sender, EventArgs e)
        {
            ISystem sys = SystemData.GetSystem(_homeSystem) ?? SystemData.GetSystem("sol") ?? new SystemClass {
                name = "Sol", SearchName = "sol", x = 0, y = 0, z = 0
            };

            OrientateMapAroundSystem(sys);

            ResetCamera();
        }
예제 #5
0
 private void ShowCenterSystem()
 {
     if (CenterSystem == null)
     {
         CenterSystem = SystemData.GetSystem("sol") ?? new SystemClass {
             name = "Sol", SearchName = "sol", x = 0, y = 0, z = 0
         };
     }
     labelSystemCoords.Text = string.Format("{0} x:{1} y:{2} z:{3}", CenterSystem.name, CenterSystem.x.ToString("0.00"), CenterSystem.y.ToString("0.00"), CenterSystem.z.ToString("0.00"));
 }
예제 #6
0
        private void buttonCenter_Click(object sender, EventArgs e)
        {
            SystemClass sys = SystemData.GetSystem(textboxFrom.Text);

            if (sys == null)
            {
                textboxFrom.Text = String.Empty;
            }
            else
            {
                OrientateMapAroundSystem(sys);
            }
        }
예제 #7
0
        private void DrawTravelHistory()
        {
            DateTime start = startDate;



            foreach (var sys in _eddiscoveryForm.TravelControl.visitedSystems)
            {
                if (sys.curSystem == null)
                {
                    sys.curSystem = SystemData.GetSystem(sys.Name);
                }
            }

            int currentcmdr = EDDiscoveryForm.EDDConfig.CurrentCommander.Nr;

            var history = from systems in _eddiscoveryForm.TravelControl.visitedSystems where systems.time > start && systems.time < endDate && systems.curSystem != null && systems.curSystem.HasCoordinate == true orderby systems.time select systems;
            List <SystemPosition> listHistory = history.ToList <SystemPosition>();
            Graphics gfx = Graphics.FromImage(imageViewer1.Image);

            if (listHistory.Count > 1)
            {
                Pen pen = new Pen(Color.FromArgb(listHistory[1].vs.MapColour), 2);
                if (pen.Color.A == 0)
                {
                    pen.Color = Color.FromArgb(255, pen.Color);
                }
                for (int ii = 1; ii < listHistory.Count; ii++)
                {
                    if (listHistory[ii].vs.MapColour != listHistory[ii - 1].vs.MapColour)
                    {
                        pen = new Pen(Color.FromArgb(listHistory[ii].vs.MapColour), 2);
                        if (pen.Color.A == 0)
                        {
                            pen.Color = Color.FromArgb(255, pen.Color);
                        }
                    }
                    DrawLine(gfx, pen, listHistory[ii - 1].curSystem, listHistory[ii].curSystem);
                }
            }

            Point test1 = currentFGEImage.TransformCoordinate(currentFGEImage.BottomLeft);
            Point test2 = currentFGEImage.TransformCoordinate(currentFGEImage.TopRight);


            if (Test)
            {
                TestGrid(gfx);
            }
        }
예제 #8
0
        public void AddVisitedSystemsInformation()
        {
            if (VisitedSystems != null && VisitedSystems.Any())
            {
                ISystem lastknownps = LastKnownSystemPosition();

                // For some reason I am unable to fathom this errors during the session after DBUpgrade8
                // colours just resolves to an object reference not set error, but after a restart it works fine
                // Not going to waste any more time, a one time restart is hardly the worst workaround in the world...
                IEnumerable <IGrouping <int, SystemPosition> > colours =
                    from SystemPosition sysPos in VisitedSystems where sysPos.vs != null
                    group sysPos by sysPos.vs.MapColour;

                if (colours != null)
                {
                    foreach (IGrouping <int, SystemPosition> colour in colours)
                    {
                        if (DrawLines)
                        {
                            var datasetl = Data3DSetClass <LineData> .Create("visitedstars" + colour.Key.ToString(), Color.FromArgb(colour.Key), 2.0f);

                            foreach (SystemPosition sp in colour)
                            {
                                if (sp.curSystem != null && sp.curSystem.HasCoordinate && sp.lastKnownSystem != null && sp.lastKnownSystem.HasCoordinate)
                                {
                                    datasetl.Add(new LineData(sp.curSystem.x, sp.curSystem.y, sp.curSystem.z,
                                                              sp.lastKnownSystem.x, sp.lastKnownSystem.y, sp.lastKnownSystem.z));
                                }
                            }
                            _datasets.Add(datasetl);
                        }
                        else
                        {
                            var datasetvs = Data3DSetClass <PointData> .Create("visitedstars" + colour.Key.ToString(), Color.FromArgb(colour.Key), 2.0f);

                            foreach (SystemPosition sp in colour)
                            {
                                ISystem star = SystemData.GetSystem(sp.Name);
                                if (star != null && star.HasCoordinate)
                                {
                                    AddSystem(star, datasetvs);
                                }
                            }
                            _datasets.Add(datasetvs);
                        }
                    }
                }
            }
        }
예제 #9
0
        private void buttonCenter_Click(object sender, EventArgs e)
        {
            SystemClass sys = SystemData.GetSystem(textBox_From.Text);

            if (sys == null)
            {
                return;
            }

            CenterSystem = sys;
            ShowCenterSystem();

            GenerateDataSets();
            glControl1.Invalidate();
        }
예제 #10
0
        public void InitData()
        {
            _visitedStars = new Dictionary <string, SystemClass>();

            if (VisitedSystems != null)
            {
                foreach (SystemPosition sp in VisitedSystems)
                {
                    SystemClass star = SystemData.GetSystem(sp.Name);
                    if (star != null && star.HasCoordinate)
                    {
                        _visitedStars[star.SearchName] = star;
                    }
                }
            }
        }
예제 #11
0
        public static bool Store(List <SystemClass> systems)
        {
            if (systems == null)
            {
                return(true);
            }

            try
            {
                Stopwatch sw = new Stopwatch();

                sw.Start();

                using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
                {
                    cn.Open();
                    SQLiteTransaction transaction = cn.BeginTransaction();
                    foreach (SystemClass system in systems)
                    {
                        SystemClass sys = SystemData.GetSystem(system.name);
                        if (sys != null)
                        {
                            system.UpdateEDSM(cn, sys.id, transaction);
                        }
                        else
                        {
                            system.Store(cn, transaction);
                        }
                    }

                    transaction.Commit();
                    cn.Close();
                }
                sw.Stop();
                System.Diagnostics.Trace.WriteLine("SQLite Add  " + systems.Count.ToString() + " systems: " + sw.Elapsed.TotalSeconds.ToString("0.000s"));
                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception SystemClass: " + ex.Message);
                System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace);
                return(false);
            }
        }
예제 #12
0
        private ISystem LastKnownSystemPosition()
        {
            ISystem lastknownps = null;

            foreach (SystemPosition ps in VisitedSystems)
            {
                if (ps.curSystem == null)
                {
                    ps.curSystem = SystemData.GetSystem(ps.Name);
                }

                if (ps.curSystem != null && ps.curSystem.HasCoordinate)
                {
                    ps.lastKnownSystem = lastknownps;
                    lastknownps        = ps.curSystem;
                }
            }
            return(lastknownps);
        }
예제 #13
0
        private void buttonShow_Click(object sender, EventArgs e)
        {
            SystemClass sys = SystemData.GetSystem(textBox_From.Text);

            if (sys == null)
            {
                return;
            }


            var syslist = (from c in SystemData.SystemList orderby(c.x - sys.x) * (c.x - sys.x) + (c.y - sys.y) * (c.y - sys.y) + (c.z - sys.z) * (c.z - sys.z) select c).ToList <SystemClass>();

            dataGridView1.Rows.Clear();

            dataGridView1.Columns.Clear();
            dataGridView1.Columns.Add("Name", "Name");
            dataGridView1.Columns.Add("Dist", "Dist");
            dataGridView1.Columns.Add("Government", "Government");
            dataGridView1.Columns.Add("Government", "Allegiance");
            dataGridView1.Columns.Add("Government", "Population");


            foreach (SystemClass sys2 in syslist)
            {
                double dist = SystemData.Distance(sys, sys2);

                object[] rowobj = { sys2.name, dist.ToString("0.00"), sys2.government.ToString(), sys2.allegiance.ToString(), sys2.population };
                int      rownr;


                dataGridView1.Rows.Add(rowobj);
                rownr = dataGridView1.Rows.Count - 1;


                var cell = dataGridView1.Rows[rownr].Cells[1];

                cell.Tag = sys2;
            }
        }
예제 #14
0
        private void DrawTravelHistory()
        {
            DateTime start = maxage;



            foreach (var sys in _eddiscoveryForm.TravelControl.visitedSystems)
            {
                if (sys.curSystem == null)
                {
                    sys.curSystem = SystemData.GetSystem(sys.Name);
                }
            }


            var history = from systems in _eddiscoveryForm.TravelControl.visitedSystems where systems.time > start && systems.curSystem != null && systems.curSystem.HasCoordinate == true orderby systems.time select systems;
            List <SystemPosition> listHistory = history.ToList <SystemPosition>();
            Graphics gfx = Graphics.FromImage(imageViewer1.Image);
            Pen      pen = new Pen(Color.Red, 2);

            if (listHistory.Count > 1)
            {
                for (int ii = 1; ii < listHistory.Count; ii++)
                {
                    DrawLine(gfx, pen, listHistory[ii - 1].curSystem, listHistory[ii].curSystem);
                }
            }

            Point test1 = currentFGEImage.TransformCoordinate(currentFGEImage.BottomLeft);
            Point test2 = currentFGEImage.TransformCoordinate(currentFGEImage.TopRight);

            if (Test)
            {
                TestGrid(gfx);
            }
        }
예제 #15
0
 private void AddSystem(string systemName, Data3DSetClass <PointData> dataset)
 {
     AddSystem(SystemData.GetSystem(systemName), dataset);
 }
예제 #16
0
        public ReferenceSystem GetCandidate()
        {
            double           maxdistance     = 0;
            ReferencesSector sectorcandidate = null;

            // Get Sector with maximum distance for all others...
            for (int i = 0; i < sections; i++)
            {
                for (int j = 0; j < sections / 2; j++)
                {
                    if (sectors[i, j].ReferencesCount == 0 && sectors[i, j].CandidatesCount > 0)  // An unused sector with candidates left?
                    {
                        double dist;
                        double mindist = 10;

                        for (int ii = 0; ii < sections; ii++)
                        {
                            for (int jj = 0; jj < sections / 2; jj++)
                            {
                                if (sectors[ii, jj].CandidatesCount > 0)
                                {
                                    dist = CalculateAngularDistance(sectors[i, j].AzimuthCenterRad, sectors[i, j].LatitudeCenterRad, sectors[ii, jj].AzimuthCenterRad, sectors[ii, jj].LatitudeCenterRad);

                                    if (dist > 0.001)
                                    {
                                        if (dist < mindist)
                                        {
                                            mindist = dist;
                                        }
                                    }
                                }
                            }
                        }


                        if (mindist > maxdistance)  // New candidate
                        {
                            maxdistance     = mindist;
                            sectorcandidate = sectors[i, j];
                        }
                    }
                }
            }

            if (sectorcandidate == null)
            {
                if (NrOfRefenreceSystems == 0)
                {
                    SystemClass sys = SystemData.GetSystem("Sol");

                    if (EstimatedPosition.x == 0 && EstimatedPosition.y == 0 && EstimatedPosition.z == 0)
                    {
                        sys = SystemData.GetSystem("Sirius");
                    }

                    if (sys == null)
                    {
                        return(null);   // Should not happend
                    }
                    ReferenceSystem refSys = new ReferenceSystem(sys, EstimatedPosition);

                    return(refSys);
                }

                return(null);
            }

            return(sectorcandidate.GetBestCandidate());
        }
예제 #17
0
        internal string GetNewSystems(SQLiteDBClass db)
        {
            string json;
            string date = "2010-01-01 00:00:00";
            string lstsyst;

            string retstr = "";


            Application.DoEvents();

            db.GetAllSystems();

            //if (lstsys)


            DateTime NewSystemTime;

            if (SQLiteDBClass.globalSystems == null || SQLiteDBClass.globalSystems.Count == 0)
            {
                lstsyst = "2010-01-01 00:00:00";
            }
            else
            {
                NewSystemTime = SQLiteDBClass.globalSystems.Max(x => x.UpdateDate);
                lstsyst       = NewSystemTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                lstsyst       = db.GetSettingString("EDSMLastSystems", lstsyst);

                if (lstsyst.Equals("2010-01-01 00:00:00"))
                {
                    lstsyst = NewSystemTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                }
            }
            json = RequestSystems(lstsyst);


            List <SystemClass> listNewSystems = SystemClass.ParseEDSM(json, ref date);



            List <SystemClass> systems2Store = new List <SystemClass>();

            foreach (SystemClass system in listNewSystems)
            {
                // Check if sys exists first
                SystemClass sys = SystemData.GetSystem(system.name);
                if (sys == null)
                {
                    systems2Store.Add(system);
                }
                else if (!sys.name.Equals(system.name) || sys.x != system.x || sys.y != system.y || sys.z != system.z)  // Case or position changed
                {
                    systems2Store.Add(system);
                }
            }
            SystemClass.Store(systems2Store);

            retstr = systems2Store.Count.ToString() + " new systems from EDSM." + Environment.NewLine;
            Application.DoEvents();


            db.PutSettingString("EDSMLastSystems", date);

            return(retstr);
        }
예제 #18
0
        public bool Add2DB(List <SystemClass> eddbsystems, List <StationClass> eddbstations)
        {
            SQLiteDBClass db = new SQLiteDBClass();

            db.Connect2DB();


            Stopwatch sw = new Stopwatch();

            sw.Start();

            using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
            {
                cn.Open();
                int nr = 0;

                using (var tra = cn.BeginTransaction())
                {
                    try
                    {
                        foreach (SystemClass sys in eddbsystems)
                        {
                            SystemClass sysdb = SystemData.GetSystem(sys.name);

                            if (sysdb != null)  // Update system
                            {
                                if (sysdb.eddb_updated_at != sys.eddb_updated_at)
                                {
                                    sysdb.id_eddb         = sys.id_eddb;
                                    sysdb.faction         = sys.faction;
                                    sysdb.population      = sys.population;
                                    sysdb.government      = sys.government;
                                    sysdb.allegiance      = sys.allegiance;
                                    sysdb.state           = sys.state;
                                    sysdb.security        = sys.security;
                                    sysdb.primary_economy = sys.primary_economy;
                                    sysdb.needs_permit    = sys.needs_permit;
                                    sysdb.eddb_updated_at = sys.eddb_updated_at;


                                    sysdb.Update(cn, sysdb.id, tra);
                                    nr++;
                                }
                            }
                            else
                            {
                                System.Diagnostics.Trace.WriteLine("New system " + sys.name);
                            }
                        }
                        System.Diagnostics.Trace.WriteLine("Add2DB  " + nr.ToString() + " eddb systems: " + sw.Elapsed.TotalSeconds.ToString("0.000s"));
                        tra.Commit();
                        sw.Stop();
                        System.Diagnostics.Trace.WriteLine("Add2DB  " + nr.ToString() + " eddb systems: " + sw.Elapsed.TotalSeconds.ToString("0.000s"));
                    }
                    catch (Exception ex)
                    {
                        tra.Rollback();
                        System.Diagnostics.Trace.WriteLine("Add2DB error: {0}" + ex.Message);
                        throw;
                    }
                }
            }

            return(true);
        }