Skip to content

Commit

Permalink
[ICP CON import] Generate renaming file and use it (#1491)
Browse files Browse the repository at this point in the history
```ChangeLog
Добалена генерация файла переименования устройств и его применение при импорте старого ICP CON проекта;
```
  • Loading branch information
KirillGutyrchik authored Dec 16, 2024
1 parent 52b117e commit 5f3e21e
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/EasyEPlanner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="ColumnNode.cs" />
<Compile Include="Configuration\ConfigurationChecker.cs" />
<Compile Include="Configuration\DeviceSynchronizeService.cs" />
<Compile Include="Main\ImportIcpCreateRenamingMap.cs" />
<Compile Include="Main\ImportIcpWagoProject.cs" />
<Compile Include="Main\ModifyIcpChbase.cs" />
<Compile Include="ProjectImportICP\BindingImporter.cs" />
Expand Down
10 changes: 8 additions & 2 deletions src/Main/AddInModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
83 changes: 83 additions & 0 deletions src/Main/ImportIcpCreateRenamingMap.cs
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
}
47 changes: 29 additions & 18 deletions src/Main/ImportIcpWagoProject.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions src/ProjectImportICP/DevicesImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,15 @@ public class DevicesImporter : IDevicesImporter
/// </summary>
private readonly List<int> tanks = new List<int>();

/// <summary>
/// Генерировать страницы EPLAN с устройствами
/// </summary>
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
{
Expand Down Expand Up @@ -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))
{
Expand Down
58 changes: 55 additions & 3 deletions src/ProjectImportICP/SetupDevicesNames.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5f3e21e

Please sign in to comment.