diff --git a/src/EasyEPlanner.csproj b/src/EasyEPlanner.csproj
index ece87cec..893f1f18 100644
--- a/src/EasyEPlanner.csproj
+++ b/src/EasyEPlanner.csproj
@@ -114,6 +114,7 @@
+
diff --git a/src/Main/AddInModule.cs b/src/Main/AddInModule.cs
index 9ba442bd..a1143e87 100644
--- a/src/Main/AddInModule.cs
+++ b/src/Main/AddInModule.cs
@@ -71,11 +71,17 @@ public bool OnInitGui()
false, false);
menuID = oMenu.AddMenuItem(
- "Импорт ICP-CON проекта",
+ "Импорт ICP CON проекта",
nameof(ImportIcpWagoProject),
- "Импорт ICP-CON проекта", menuID, 1,
+ "Импорт ICP CON проекта", menuID, 1,
true, false);
+ menuID = oMenu.AddMenuItem(
+ "Создать файл переименования старых устройств",
+ nameof(ImportIcpCreateRenamingMap),
+ "Создать файл переименования старых устройств", menuID, 1,
+ false, false);
+
menuID = oMenu.AddMenuItem(
"Модифицировать базу каналов",
nameof(ModifyIcpChbase),
diff --git a/src/Main/ImportIcpCreateRenamingMap.cs b/src/Main/ImportIcpCreateRenamingMap.cs
new file mode 100644
index 00000000..9239486d
--- /dev/null
+++ b/src/Main/ImportIcpCreateRenamingMap.cs
@@ -0,0 +1,83 @@
+using EasyEPlanner.ProjectImportICP;
+using Eplan.EplApi.ApplicationFramework;
+using Eplan.EplApi.DataModel;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace EasyEPlanner
+{
+ [ExcludeFromCodeCoverage]
+ public class ImportIcpCreateRenamingMap : IEplAction
+ {
+ ~ImportIcpCreateRenamingMap() { }
+
+ public bool Execute(ActionCallingContext oActionCallingContext)
+ {
+ try
+ {
+ Project currentProject = EProjectManager.GetInstance()
+ .GetCurrentPrj();
+ if (currentProject == null)
+ {
+ MessageBox.Show("Нет открытого проекта!", "EPlaner",
+ MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ return true;
+ }
+
+ var data = ImportIcpWagoProject.GetMainWagoPluaData();
+ if (string.IsNullOrEmpty(data))
+ return true;
+
+ var devicesImporter = new DevicesImporter(currentProject, data, false);
+ devicesImporter.Import();
+
+ var devices = devicesImporter.ImportDevices;
+
+ var outputFileDialog = new SaveFileDialog
+ {
+ Title = "Сохранение карты переименования устройств",
+ Filter = "*.txt|*.txt",
+ FileName = $"{currentProject.ProjectName}_devs_renaming",
+ DefaultExt = "txt",
+ };
+
+ if (outputFileDialog.ShowDialog() == DialogResult.Cancel)
+ {
+ return true;
+ }
+
+ using (var writer = new StreamWriter(outputFileDialog.FileName, false))
+ {
+ foreach (var dev in devices)
+ {
+ writer.Write($"{dev.WagoType + dev.FullNumber,10} => {dev.Object,10} | {dev.Type, 3} | {dev.Number}\n");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
+
+ return true;
+ }
+
+ public bool OnRegister(ref string Name, ref int Ordinal)
+ {
+ Name = nameof(ImportIcpCreateRenamingMap);
+ Ordinal = 30;
+
+ return true;
+ }
+
+ public void GetActionProperties(ref ActionProperties actionProperties)
+ {
+ }
+ }
+}
diff --git a/src/Main/ImportIcpWagoProject.cs b/src/Main/ImportIcpWagoProject.cs
index d23f27a3..61788394 100644
--- a/src/Main/ImportIcpWagoProject.cs
+++ b/src/Main/ImportIcpWagoProject.cs
@@ -1,4 +1,5 @@
-using EasyEPlanner.ProjectImportICP;
+using BrightIdeasSoftware;
+using EasyEPlanner.ProjectImportICP;
using Eplan.EplApi.ApplicationFramework;
using Eplan.EplApi.DataModel;
using Eplan.EplApi.DataModel.EObjects;
@@ -21,6 +22,31 @@ public class ImportIcpWagoProject : IEplAction
{
~ImportIcpWagoProject() { }
+ public static string GetMainWagoPluaData()
+ {
+ var openFileDialog = new OpenFileDialog
+ {
+ Title = "Открытие main.wago.plua",
+ Filter = "main.wago.plua|main.wago.plua",
+ Multiselect = false
+ };
+
+ if (openFileDialog.ShowDialog() == DialogResult.Cancel)
+ {
+ return string.Empty;
+ }
+
+ var data = "";
+ using (var reader = new StreamReader(openFileDialog.FileName, EncodingDetector.DetectFileEncoding(openFileDialog.FileName), true))
+ {
+ // read main.wago.plua file data
+ data = reader.ReadToEnd();
+ }
+
+ return data;
+ }
+
+
public bool Execute(ActionCallingContext oActionCallingContext)
{
try
@@ -34,24 +60,9 @@ public bool Execute(ActionCallingContext oActionCallingContext)
return true;
}
- var openFileDialog = new OpenFileDialog
- {
- Title = "Открытие main.wago.plua",
- Filter = "main.wago.plua|main.wago.plua",
- Multiselect = false
- };
-
- if (openFileDialog.ShowDialog() == DialogResult.Cancel)
- {
+ var data = GetMainWagoPluaData();
+ if (string.IsNullOrEmpty(data))
return true;
- }
-
- var data = "";
- using (var reader = new StreamReader(openFileDialog.FileName, EncodingDetector.DetectFileEncoding(openFileDialog.FileName), true))
- {
- // read main.wago.plua file data
- data = reader.ReadToEnd();
- }
Logs.Show();
Logs.DisableButtons();
diff --git a/src/ProjectImportICP/DevicesImporter.cs b/src/ProjectImportICP/DevicesImporter.cs
index def93ca3..77626f22 100644
--- a/src/ProjectImportICP/DevicesImporter.cs
+++ b/src/ProjectImportICP/DevicesImporter.cs
@@ -216,10 +216,15 @@ public class DevicesImporter : IDevicesImporter
///
private readonly List tanks = new List();
+ ///
+ /// Генерировать страницы EPLAN с устройствами
+ ///
+ private readonly bool generatePages;
- public DevicesImporter(Project project, string wagoData)
+ public DevicesImporter(Project project, string wagoData, bool generatePages = true)
{
this.project = project;
+ this.generatePages = generatePages;
try
{
@@ -343,9 +348,12 @@ public IImportDevice ImportDevice(string type, string wagoType, int number, stri
public void GenerateDevicesPages()
{
- var s = new SetupDevicesNames();
- s.Init(ImportDevices);
- s.ShowDialog();
+ var setupRenaming = new SetupDevicesNames();
+ setupRenaming.Init(ImportDevices);
+ setupRenaming.ShowDialog();
+
+ if (!generatePages)
+ return;
foreach (var Object in ImportDevices.GroupBy(d => d.Object))
{
diff --git a/src/ProjectImportICP/SetupDevicesNames.Designer.cs b/src/ProjectImportICP/SetupDevicesNames.Designer.cs
index b891b402..06a74ace 100644
--- a/src/ProjectImportICP/SetupDevicesNames.Designer.cs
+++ b/src/ProjectImportICP/SetupDevicesNames.Designer.cs
@@ -29,34 +29,83 @@ protected override void Dispose(bool disposing)
private void InitializeComponent()
{
this.objectListView = new BrightIdeasSoftware.ObjectListView();
+ this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+ this.LoadRenameMapBttn = new System.Windows.Forms.Button();
+ this.OkBttn = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.objectListView)).BeginInit();
+ this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// objectListView
//
this.objectListView.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.DoubleClick;
this.objectListView.CellEditUseWholeCell = false;
+ this.tableLayoutPanel1.SetColumnSpan(this.objectListView, 3);
this.objectListView.Cursor = System.Windows.Forms.Cursors.Default;
this.objectListView.Dock = System.Windows.Forms.DockStyle.Fill;
this.objectListView.HideSelection = false;
- this.objectListView.Location = new System.Drawing.Point(0, 0);
+ this.objectListView.Location = new System.Drawing.Point(3, 3);
this.objectListView.Name = "objectListView";
- this.objectListView.Size = new System.Drawing.Size(365, 495);
+ this.objectListView.Size = new System.Drawing.Size(359, 451);
this.objectListView.TabIndex = 0;
this.objectListView.UseCompatibleStateImageBehavior = false;
this.objectListView.View = System.Windows.Forms.View.Details;
this.objectListView.CellEditFinishing += new BrightIdeasSoftware.CellEditEventHandler(this.objectListView_CellEditFinishing);
this.objectListView.CellEditStarting += new BrightIdeasSoftware.CellEditEventHandler(this.objectListView_CellEditStarting);
//
+ // tableLayoutPanel1
+ //
+ this.tableLayoutPanel1.ColumnCount = 3;
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 80F));
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 75F));
+ this.tableLayoutPanel1.Controls.Add(this.objectListView, 0, 0);
+ this.tableLayoutPanel1.Controls.Add(this.LoadRenameMapBttn, 0, 1);
+ this.tableLayoutPanel1.Controls.Add(this.OkBttn, 2, 1);
+ this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
+ this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+ this.tableLayoutPanel1.RowCount = 2;
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 38F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(365, 495);
+ this.tableLayoutPanel1.TabIndex = 1;
+ //
+ // LoadRenameMapBttn
+ //
+ this.LoadRenameMapBttn.Dock = System.Windows.Forms.DockStyle.Top;
+ this.LoadRenameMapBttn.Location = new System.Drawing.Point(3, 460);
+ this.LoadRenameMapBttn.Name = "LoadRenameMapBttn";
+ this.LoadRenameMapBttn.Size = new System.Drawing.Size(226, 23);
+ this.LoadRenameMapBttn.TabIndex = 1;
+ this.LoadRenameMapBttn.Text = "Применить файл переименования";
+ this.LoadRenameMapBttn.UseVisualStyleBackColor = true;
+ this.LoadRenameMapBttn.Click += new System.EventHandler(this.LoadRenameMapBttn_Click);
+ //
+ // OkBttn
+ //
+ this.OkBttn.Dock = System.Windows.Forms.DockStyle.Top;
+ this.OkBttn.Location = new System.Drawing.Point(293, 460);
+ this.OkBttn.Name = "OkBttn";
+ this.OkBttn.Size = new System.Drawing.Size(69, 23);
+ this.OkBttn.TabIndex = 2;
+ this.OkBttn.Text = "OK";
+ this.OkBttn.UseVisualStyleBackColor = true;
+ this.OkBttn.Click += new System.EventHandler(this.OkBttn_Click);
+ //
// SetupDevicesNames
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(365, 495);
- this.Controls.Add(this.objectListView);
+ this.Controls.Add(this.tableLayoutPanel1);
this.Name = "SetupDevicesNames";
+ this.ShowIcon = false;
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Настройка замены имен устройств";
+ this.TopMost = true;
((System.ComponentModel.ISupportInitialize)(this.objectListView)).EndInit();
+ this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}
@@ -64,5 +113,8 @@ private void InitializeComponent()
#endregion
private BrightIdeasSoftware.ObjectListView objectListView;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
+ private System.Windows.Forms.Button LoadRenameMapBttn;
+ private System.Windows.Forms.Button OkBttn;
}
}
\ No newline at end of file
diff --git a/src/ProjectImportICP/SetupDevicesNames.cs b/src/ProjectImportICP/SetupDevicesNames.cs
index 76442abd..8dcdb5cd 100644
--- a/src/ProjectImportICP/SetupDevicesNames.cs
+++ b/src/ProjectImportICP/SetupDevicesNames.cs
@@ -6,8 +6,10 @@
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
+using System.IO;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -22,8 +24,6 @@ public partial class SetupDevicesNames : Form
TextBox textBoxCellEditor;
- List Devices;
-
public SetupDevicesNames()
{
InitializeComponent();
@@ -70,15 +70,12 @@ public void Init(List devices)
{
objectListView.BeginUpdate();
- Devices = new List();
- Devices.AddRange(devices);
-
- objectListView.Objects = Devices;
+ objectListView.Objects = devices;
objectListView.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
objectListView.Columns[0].Width = 70;
objectListView.Columns[1].Width = 20;
- objectListView.Columns[2].Width = 70;
+ objectListView.Columns[2].Width = 100;
objectListView.Columns[2].TextAlign = HorizontalAlignment.Right;
objectListView.Columns[3].Width = 70;
@@ -176,7 +173,7 @@ private void objectListView_CellEditFinishing(object sender, CellEditEventArgs e
switch (e.Column.Index)
{
case 2:
- device.Object = e.NewValue.ToString();
+ device.Object = e.NewValue.ToString().ToUpper();
objectListView.Refresh();
break;
@@ -198,5 +195,58 @@ private void objectListView_CellEditFinishing(object sender, CellEditEventArgs e
e.Cancel = true;
objectListView.Unfreeze();
}
+
+ private void OkBttn_Click(object sender, EventArgs e)
+ {
+ Close();
+ }
+
+ private void LoadRenameMapBttn_Click(object sender, EventArgs e)
+ {
+ var openFileDialog = new OpenFileDialog
+ {
+ Title = "Открыть файл карты переименования устройств",
+ Filter = "Текстовый файл|*.txt",
+ Multiselect = false
+ };
+
+ if (openFileDialog.ShowDialog() == DialogResult.Cancel)
+ {
+ return;
+ }
+
+ var data = "";
+ using (var reader = new StreamReader(openFileDialog.FileName, EncodingDetector.DetectFileEncoding(openFileDialog.FileName), true))
+ {
+ // read main.wago.plua file data
+ data = reader.ReadToEnd();
+ }
+
+ var matches = Regex.Matches(data,
+ @"\s*(?[\w]*?)(?[\d]*)\s*=>\s*(?