diff --git a/ProjectPlane/ProjectPlane/DrawingObject.cs b/ProjectPlane/ProjectPlane/DrawingObject.cs
index 18e6766..d228a40 100644
--- a/ProjectPlane/ProjectPlane/DrawingObject.cs
+++ b/ProjectPlane/ProjectPlane/DrawingObject.cs
@@ -36,5 +36,11 @@ namespace ProjectPlane
{
_plane.DrawTransport(g);
}
+
+ public string GetInfo() => _plane?.GetDataForSave();
+ public static IDrawingObject Create(string data) => new DrawingObject(data.CreateDrawingPlane());
+
}
+
}
+
diff --git a/ProjectPlane/ProjectPlane/ExtentionPlane.cs b/ProjectPlane/ProjectPlane/ExtentionPlane.cs
new file mode 100644
index 0000000..b8199f0
--- /dev/null
+++ b/ProjectPlane/ProjectPlane/ExtentionPlane.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectPlane
+{
+ internal static class ExtentionPlane
+ {
+
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly char _separatorForObject = ':';
+ ///
+ /// Создание объекта из строки
+ ///
+ ///
+ ///
+ public static DrawingPlane CreateDrawingPlane(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ if (strs.Length == 3)
+ {
+ return new DrawingPlane(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
+ }
+ if (strs.Length == 6)
+ {
+ return new DrawingWarPlane(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
+ Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
+ Convert.ToBoolean(strs[5]));
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ ///
+ ///
+ public static string GetDataForSave(this DrawingPlane drawingplane)
+ {
+ var plane = drawingplane.Plane;
+ var str =
+ $"{plane.Speed}{_separatorForObject}{plane.Weight}{_separatorForObject}{plane.BodyColor.Name}";
+ if (plane is not EntityWarPlane warPlane)
+ {
+ return str;
+ }
+ return
+ $"{str}{_separatorForObject}{warPlane.DopColor.Name}{_separatorForObject}{warPlane.extraCell}" +
+ $"{_separatorForObject}{warPlane.SuperTurbine}";
+ }
+
+ }
+}
diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs
index 239d1ca..7a40ffc 100644
--- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs
+++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs
@@ -46,9 +46,16 @@
this.ButtonAddMap = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
+ this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// groupBoxTools
@@ -64,9 +71,9 @@
this.groupBoxTools.Controls.Add(this.buttonAddPlane);
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBoxTools.Location = new System.Drawing.Point(680, 0);
+ this.groupBoxTools.Location = new System.Drawing.Point(680, 24);
this.groupBoxTools.Name = "groupBoxTools";
- this.groupBoxTools.Size = new System.Drawing.Size(204, 590);
+ this.groupBoxTools.Size = new System.Drawing.Size(204, 566);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools";
@@ -76,7 +83,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(133, 529);
+ this.buttonRight.Location = new System.Drawing.Point(133, 505);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(50, 49);
this.buttonRight.TabIndex = 14;
@@ -88,7 +95,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(77, 529);
+ this.buttonDown.Location = new System.Drawing.Point(77, 505);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(50, 49);
this.buttonDown.TabIndex = 13;
@@ -100,7 +107,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(21, 529);
+ this.buttonLeft.Location = new System.Drawing.Point(21, 505);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(50, 49);
this.buttonLeft.TabIndex = 12;
@@ -112,7 +119,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(77, 472);
+ this.buttonUp.Location = new System.Drawing.Point(77, 448);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(50, 49);
this.buttonUp.TabIndex = 11;
@@ -234,12 +241,50 @@
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(680, 590);
+ this.pictureBox.Size = new System.Drawing.Size(680, 566);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
+ // menuStrip
+ //
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.fileToolStripMenuItem});
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(884, 24);
+ this.menuStrip.TabIndex = 2;
+ this.menuStrip.Text = "menuStrip1";
+ //
+ // fileToolStripMenuItem
+ //
+ this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.saveToolStripMenuItem,
+ this.loadToolStripMenuItem});
+ this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
+ this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
+ this.fileToolStripMenuItem.Text = "File";
+ //
+ // saveToolStripMenuItem
+ //
+ this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
+ this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.saveToolStripMenuItem.Text = "Save";
+ this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
+ //
+ // loadToolStripMenuItem
+ //
+ this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
+ this.loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.loadToolStripMenuItem.Text = "Load";
+ this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
+ //
+ // openFileDialog
+ //
+ this.openFileDialog.FileName = "openFileDialog1";
+ this.openFileDialog.Filter = "text file | *.txt";
+ //
// FormMapWithSetPlanes
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -247,6 +292,8 @@
this.ClientSize = new System.Drawing.Size(884, 590);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
this.Name = "FormMapWithSetPlanes";
this.Text = "Map with object sets";
this.groupBoxTools.ResumeLayout(false);
@@ -254,7 +301,10 @@
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -277,5 +327,11 @@
private Button buttonDown;
private Button buttonLeft;
private Button buttonUp;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem fileToolStripMenuItem;
+ private ToolStripMenuItem saveToolStripMenuItem;
+ private ToolStripMenuItem loadToolStripMenuItem;
+ private OpenFileDialog openFileDialog;
+ private SaveFileDialog saveFileDialog;
}
}
\ No newline at end of file
diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs
index 619fb67..aa927a9 100644
--- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs
+++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs
@@ -231,5 +231,37 @@ namespace ProjectPlane
}
}
+ private void loadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_mapsCollection.LoadData(openFileDialog.FileName))
+ {
+ MessageBox.Show("Succesfull loading", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Loading failed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ ReloadMaps();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ }
+
+ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (saveFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_mapsCollection.SaveData(saveFileDialog.FileName))
+ {
+ MessageBox.Show("Succesfull saving", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Savingfailed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ }
+ }
}
}
diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx
index f298a7b..1d824c7 100644
--- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx
+++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx
@@ -57,4 +57,13 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 125, 17
+
+
+ 258, 17
+
\ No newline at end of file
diff --git a/ProjectPlane/ProjectPlane/FormPlaneConfig.cs b/ProjectPlane/ProjectPlane/FormPlaneConfig.cs
index 72a7bce..71897fb 100644
--- a/ProjectPlane/ProjectPlane/FormPlaneConfig.cs
+++ b/ProjectPlane/ProjectPlane/FormPlaneConfig.cs
@@ -23,6 +23,8 @@ namespace ProjectPlane
///
/// Конструктор
///
+
+ delegate void MessageHandler(string message);
public FormPlaneConfig()
{
InitializeComponent();
diff --git a/ProjectPlane/ProjectPlane/IDrawingObject.cs b/ProjectPlane/ProjectPlane/IDrawingObject.cs
index 7e27543..097c15a 100644
--- a/ProjectPlane/ProjectPlane/IDrawingObject.cs
+++ b/ProjectPlane/ProjectPlane/IDrawingObject.cs
@@ -36,5 +36,12 @@ namespace ProjectPlane
///
///
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
+
+ ///
+ /// Получение информации по объекту
+ ///
+ ///
+ string GetInfo();
+
}
}
diff --git a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs
index 1ded118..d03b30f 100644
--- a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs
+++ b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs
@@ -108,6 +108,31 @@ namespace ProjectPlane
return new(_pictureWidth, _pictureHeight);
}
///
+ /// Получение данных в виде строки
+ ///
+ ///
+ ///
+ public string GetData(char separatorType, char separatorData)
+ {
+ string data = $"{_map.GetType().Name}{separatorType}";
+ foreach (var car in _setPlanes.GetPlanes())
+ {
+ data += $"{car.GetInfo()}{separatorData}";
+ }
+ return data;
+ }
+ ///
+ /// Загрузка списка из массива строк
+ ///
+ ///
+ public void LoadData(string[] records)
+ {
+ foreach (var rec in records)
+ {
+ _setPlanes.Insert(DrawingObject.Create(rec) as T);
+ }
+ }
+ ///
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
///
private void Shaking()
diff --git a/ProjectPlane/ProjectPlane/MapsCollection.cs b/ProjectPlane/ProjectPlane/MapsCollection.cs
index bab6984..891400b 100644
--- a/ProjectPlane/ProjectPlane/MapsCollection.cs
+++ b/ProjectPlane/ProjectPlane/MapsCollection.cs
@@ -1,4 +1,5 @@
-namespace ProjectPlane
+using System.Text;
+namespace ProjectPlane
{
///
/// Класс для хранения коллекции карт
@@ -8,7 +9,7 @@
///
/// Словарь (хранилище) с картами
///
- readonly Dictionary> _mapStorages;
+ readonly Dictionary> _mapStorages;
///
/// Возвращение списка названий карт
///
@@ -26,9 +27,18 @@
///
///
///
+ /// ///
+ /// Разделитель для записи информации по элементу словаря в файл
+ ///
+ private readonly char separatorDict = '|';
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly char separatorData = ';';
+
public MapsCollection(int pictureWidth, int pictureHeight)
{
- _mapStorages = new Dictionary>();
+ _mapStorages = new Dictionary>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@@ -40,7 +50,7 @@
public void AddMap(string name, AbstractMap map)
{
if (!_mapStorages.ContainsKey(name))
- _mapStorages.Add(name, new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages.Add(name, new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map));
}
///
/// Удаление карты
@@ -56,7 +66,7 @@
///
///
///
- public MapWithSetPlanesGeneric this[string ind]
+ public MapWithSetPlanesGeneric this[string ind]
{
get
{
@@ -64,5 +74,79 @@
return null;
}
}
+ ///
+ /// Метод записи информации в файл
+ ///
+ /// Строка, которую следует записать
+ /// Поток для записи
+ private static void WriteToFile(string text, FileStream stream)
+ {
+ byte[] info = new UTF8Encoding(true).GetBytes(text);
+ stream.Write(info, 0, info.Length);
+ }
+ public bool SaveData(string filename)
+ {
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+ using (FileStream fs = new(filename, FileMode.Create))
+ using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
+ {
+ sw.WriteLine("MapsCollection");
+ foreach (var storage in _mapStorages)
+ {
+
+ sw.WriteLine(
+ $"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"
+ );
+ }
+ }
+ return true;
+ }
+
+
+ ///
+ /// Загрузка нформации по автомобилям на парковках из файла
+ ///
+ ///
+ ///
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ string bufferTextFromFile = "";
+ using (FileStream fs = new(filename, FileMode.Open))
+ using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
+ {
+ string curLine = sr.ReadLine();
+
+ if (!curLine.Contains("MapsCollection"))
+ {
+ return false;
+ }
+
+ _mapStorages.Clear();
+ while ((curLine = sr.ReadLine()) != null)
+ {
+ var elem = curLine.Split(separatorDict);
+ AbstractMap map = null;
+ switch (elem[1])
+ {
+ case "SimpleMap":
+ map = new SimpleMap();
+ break;
+ case "SkyMap":
+ map = new SkyMap();
+ break;
+ }
+ _mapStorages.Add(elem[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
+ }
+ return true;
+ }
+ }
}
}
\ No newline at end of file