From dbdb3b9e47535af12e6535d93e271dc196d09698 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 27 Dec 2022 17:55:00 +0100 Subject: [PATCH] =?UTF-8?q?Import=20von=20Bastis=20Zonen,=20Laden=20und=20?= =?UTF-8?q?Speichern,=20Reihenfolge=20der=20Zonen=20(Sequence)=20=C3=A4nde?= =?UTF-8?q?rn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIS/AISAdmin/Main.Designer.cs | 61 +++++----- AIS/AISAdmin/Main.cs | 132 +++++++++++++--------- AIS/SQL/ais_initial.db | Bin 40960 -> 40960 bytes AIS/bsmd.AIS2Service/AIS_SQLiteStorage.cs | 14 +-- AIS/bsmd.AIS2Service/MonitorZone.cs | 86 +++++++++++++- AIS/bsmd.AIS2Service/Util.cs | 8 +- 6 files changed, 206 insertions(+), 95 deletions(-) diff --git a/AIS/AISAdmin/Main.Designer.cs b/AIS/AISAdmin/Main.Designer.cs index 70c35312..e97243a3 100644 --- a/AIS/AISAdmin/Main.Designer.cs +++ b/AIS/AISAdmin/Main.Designer.cs @@ -35,14 +35,13 @@ this.buttonDeleteGroup = new System.Windows.Forms.Button(); this.groupBoxZones = new System.Windows.Forms.GroupBox(); this.checkBoxZoneActive = new System.Windows.Forms.CheckBox(); - this.buttonSaveZone = new System.Windows.Forms.Button(); this.textBoxZone = new System.Windows.Forms.TextBox(); this.buttonDeleteZone = new System.Windows.Forms.Button(); this.buttonEditZone = new System.Windows.Forms.Button(); - this.buttonImportZone = new System.Windows.Forms.Button(); this.buttonZoneDown = new System.Windows.Forms.Button(); this.buttonZoneUp = new System.Windows.Forms.Button(); this.listBoxZones = new System.Windows.Forms.ListBox(); + this.buttonImportZone = new System.Windows.Forms.Button(); this.groupBoxAssignments = new System.Windows.Forms.GroupBox(); this.textBoxGroup = new System.Windows.Forms.TextBox(); this.buttonSaveGroup = new System.Windows.Forms.Button(); @@ -64,7 +63,7 @@ this.comboBoxGroup.FormattingEnabled = true; this.comboBoxGroup.Location = new System.Drawing.Point(63, 11); this.comboBoxGroup.Name = "comboBoxGroup"; - this.comboBoxGroup.Size = new System.Drawing.Size(137, 23); + this.comboBoxGroup.Size = new System.Drawing.Size(180, 23); this.comboBoxGroup.TabIndex = 1; this.comboBoxGroup.SelectedIndexChanged += new System.EventHandler(this.comboBoxGroup_SelectedIndexChanged); // @@ -92,11 +91,9 @@ // groupBoxZones // this.groupBoxZones.Controls.Add(this.checkBoxZoneActive); - this.groupBoxZones.Controls.Add(this.buttonSaveZone); this.groupBoxZones.Controls.Add(this.textBoxZone); this.groupBoxZones.Controls.Add(this.buttonDeleteZone); this.groupBoxZones.Controls.Add(this.buttonEditZone); - this.groupBoxZones.Controls.Add(this.buttonImportZone); this.groupBoxZones.Controls.Add(this.buttonZoneDown); this.groupBoxZones.Controls.Add(this.buttonZoneUp); this.groupBoxZones.Controls.Add(this.listBoxZones); @@ -110,27 +107,18 @@ // checkBoxZoneActive // this.checkBoxZoneActive.AutoSize = true; - this.checkBoxZoneActive.Location = new System.Drawing.Point(237, 27); + this.checkBoxZoneActive.Location = new System.Drawing.Point(401, 29); this.checkBoxZoneActive.Name = "checkBoxZoneActive"; this.checkBoxZoneActive.Size = new System.Drawing.Size(59, 19); this.checkBoxZoneActive.TabIndex = 11; this.checkBoxZoneActive.Text = "Active"; this.checkBoxZoneActive.UseVisualStyleBackColor = true; - // - // buttonSaveZone - // - this.buttonSaveZone.Enabled = false; - this.buttonSaveZone.Image = global::AISAdmin.Properties.Resources.disk_blue; - this.buttonSaveZone.Location = new System.Drawing.Point(733, 22); - this.buttonSaveZone.Name = "buttonSaveZone"; - this.buttonSaveZone.Size = new System.Drawing.Size(37, 31); - this.buttonSaveZone.TabIndex = 10; - this.buttonSaveZone.UseVisualStyleBackColor = true; - this.buttonSaveZone.Click += new System.EventHandler(this.buttonSaveZone_Click); + this.checkBoxZoneActive.CheckedChanged += new System.EventHandler(this.checkBoxZoneActive_CheckedChanged); // // textBoxZone // - this.textBoxZone.Location = new System.Drawing.Point(525, 27); + this.textBoxZone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxZone.Location = new System.Drawing.Point(568, 25); this.textBoxZone.Name = "textBoxZone"; this.textBoxZone.ReadOnly = true; this.textBoxZone.Size = new System.Drawing.Size(202, 23); @@ -138,9 +126,10 @@ // // buttonDeleteZone // + this.buttonDeleteZone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonDeleteZone.Enabled = false; this.buttonDeleteZone.Image = global::AISAdmin.Properties.Resources.delete; - this.buttonDeleteZone.Location = new System.Drawing.Point(482, 22); + this.buttonDeleteZone.Location = new System.Drawing.Point(525, 20); this.buttonDeleteZone.Name = "buttonDeleteZone"; this.buttonDeleteZone.Size = new System.Drawing.Size(37, 31); this.buttonDeleteZone.TabIndex = 8; @@ -149,30 +138,21 @@ // // buttonEditZone // + this.buttonEditZone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonEditZone.Enabled = false; this.buttonEditZone.Image = global::AISAdmin.Properties.Resources.pencil; - this.buttonEditZone.Location = new System.Drawing.Point(439, 22); + this.buttonEditZone.Location = new System.Drawing.Point(482, 20); this.buttonEditZone.Name = "buttonEditZone"; this.buttonEditZone.Size = new System.Drawing.Size(37, 31); this.buttonEditZone.TabIndex = 6; this.buttonEditZone.UseVisualStyleBackColor = true; this.buttonEditZone.Click += new System.EventHandler(this.buttonEditZone_Click); // - // buttonImportZone - // - this.buttonImportZone.Image = global::AISAdmin.Properties.Resources.import2; - this.buttonImportZone.Location = new System.Drawing.Point(396, 22); - this.buttonImportZone.Name = "buttonImportZone"; - this.buttonImportZone.Size = new System.Drawing.Size(37, 31); - this.buttonImportZone.TabIndex = 5; - this.buttonImportZone.UseVisualStyleBackColor = true; - this.buttonImportZone.Click += new System.EventHandler(this.buttonImportZone_Click); - // // buttonZoneDown // this.buttonZoneDown.Enabled = false; this.buttonZoneDown.Image = global::AISAdmin.Properties.Resources.arrow_down_green; - this.buttonZoneDown.Location = new System.Drawing.Point(194, 145); + this.buttonZoneDown.Location = new System.Drawing.Point(358, 145); this.buttonZoneDown.Name = "buttonZoneDown"; this.buttonZoneDown.Size = new System.Drawing.Size(37, 31); this.buttonZoneDown.TabIndex = 4; @@ -183,7 +163,7 @@ // this.buttonZoneUp.Enabled = false; this.buttonZoneUp.Image = global::AISAdmin.Properties.Resources.arrow_up_green; - this.buttonZoneUp.Location = new System.Drawing.Point(194, 22); + this.buttonZoneUp.Location = new System.Drawing.Point(358, 22); this.buttonZoneUp.Name = "buttonZoneUp"; this.buttonZoneUp.Size = new System.Drawing.Size(37, 31); this.buttonZoneUp.TabIndex = 3; @@ -197,8 +177,19 @@ this.listBoxZones.ItemHeight = 15; this.listBoxZones.Location = new System.Drawing.Point(6, 22); this.listBoxZones.Name = "listBoxZones"; - this.listBoxZones.Size = new System.Drawing.Size(182, 154); + this.listBoxZones.Size = new System.Drawing.Size(346, 154); this.listBoxZones.TabIndex = 0; + this.listBoxZones.SelectedIndexChanged += new System.EventHandler(this.listBoxZones_SelectedIndexChanged); + // + // buttonImportZone + // + this.buttonImportZone.Image = global::AISAdmin.Properties.Resources.import2; + this.buttonImportZone.Location = new System.Drawing.Point(702, 6); + this.buttonImportZone.Name = "buttonImportZone"; + this.buttonImportZone.Size = new System.Drawing.Size(37, 31); + this.buttonImportZone.TabIndex = 5; + this.buttonImportZone.UseVisualStyleBackColor = true; + this.buttonImportZone.Click += new System.EventHandler(this.buttonImportZone_Click); // // groupBoxAssignments // @@ -221,7 +212,7 @@ // this.buttonSaveGroup.Enabled = false; this.buttonSaveGroup.Image = global::AISAdmin.Properties.Resources.disk_blue; - this.buttonSaveGroup.Location = new System.Drawing.Point(501, 6); + this.buttonSaveGroup.Location = new System.Drawing.Point(745, 6); this.buttonSaveGroup.Name = "buttonSaveGroup"; this.buttonSaveGroup.Size = new System.Drawing.Size(37, 31); this.buttonSaveGroup.TabIndex = 5; @@ -238,6 +229,7 @@ this.Controls.Add(this.groupBoxAssignments); this.Controls.Add(this.groupBoxZones); this.Controls.Add(this.buttonDeleteGroup); + this.Controls.Add(this.buttonImportZone); this.Controls.Add(this.buttonNewGroup); this.Controls.Add(this.comboBoxGroup); this.Controls.Add(this.label1); @@ -266,7 +258,6 @@ private Button buttonZoneUp; private TextBox textBoxGroup; private Button buttonSaveGroup; - private Button buttonSaveZone; private TextBox textBoxZone; private Button buttonDeleteZone; private Button buttonEditZone; diff --git a/AIS/AISAdmin/Main.cs b/AIS/AISAdmin/Main.cs index ccc1df40..ebaa41b2 100644 --- a/AIS/AISAdmin/Main.cs +++ b/AIS/AISAdmin/Main.cs @@ -7,8 +7,7 @@ namespace AISAdmin public partial class Main : Form { private AIS_SQLiteStorage? _storage; - private BindingList? _monitorGroups = new BindingList(); - private BindingList? _monitorZones; + private BindingList? _monitorGroups = new(); private MonitorGroup? _currentGroup; public Main() @@ -19,39 +18,50 @@ namespace AISAdmin private void buttonZoneUp_Click(object sender, EventArgs e) { - + MonitorZone mz = (MonitorZone)this.listBoxZones.SelectedItem; + int i = this.listBoxZones.SelectedIndex; + BindingList zones = (BindingList)this.listBoxZones.DataSource; + if (mz != null && (i > 0)) + { + MonitorZone prevZone = zones[i - 1]; + mz.Sequence -= 1; + prevZone.Sequence += 1; + zones[i - 1] = mz; + zones[i] = prevZone; + this.listBoxZones.SelectedIndex = i - 1; + } } private void buttonZoneDown_Click(object sender, EventArgs e) { - + MonitorZone mz = (MonitorZone)this.listBoxZones.SelectedItem; + int i = this.listBoxZones.SelectedIndex; + BindingList zones = (BindingList) this.listBoxZones.DataSource; + if (mz != null && (i < (zones.Count - 1))) + { + MonitorZone nextZone = zones[i + 1]; + mz.Sequence += 1; + nextZone.Sequence -= 1; + zones[i + 1] = mz; + zones[i] = nextZone; + this.listBoxZones.SelectedIndex = i + 1; + } } private void buttonImportZone_Click(object sender, EventArgs e) { - using (OpenFileDialog ofd = new OpenFileDialog()) + using OpenFileDialog ofd = new(); + ofd.Filter = "Google Earth KML files (*.kml)|*.kml|All files (*.*)|*.*"; + ofd.RestoreDirectory = true; + ofd.Multiselect = false; + if (ofd.ShowDialog() == DialogResult.OK) { - ofd.Filter = "Google Earth KML files (*.kml)|*.kml|All files (*.*)|*.*"; - ofd.RestoreDirectory = true; - ofd.Multiselect = true; - if (ofd.ShowDialog() == DialogResult.OK) - { - for (int i = 0, seq = this._monitorGroups.Count; i < ofd.FileNames.Length; i++, seq++) - { - MonitorZone mz = MonitorZone.ImportFromKML(ofd.FileNames[i]); - if(mz != null) - { - mz.MonitorGroupId = this._currentGroup.Id; - mz.Sequence = seq; - _storage.Save(mz); - foreach(GeoPoint gp in mz.Vertices) - { - gp.MonitorZoneId = mz.Id; - _storage.Save(gp); - } - } - } - } + _monitorGroups = new BindingList(MonitorGroup.LoadGroups(ofd.FileName)); + this.comboBoxGroup.DataSource = _monitorGroups; + if (_monitorGroups.Count > 0) + this.comboBoxGroup.SelectedIndex = 0; + this.buttonSaveGroup.Enabled = _monitorGroups.Count > 0; + this.listBoxZones.Enabled = _monitorGroups.Count > 0; } } @@ -65,11 +75,6 @@ namespace AISAdmin } - private void buttonSaveZone_Click(object sender, EventArgs e) - { - - } - private void buttonNewGroup_Click(object sender, EventArgs e) { this.textBoxGroup.ReadOnly = false; @@ -85,18 +90,19 @@ namespace AISAdmin private void buttonSaveGroup_Click(object sender, EventArgs e) { - if(this.textBoxGroup.Text != null) + // save everything + foreach(MonitorGroup mg in this._monitorGroups) { - string groupName = this.textBoxGroup.Text.Trim(); - if(groupName.Length > 0) + this._storage?.Save(mg); + foreach(MonitorZone mz in mg.Zones) { - _currentGroup.Name = groupName; - if(_storage.Save(_currentGroup)) + if (mz.MonitorGroupId < 1) mz.MonitorGroupId = mg.Id; + this._storage?.Save(mz); + + foreach(GeoPoint vertex in mz.Vertices) { - if ((bool)!(_monitorGroups?.Contains(_currentGroup))) - this._monitorGroups.Add(_currentGroup); - - this.comboBoxGroup.SelectedItem = _currentGroup; + if(vertex.MonitorZoneId < 1) vertex.MonitorZoneId = mz.Id; + this._storage?.Save(vertex); } } } @@ -106,27 +112,30 @@ namespace AISAdmin { _storage = new AIS_SQLiteStorage(null); _monitorGroups = new BindingList(_storage.LoadGroups()); - _monitorZones = new BindingList(_storage.LoadMonitorZones()); + List zones = _storage.LoadMonitorZones(); + foreach(MonitorGroup mg in _monitorGroups) + { + foreach(MonitorZone mz in zones) + { + if (mz.MonitorGroupId == mg.Id) + mg.Zones.Add(mz); + } + } this.comboBoxGroup.DataSource = _monitorGroups; this.comboBoxGroup.DisplayMember = "Name"; if (_monitorGroups.Count > 0) this.comboBoxGroup.SelectedIndex = 0; + this.buttonSaveGroup.Enabled = _monitorGroups.Count > 0; + this.listBoxZones.Enabled = _monitorGroups.Count > 0; } private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) { _currentGroup = (MonitorGroup) this.comboBoxGroup.SelectedItem; if (_currentGroup != null) - { - this.textBoxGroup.Text = _currentGroup.Name; - List groupZones = new List(); - foreach(MonitorZone mZone in _monitorZones) - { - if (mZone.MonitorGroupId == _currentGroup.Id) - groupZones.Add(mZone); - } - groupZones.Sort(); - this.listBoxZones.DataSource = groupZones; + { + _currentGroup.Zones.Sort(); + this.listBoxZones.DataSource = new BindingList(_currentGroup.Zones); } else { @@ -135,6 +144,27 @@ namespace AISAdmin this.buttonSaveGroup.Enabled = false; this.textBoxGroup.ReadOnly = true; } + this.buttonZoneDown.Enabled = (this._currentGroup != null) && (this._currentGroup.Zones.Count > 1); + this.buttonZoneUp.Enabled = (this._currentGroup != null) && (this._currentGroup.Zones.Count > 1); + } + + private void checkBoxZoneActive_CheckedChanged(object sender, EventArgs e) + { + MonitorZone mz = (MonitorZone)this.listBoxZones.SelectedItem; + if (mz != null) + { + mz.Active = this.checkBoxZoneActive.Checked; + } + } + + private void listBoxZones_SelectedIndexChanged(object sender, EventArgs e) + { + MonitorZone mz = (MonitorZone) this.listBoxZones.SelectedItem; + if(mz != null) + { + this.checkBoxZoneActive.Checked = mz.Active; + this.textBoxZone.Text = mz.Name; + } } } } \ No newline at end of file diff --git a/AIS/SQL/ais_initial.db b/AIS/SQL/ais_initial.db index 844e6a3034f10d675b9c0041d3e2a29142488f41..56806f247ac2e6cc5ae943dc14f56fee22b05943 100644 GIT binary patch delta 210 zcmZoTz|?SnX@az%C<6ln7Z7s*F(VM0Pt-A16lKu!ujOUG#lXqBoSAPnpC?Zh_jHcy zT$4B}*p9I-XPvQGP=K3tayKilIr}X}J#iqRDXy>2*j(KtBgQVSstRP4Bqrsg=H};R zmgE=3SLNrSu-PXwa*9os;MhAkpIwQGOLOxvHW5Y^&Ju>doA0r!N${}nA7tRa!~cf= l68}MOB`3AGFefR#BsI4nz9cazCpF#>Lx9UU$kj2#RUyRD z$;VYe2}6Fe42RrgLG~>YoF$Ap;`;iGEsS8J;0iY%V-sOyX{-`t-+Yf + /// Da Basti nun eine Datei mit allen Elementen exportiert gibt es eine einzelne Funktion, die alles + /// importiert + /// + /// + /// + public static List LoadGroups(string filename) + { + List groups = new List(); + try + { + if (File.Exists(filename)) + { + XDocument kml = XDocument.Load(filename); + XNamespace ns = "http://www.opengis.net/kml/2.2"; + + foreach(XElement rootFolderNode in kml.Root.Element(ns + "Document").Element(ns + "Folder").Elements(ns + "Folder")) + { + MonitorGroup mg = new MonitorGroup(-1, rootFolderNode.Element(ns + "name").Value); + int sequence = 1; + foreach(XElement placemark in rootFolderNode.Elements(ns + "Placemark")) + { + MonitorZone mz = new MonitorZone(-1, placemark.Element(ns + "name").Value); + mz.Active = true; + mz.Sequence = sequence; + // now add all vertices + string[] vertices = placemark.Element(ns + "Polygon").Element(ns + "outerBoundaryIs").Element(ns + "LinearRing").Element(ns + "coordinates").Value.Split(' '); + for (int i = 0; i < vertices.Length - 1; i++) + { + string[] pointElems = vertices[i].Trim().Split(','); + if (pointElems.Length != 3) continue; + GeoPoint gp = new GeoPoint(-1); + gp.Lon = Double.Parse(pointElems[0], System.Globalization.NumberFormatInfo.InvariantInfo); + gp.Lat = Double.Parse(pointElems[1], System.Globalization.NumberFormatInfo.InvariantInfo); + mz.Vertices.Add(gp); + } + + mg.Zones.Add(mz); + sequence++; + } + + groups.Add(mg); + } + } + } + catch(Exception ex) + { + _log.Error(ex.ToString()); + } + return groups; + } + + #endregion + + #region public methods + + public override string ToString() + { + return this.Name; + } + + #endregion + } #endregion #region class MonitorZone - public class MonitorZone : DBEntity + public class MonitorZone : DBEntity, IComparable { #region fields @@ -100,6 +170,10 @@ namespace bsmd.AIS2Service public long MonitorGroupId { get; set; } + #endregion + + #region public static methods + public static MonitorZone ImportFromKML(string filename) { MonitorZone result = null; @@ -150,6 +224,16 @@ namespace bsmd.AIS2Service return result; } + public int CompareTo(MonitorZone other) + { + return this.Sequence.CompareTo(other.Sequence); + } + + public override string ToString() + { + return String.Format("{0} (Seq.:{1} #Vert.:{2}", this.Name, this.Sequence, this.Vertices.Count); + } + #endregion } diff --git a/AIS/bsmd.AIS2Service/Util.cs b/AIS/bsmd.AIS2Service/Util.cs index ee98981a..c56f22b8 100644 --- a/AIS/bsmd.AIS2Service/Util.cs +++ b/AIS/bsmd.AIS2Service/Util.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -24,6 +25,11 @@ namespace bsmd.AIS2Service flags = (T)(object)(flagsValue | flagValue); else flags = (T)(object)(flagsValue & (~flagValue)); - } + } + + public static string ToDotString(this double value) + { + return value.ToString(CultureInfo.GetCultureInfo("en-GB")); + } } }