Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ICP CON import] Ability to change subtype and set default parameters #1500

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using EasyEPlanner.ProjectImportICP;
using EplanDevice;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyEplannerTests.ProjectImportICPTest
{
public class ImportDefaultDeviceParameterTest
{

[Test]
public void CreateInstance()
{
var par = new ImportDefaultDeviceParamter("V", IODevice.Parameter.P_DT);

Assert.Multiple(() =>
{
Assert.IsNotNull(par);
Assert.AreEqual("V", par.DeviceType);
Assert.AreEqual(IODevice.Parameter.P_DT, par.Parameter);
Assert.AreEqual(0, par.DefaultValue);
});
}
}
}
1 change: 1 addition & 0 deletions src/EasyEPlanner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<Compile Include="EProjectManager\InsertMacrosInteraction.cs" />
<Compile Include="EProjectManager\SelectInteractionWhileEditModes.cs" />
<Compile Include="Extensions\ApiExtensions.cs" />
<Compile Include="ProjectImportICP\ImportDefaultDeviceParamter.cs" />
<Compile Include="ProjectImportICP\ImportDevice.cs" />
<Compile Include="ProjectImportICP\ImportModule.cs" />
<Compile Include="ProjectImportICP\ModifyChannelsDBDialog.cs">
Expand Down
2 changes: 1 addition & 1 deletion src/Main/ImportIcpCreateRenamingMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public bool Execute(ActionCallingContext oActionCallingContext)
{
foreach (var dev in devices)
{
writer.Write($"{dev.WagoType + dev.FullNumber,10} => {dev.Object,10} | {dev.Type, 3} | {dev.Number, -5} | '{dev.Description}'\n");
writer.Write($"{dev.WagoType + dev.FullNumber,10} => {dev.Object,10} | {dev.Type, 3} | {dev.Number, -5} | {dev.Subtype, -10} | '{dev.Description}'\n");
}
}
}
Expand Down
64 changes: 33 additions & 31 deletions src/ProjectImportICP/DevicesImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -280,6 +281,8 @@ public void Import()

public List<ImportDevice> ImportDevices { get; private set; } = new List<ImportDevice>();

public List<ImportDefaultDeviceParamter> DefaultParameters { get; private set; } = new List<ImportDefaultDeviceParamter>();


public IImportDevice ImportDevice(string type, string wagoType, int number, string subtype, string description)
{
Expand All @@ -293,36 +296,6 @@ public IImportDevice ImportDevice(string type, string wagoType, int number, stri
Description = description
};

// Установка стандартных параметров для определенных типов устройств
switch (type)
{
case "DI":
dev.Parameters.Add(IODevice.Parameter.P_DT, "0");
break;

case "V":
case "M":
dev.Parameters.Add(IODevice.Parameter.P_ON_TIME, "0");
break;

case "TE":
case "LT":
dev.Parameters.Add(IODevice.Parameter.P_C0, "0");
dev.Parameters.Add(IODevice.Parameter.P_ERR, "0");
break;

case "AO":
dev.Parameters.Add(IODevice.Parameter.P_MIN_V, "0");
dev.Parameters.Add(IODevice.Parameter.P_MAX_V, "0");
break;

case "QT":
dev.Parameters.Add(IODevice.Parameter.P_MIN_V, "0");
dev.Parameters.Add(IODevice.Parameter.P_MAX_V, "0");
dev.Parameters.Add(IODevice.Parameter.P_C0, "0");
break;
}

// Если в проекте есть подходящий номеру танк
if (tanks.Contains(number / 100))
{
Expand All @@ -348,8 +321,28 @@ public IImportDevice ImportDevice(string type, string wagoType, int number, stri

public void GenerateDevicesPages()
{
DefaultParameters.Add(new ImportDefaultDeviceParamter("DI", IODevice.Parameter.P_DT, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("LS", IODevice.Parameter.P_DT, 0));

DefaultParameters.Add(new ImportDefaultDeviceParamter("V", IODevice.Parameter.P_ON_TIME, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("M", IODevice.Parameter.P_ON_TIME, 0));

DefaultParameters.Add(new ImportDefaultDeviceParamter("TE", IODevice.Parameter.P_C0, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("TE", IODevice.Parameter.P_ERR, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("LT", IODevice.Parameter.P_C0, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("LT", IODevice.Parameter.P_ERR, 0));

DefaultParameters.Add(new ImportDefaultDeviceParamter("AO", IODevice.Parameter.P_MIN_V, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("AO", IODevice.Parameter.P_MAX_V, 0));

DefaultParameters.Add(new ImportDefaultDeviceParamter("QT", IODevice.Parameter.P_MIN_V, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("QT", IODevice.Parameter.P_MAX_V, 0));
DefaultParameters.Add(new ImportDefaultDeviceParamter("QT", IODevice.Parameter.P_C0, 0));


var setupRenaming = new SetupDevicesNames();
setupRenaming.Init(ImportDevices);
setupRenaming.InitRenamingDevices(ImportDevices);
setupRenaming.InitDefaultParameters(DefaultParameters);
setupRenaming.ShowDialog();

if (!generatePages)
Expand All @@ -359,6 +352,15 @@ public void GenerateDevicesPages()
{
var devices = Object.ToList();

// Установка стандартных параметров для определенных типов устройств
foreach (var device in devices)
{
foreach (var parameter in DefaultParameters.Where(p => p.DeviceType == device.Type))
{
device.Parameters.Add(parameter.Parameter, parameter.DefaultValue.ToString());
}
}

if (string.IsNullOrEmpty(Object.Key))
{ // Генерация страницы с сигналами DO/DO без объекта
var signals = devices.Where(d => d.Type == "DO" || d.Type == "DI").ToList();
Expand Down
26 changes: 26 additions & 0 deletions src/ProjectImportICP/ImportDefaultDeviceParamter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using EplanDevice;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyEPlanner.ProjectImportICP
{
public class ImportDefaultDeviceParamter
{
public ImportDefaultDeviceParamter(string deviceType, IODevice.Parameter parameter, int defaultValue = 0)
{
DeviceType = deviceType;
Parameter = parameter;
DefaultValue = defaultValue;
}

public string DeviceType { get; }

public IODevice.Parameter Parameter { get; }

public int DefaultValue { get; set; }
}
}
111 changes: 90 additions & 21 deletions src/ProjectImportICP/SetupDevicesNames.Designer.cs

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

Loading