diff --git a/SectorLister/SectorLister.Designer.cs b/SectorLister/SectorLister.Designer.cs index 9f6c377..175cdca 100644 --- a/SectorLister/SectorLister.Designer.cs +++ b/SectorLister/SectorLister.Designer.cs @@ -40,14 +40,22 @@ private void InitializeComponent() this.btnOutputDir = new System.Windows.Forms.Button(); this.progressBar = new System.Windows.Forms.ProgressBar(); this.chkAppend = new System.Windows.Forms.CheckBox(); + this.chkIsolate = new System.Windows.Forms.CheckBox(); + this.grpIsolate = new System.Windows.Forms.GroupBox(); + this.chkNeighbours = new System.Windows.Forms.CheckBox(); + this.chkChildren = new System.Windows.Forms.CheckBox(); + this.chkParents = new System.Windows.Forms.CheckBox(); + this.lstSystemNames = new System.Windows.Forms.ListView(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); ((System.ComponentModel.ISupportInitialize)(this.updnStart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.updnEnd)).BeginInit(); + this.grpIsolate.SuspendLayout(); this.SuspendLayout(); // // lblSectorName // this.lblSectorName.AutoSize = true; - this.lblSectorName.Location = new System.Drawing.Point(27, 15); + this.lblSectorName.Location = new System.Drawing.Point(24, 12); this.lblSectorName.Name = "lblSectorName"; this.lblSectorName.Size = new System.Drawing.Size(69, 13); this.lblSectorName.TabIndex = 0; @@ -56,15 +64,16 @@ private void InitializeComponent() // // txtSectorName // - this.txtSectorName.Location = new System.Drawing.Point(102, 12); + this.txtSectorName.Location = new System.Drawing.Point(99, 9); this.txtSectorName.Name = "txtSectorName"; - this.txtSectorName.Size = new System.Drawing.Size(174, 20); + this.txtSectorName.Size = new System.Drawing.Size(177, 20); this.txtSectorName.TabIndex = 1; + this.txtSectorName.TextChanged += new System.EventHandler(this.txtSectorName_TextChanged); // // lblStart // this.lblStart.AutoSize = true; - this.lblStart.Location = new System.Drawing.Point(67, 40); + this.lblStart.Location = new System.Drawing.Point(64, 292); this.lblStart.Name = "lblStart"; this.lblStart.Size = new System.Drawing.Size(29, 13); this.lblStart.TabIndex = 2; @@ -73,7 +82,7 @@ private void InitializeComponent() // // updnStart // - this.updnStart.Location = new System.Drawing.Point(102, 38); + this.updnStart.Location = new System.Drawing.Point(99, 290); this.updnStart.Maximum = new decimal(new int[] { 20000, 0, @@ -85,7 +94,7 @@ private void InitializeComponent() // // updnEnd // - this.updnEnd.Location = new System.Drawing.Point(102, 64); + this.updnEnd.Location = new System.Drawing.Point(99, 316); this.updnEnd.Maximum = new decimal(new int[] { 20000, 0, @@ -103,7 +112,7 @@ private void InitializeComponent() // lblEnd // this.lblEnd.AutoSize = true; - this.lblEnd.Location = new System.Drawing.Point(70, 66); + this.lblEnd.Location = new System.Drawing.Point(67, 318); this.lblEnd.Name = "lblEnd"; this.lblEnd.Size = new System.Drawing.Size(26, 13); this.lblEnd.TabIndex = 6; @@ -112,7 +121,7 @@ private void InitializeComponent() // // txtOutputDir // - this.txtOutputDir.Location = new System.Drawing.Point(102, 90); + this.txtOutputDir.Location = new System.Drawing.Point(99, 342); this.txtOutputDir.Name = "txtOutputDir"; this.txtOutputDir.Size = new System.Drawing.Size(140, 20); this.txtOutputDir.TabIndex = 7; @@ -120,7 +129,7 @@ private void InitializeComponent() // btnGenerate // this.btnGenerate.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnGenerate.Location = new System.Drawing.Point(12, 139); + this.btnGenerate.Location = new System.Drawing.Point(12, 391); this.btnGenerate.Name = "btnGenerate"; this.btnGenerate.Size = new System.Drawing.Size(264, 47); this.btnGenerate.TabIndex = 8; @@ -131,7 +140,7 @@ private void InitializeComponent() // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 93); + this.label1.Location = new System.Drawing.Point(9, 345); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(84, 13); this.label1.TabIndex = 9; @@ -141,7 +150,7 @@ private void InitializeComponent() // btnOutputDir // this.btnOutputDir.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnOutputDir.Location = new System.Drawing.Point(248, 89); + this.btnOutputDir.Location = new System.Drawing.Point(245, 341); this.btnOutputDir.Name = "btnOutputDir"; this.btnOutputDir.Size = new System.Drawing.Size(28, 20); this.btnOutputDir.TabIndex = 10; @@ -151,7 +160,7 @@ private void InitializeComponent() // // progressBar // - this.progressBar.Location = new System.Drawing.Point(12, 192); + this.progressBar.Location = new System.Drawing.Point(12, 444); this.progressBar.Name = "progressBar"; this.progressBar.Size = new System.Drawing.Size(264, 10); this.progressBar.TabIndex = 11; @@ -159,7 +168,7 @@ private void InitializeComponent() // chkAppend // this.chkAppend.AutoSize = true; - this.chkAppend.Location = new System.Drawing.Point(24, 116); + this.chkAppend.Location = new System.Drawing.Point(21, 368); this.chkAppend.Name = "chkAppend"; this.chkAppend.RightToLeft = System.Windows.Forms.RightToLeft.Yes; this.chkAppend.Size = new System.Drawing.Size(91, 17); @@ -167,29 +176,102 @@ private void InitializeComponent() this.chkAppend.Text = "Append to file"; this.chkAppend.UseVisualStyleBackColor = true; // + // chkIsolate + // + this.chkIsolate.AutoSize = true; + this.chkIsolate.Location = new System.Drawing.Point(24, 35); + this.chkIsolate.Name = "chkIsolate"; + this.chkIsolate.Size = new System.Drawing.Size(93, 17); + this.chkIsolate.TabIndex = 13; + this.chkIsolate.Text = "Isolate cube ?"; + this.chkIsolate.UseVisualStyleBackColor = true; + this.chkIsolate.CheckedChanged += new System.EventHandler(this.chkIsolate_CheckedChanged); + // + // grpIsolate + // + this.grpIsolate.Controls.Add(this.lstSystemNames); + this.grpIsolate.Controls.Add(this.chkNeighbours); + this.grpIsolate.Controls.Add(this.chkChildren); + this.grpIsolate.Controls.Add(this.chkParents); + this.grpIsolate.Location = new System.Drawing.Point(12, 35); + this.grpIsolate.Name = "grpIsolate"; + this.grpIsolate.Size = new System.Drawing.Size(264, 249); + this.grpIsolate.TabIndex = 15; + this.grpIsolate.TabStop = false; + // + // chkNeighbours + // + this.chkNeighbours.AutoSize = true; + this.chkNeighbours.Location = new System.Drawing.Point(144, 23); + this.chkNeighbours.Name = "chkNeighbours"; + this.chkNeighbours.Size = new System.Drawing.Size(80, 17); + this.chkNeighbours.TabIndex = 18; + this.chkNeighbours.Text = "Neighbours"; + this.chkNeighbours.UseVisualStyleBackColor = true; + this.chkNeighbours.CheckedChanged += new System.EventHandler(this.chkNeighbours_CheckedChanged); + // + // chkChildren + // + this.chkChildren.AutoSize = true; + this.chkChildren.Location = new System.Drawing.Point(74, 23); + this.chkChildren.Name = "chkChildren"; + this.chkChildren.Size = new System.Drawing.Size(64, 17); + this.chkChildren.TabIndex = 17; + this.chkChildren.Text = "Children"; + this.chkChildren.UseVisualStyleBackColor = true; + this.chkChildren.CheckedChanged += new System.EventHandler(this.chkChildren_CheckedChanged); + // + // chkParents + // + this.chkParents.AutoSize = true; + this.chkParents.Location = new System.Drawing.Point(6, 23); + this.chkParents.Name = "chkParents"; + this.chkParents.Size = new System.Drawing.Size(62, 17); + this.chkParents.TabIndex = 16; + this.chkParents.Text = "Parents"; + this.chkParents.UseVisualStyleBackColor = true; + this.chkParents.CheckedChanged += new System.EventHandler(this.chkParents_CheckedChanged); + // + // lstSystemNames + // + this.lstSystemNames.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1}); + this.lstSystemNames.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; + this.lstSystemNames.Location = new System.Drawing.Point(6, 46); + this.lstSystemNames.MultiSelect = false; + this.lstSystemNames.Name = "lstSystemNames"; + this.lstSystemNames.Size = new System.Drawing.Size(252, 197); + this.lstSystemNames.TabIndex = 19; + this.lstSystemNames.UseCompatibleStateImageBehavior = false; + this.lstSystemNames.View = System.Windows.Forms.View.Details; + // // SectorLister // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(291, 214); - this.Controls.Add(this.chkAppend); + this.ClientSize = new System.Drawing.Size(288, 468); + this.Controls.Add(this.chkIsolate); + this.Controls.Add(this.lblSectorName); this.Controls.Add(this.progressBar); - this.Controls.Add(this.btnOutputDir); + this.Controls.Add(this.chkAppend); + this.Controls.Add(this.lblStart); this.Controls.Add(this.label1); - this.Controls.Add(this.btnGenerate); - this.Controls.Add(this.txtOutputDir); this.Controls.Add(this.lblEnd); - this.Controls.Add(this.updnEnd); this.Controls.Add(this.updnStart); - this.Controls.Add(this.lblStart); + this.Controls.Add(this.btnGenerate); this.Controls.Add(this.txtSectorName); - this.Controls.Add(this.lblSectorName); + this.Controls.Add(this.btnOutputDir); + this.Controls.Add(this.updnEnd); + this.Controls.Add(this.txtOutputDir); + this.Controls.Add(this.grpIsolate); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "SectorLister"; - this.Text = "Sector Lister 1v2"; + this.Text = "Sector Lister 1v3"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.updnStart)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.updnEnd)).EndInit(); + this.grpIsolate.ResumeLayout(false); + this.grpIsolate.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -209,6 +291,13 @@ private void InitializeComponent() private System.Windows.Forms.Button btnOutputDir; private System.Windows.Forms.ProgressBar progressBar; private System.Windows.Forms.CheckBox chkAppend; + private System.Windows.Forms.CheckBox chkIsolate; + private System.Windows.Forms.GroupBox grpIsolate; + private System.Windows.Forms.CheckBox chkNeighbours; + private System.Windows.Forms.CheckBox chkChildren; + private System.Windows.Forms.CheckBox chkParents; + private System.Windows.Forms.ListView lstSystemNames; + private System.Windows.Forms.ColumnHeader columnHeader1; } } diff --git a/SectorLister/SectorLister.cs b/SectorLister/SectorLister.cs index 39b3d1a..31ec1ee 100644 --- a/SectorLister/SectorLister.cs +++ b/SectorLister/SectorLister.cs @@ -1,17 +1,23 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace SectorLister { public partial class SectorLister : Form { + private struct sectorPos + { + public int x; + public int y; + public int z; + public char code; + public int num; + } + + private sectorPos spTarget; + private String sTargetPrefix = ""; + public SectorLister() { InitializeComponent(); @@ -21,24 +27,59 @@ private void Form1_Load(object sender, EventArgs e) { // init output file to %UserProfile%\Desktop txtOutputDir.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + + // disable isolator + chkIsolate.Checked = false; + grpIsolate.Enabled = false; + + // resize listview column width + lstSystemNames.Columns[0].Width = lstSystemNames.Width - 24; } private void btnGenerate_Click(object sender, EventArgs e) { + // reset progress bar + progressBar.Value = 0; + String filename = txtOutputDir.Text + "\\ImportStars.txt"; using (System.IO.StreamWriter file = new System.IO.StreamWriter(filename, chkAppend.Checked)) { - int start = Decimal.ToInt32(updnStart.Value); - int end = Decimal.ToInt32(updnEnd.Value); - progressBar.Maximum = (end - start); - for (int i = start; i <= end; i++) + // single system ? + if (!chkIsolate.Checked) + { + int start = Decimal.ToInt32(updnStart.Value); + int end = Decimal.ToInt32(updnEnd.Value); + progressBar.Maximum = (end - start); + for (int i = start; i <= end; i++) + { + // write data + String line = txtSectorName.Text + "-" + i.ToString(); + file.WriteLine(line); + + // update progress bar + progressBar.Value = i - start; + } + } + else { - // write data - String line = txtSectorName.Text + i.ToString(); - file.WriteLine(line); + int start = Decimal.ToInt32(updnStart.Value); + int end = Decimal.ToInt32(updnEnd.Value); + int count = lstSystemNames.Items.Count; + progressBar.Maximum = count; + // loop through all sectors in the list + for (int j = 0; j < count; j++) + { + ListViewItem item = lstSystemNames.Items[j]; + for (int i = start; i <= end; i++) + { + // write data + String line2 = item.Text + "-" + i.ToString(); + file.WriteLine(line2); + } - // update progress bar - progressBar.Value = i - start; + // update progress bar + progressBar.Value = j + 1; + } } } } @@ -54,5 +95,234 @@ private void btnOutputDir_Click(object sender, EventArgs e) txtOutputDir.Text = dlg.SelectedPath; } } + + private void chkIsolate_CheckedChanged(object sender, EventArgs e) + { + grpIsolate.Enabled = chkIsolate.Checked; + } + + private void updateIsolationList() + { + // remove any existing names + lstSystemNames.Items.Clear(); + + // find parents ? + if (chkParents.Checked) + { + FindParents(spTarget.x, spTarget.y, spTarget.z, spTarget.code); + } + + // find children and/or neighbours ? + FindChildrenAndNeighbours(spTarget.x, spTarget.y, spTarget.z, spTarget.code, chkChildren.Checked, chkNeighbours.Checked); + } + + private void chkParents_CheckedChanged(object sender, EventArgs e) + { + updateIsolationList(); + } + + private void chkChildren_CheckedChanged(object sender, EventArgs e) + { + updateIsolationList(); + } + + private void chkNeighbours_CheckedChanged(object sender, EventArgs e) + { + updateIsolationList(); + } + + sectorPos FindPosition(char a, char b, char c, char code, int d) + { + int pos = (d * (26 * 26 * 26)) + ((c - 'A') * (26 * 26)) + ((b - 'A') * 26) + (a - 'A'); + sectorPos sp; + sp.x = pos % 128; + sp.y = (pos / 128) % 128; + sp.z = (pos / (128 * 128)) % 128; + sp.code = code; + sp.num = d; + return sp; + } + + private void FindParents(int x, int y, int z, char code) + { + code++; + int size = (int)Math.Pow(2, (int)'H' - (int)code); + while (size >= 1) + { + x /= 2; + y /= 2; + z /= 2; + AddSectorName(x, y, z, code++); + size /= 2; + } + } + + void FindChildrenAndNeighbours(int x, int y, int z, char code, bool bFindChildren, bool bFindNeighbours) + { + int x0 = x, y0 = y, z0 = z, code0 = code; + int size = 1; + int max = (int)Math.Pow(2, (int)'H' - ((int)code + 1)); + while (code > 'A') // ignore A cubes ... otherwise use >= 'A' + { + max *= 2; + for (int z2 = -1; z2 < (size + 1); z2++) + { + // outside the target cube ? + // if so, ignore if not searching for neighbours + if (!bFindNeighbours && + ((z2 < 0) || (z2 >= size))) + continue; + + // outside the child cube range ? + if (((z2 + z) < 0) || ((z2 + z) >= max)) + continue; + + for (int y2 = -1; y2 < (size + 1); y2++) + { + // outside the target cube ? + // if so, ignore if not searching for neighbours + if (!bFindNeighbours && + ((y2 < 0) || (y2 >= size))) + continue; + + // outside the child cube range ? + if (((y2 + y) < 0) || ((y2 + y) >= max)) + continue; + + for (int x2 = -1; x2 < (size + 1); x2++) + { + // the target cube ? + // if so, always ignore + if ((code0 == code) && + (x0 == (x2 + x)) && + (y0 == (y2 + y)) && + (z0 == (z2 + z))) + continue; + + // outside the target cube ? + // if so, ignore if not searching for neighbours + if (!bFindNeighbours && + ((x2 < 0) || (x2 >= size))) + continue; + + // outside the child cube range ? + if (((x2 + x) < 0) || ((x2 + x) >= max)) + continue; + + // within the target cube ? + // if so, ignore if not searching for children + if (!bFindChildren && + (x2 >= 0) && (x2 < size) && + (y2 >= 0) && (y2 < size) && + (z2 >= 0) && (z2 < size)) + continue; + + AddSectorName(x2 + x, y2 + y, z2 + z, code); + } + } + } + + size *= 2; + x *= 2; + y *= 2; + z *= 2; + code--; + } + } + + void AddSectorName(int x, int y, int z, char code) + { + int location = (z * (128 * 128)) + (y * 128) + x; + int a = location % 26; + int b = (location / 26) % 26; + int c = (location / (26 * 26)) % 26; + int d = location / (26 * 26 * 26); + + String s = Char.ToString((char)(a + (int)'A')) + Char.ToString((char)(b + (int)'A')) + "-" + Char.ToString((char)(c + (int)'A')) + " " + code; + if (d != 0) + s += d.ToString(); + + lstSystemNames.Items.Add(sTargetPrefix + " " + s); + } + + private void txtSectorName_TextChanged(object sender, EventArgs e) + { + // target name format:- + // AB-C D<0,1,2 or 3 digit num> + + // Examples:- + // EOL PROU AA-A D + // Plaa Aescs KW-U b16 + // Tegnae RD-T e3 + + // reset target + spTarget.x = 0; + spTarget.y = 0; + spTarget.z = 0; + spTarget.code = 'A'; + spTarget.num = 0; + + // assume name is invalid + txtSectorName.BackColor = Color.Red; + + int len = txtSectorName.TextLength; + if (len < 8) + return; + + // find penultimate space + int nPos = txtSectorName.Text.LastIndexOf(' '); + if ((nPos == -1) || (nPos == 0)) + return; + nPos = txtSectorName.Text.LastIndexOf(' ', nPos - 1); + if ((nPos == -1) || ((len - nPos) < 7)) + return; + + // extract prefix + String sPrefix = txtSectorName.Text.Substring(0, nPos).Trim(); + if (sPrefix.Length == 0) + return; + + // extract 'A', 'B', '-', 'C', ' ', 'D' + nPos++; + Char a = Char.ToUpper(txtSectorName.Text[nPos++]); + if (!Char.IsLetter(a)) + return; + Char b = Char.ToUpper(txtSectorName.Text[nPos++]); + if (!Char.IsLetter(b)) + return; + if (txtSectorName.Text[nPos++] != '-') + return; + Char c = Char.ToUpper(txtSectorName.Text[nPos++]); + if (!Char.IsLetter(c)) + return; + if (txtSectorName.Text[nPos++] != ' ') + return; + Char d = Char.ToUpper(txtSectorName.Text[nPos++]); + if (!Char.IsLetter(d)) + return; + + // check for optional + int nNum = 0; + if (nPos < len) + { + while (nPos < len) + { + Char n = txtSectorName.Text[nPos++]; + if (!Char.IsDigit(n)) + return; + nNum = (nNum * 10) + (n - '0'); + } + + // invalid number ? + if (nNum > 119) + return; + } + + // seems valid + spTarget = FindPosition(a, b, c, d, nNum); + sTargetPrefix = sPrefix; + txtSectorName.BackColor = SystemColors.Window; + } } } +