From afe1853f769b06cac1813a192125cec10978ff7a Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Thu, 1 Aug 2024 17:01:27 +0300 Subject: [PATCH] Remove old methods and better style --- .../Properties.Test/ActionParameter.Test.cs | 68 ++++---- .../Actions.Test/Action.Test.cs | 130 +++++++-------- .../UniversalObject.Test/Equipment.Test.cs | 88 +++++------ src/Device/DeviceManager.cs | 13 +- src/Editor/NewEditorControl.resx | 2 +- src/TechObject/Base/BaseParameter.cs | 28 ++-- .../Base/Properties/ActionParameter.cs | 21 +-- .../UniversalObject/Actions/Action.cs | 148 +++--------------- .../UniversalObject/Actions/ActionWash.cs | 13 -- .../Actions/GroupableAction.cs | 35 +---- .../ObjectsTree/UniversalObject/Equipment.cs | 43 ++--- .../ObjectsTree/UniversalObject/Mode.cs | 5 +- .../UniversalObject/ModesManager.cs | 4 +- .../ObjectsTree/UniversalObject/State.cs | 4 +- .../ObjectsTree/UniversalObject/Step.cs | 4 +- .../ObjectsTree/UniversalObject/TechObject.cs | 3 +- 16 files changed, 238 insertions(+), 371 deletions(-) diff --git a/EasyEplanner.Tests/TechObject.Test/Base.Test/Properties.Test/ActionParameter.Test.cs b/EasyEplanner.Tests/TechObject.Test/Base.Test/Properties.Test/ActionParameter.Test.cs index df24a5de..1d7b94b7 100644 --- a/EasyEplanner.Tests/TechObject.Test/Base.Test/Properties.Test/ActionParameter.Test.cs +++ b/EasyEplanner.Tests/TechObject.Test/Base.Test/Properties.Test/ActionParameter.Test.cs @@ -69,45 +69,45 @@ public void SetNewValue_and_DisplayText_DisplayParameter() }); } - [Test] - public void ModifyDevName() - { - string OBJ = nameof(OBJ); + //[Test] + //public void ModifyDevName() + //{ + // string OBJ = nameof(OBJ); - var deviceManagerMock = new Mock(); - var dev1 = new V($"{OBJ}1V1", $"+{OBJ}1-V1", "", 1, OBJ, 1, ""); - var dev2 = new V($"{OBJ}2V1", $"+{OBJ}2-V1", "", 1, OBJ, 2, ""); + // var deviceManagerMock = new Mock(); + // var dev1 = new V($"{OBJ}1V1", $"+{OBJ}1-V1", "", 1, OBJ, 1, ""); + // var dev2 = new V($"{OBJ}2V1", $"+{OBJ}2-V1", "", 1, OBJ, 2, ""); - deviceManagerMock.Setup(m => m.GetDeviceByEplanName($"{OBJ}1V1")).Returns(dev1); - deviceManagerMock.Setup(m => m.GetDeviceByEplanName($"{OBJ}2V1")).Returns(dev2); + // deviceManagerMock.Setup(m => m.GetDeviceByEplanName($"{OBJ}1V1")).Returns(dev1); + // deviceManagerMock.Setup(m => m.GetDeviceByEplanName($"{OBJ}2V1")).Returns(dev2); - deviceManagerMock.Setup(m => m.GetDeviceIndex($"{OBJ}1V1")).Returns(0); - deviceManagerMock.Setup(m => m.GetDeviceIndex($"{OBJ}2V1")).Returns(1); + // deviceManagerMock.Setup(m => m.GetDeviceIndex($"{OBJ}1V1")).Returns(0); + // deviceManagerMock.Setup(m => m.GetDeviceIndex($"{OBJ}2V1")).Returns(1); - deviceManagerMock.Setup(m => m.GetDeviceByIndex(0)).Returns(dev1); - deviceManagerMock.Setup(m => m.GetDeviceByIndex(1)).Returns(dev2); + // deviceManagerMock.Setup(m => m.GetDeviceByIndex(0)).Returns(dev1); + // deviceManagerMock.Setup(m => m.GetDeviceByIndex(1)).Returns(dev2); - var actionParameter = new ActionParameter("action_parameter", "параметр"); + // var actionParameter = new ActionParameter("action_parameter", "параметр"); - typeof(BaseParameter).GetField("deviceManager", - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) - .SetValue(null, deviceManagerMock.Object); - - Assert.Multiple(() => - { - actionParameter.SetNewValue($"{OBJ}1V1"); - actionParameter.ModifyDevName(1, 2, OBJ); - Assert.AreEqual($"{OBJ}2V1",actionParameter.Value); - - - actionParameter.SetNewValue($"{OBJ}1V1"); - actionParameter.ModifyDevName(2, -1, OBJ); - Assert.AreEqual($"{OBJ}2V1", actionParameter.Value); - }); - - typeof(BaseParameter).GetField("deviceManager", - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) - .SetValue(null, DeviceManager.GetInstance()); - } + // typeof(BaseParameter).GetField("deviceManager", + // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) + // .SetValue(null, deviceManagerMock.Object); + + // Assert.Multiple(() => + // { + // actionParameter.SetNewValue($"{OBJ}1V1"); + // actionParameter.ModifyDevName(1, 2, OBJ); + // Assert.AreEqual($"{OBJ}2V1",actionParameter.Value); + + + // actionParameter.SetNewValue($"{OBJ}1V1"); + // actionParameter.ModifyDevName(2, -1, OBJ); + // Assert.AreEqual($"{OBJ}2V1", actionParameter.Value); + // }); + + // typeof(BaseParameter).GetField("deviceManager", + // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) + // .SetValue(null, DeviceManager.GetInstance()); + //} } } diff --git a/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Actions.Test/Action.Test.cs b/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Actions.Test/Action.Test.cs index 3f4615da..c2b8b20a 100644 --- a/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Actions.Test/Action.Test.cs +++ b/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Actions.Test/Action.Test.cs @@ -551,71 +551,71 @@ private static object[] SaveAsLuaTableTestCaseSource() }; } - [TestCase(new int[] { 1, 2, 4, 5, 6 }, - new int[] { 3, 4, 5, 6 }, "KOAG", "1", "TANK", "1")] - [TestCase(new int[] { 1, 2, 3, 4 }, - new int[] { 5, 6, 3, 4 }, "TANK", "2", "TANK", "1")] - [TestCase(new int[] { 1, 2, 3, 4 }, - new int[] { 1, 2, 5 }, "TANK", "2", "KOAG", "1")] - public void ModifyDevNames(int[] devIds, int[] expectedDevIds, - string newTechObjectName, int newTechObjectNumber, - string oldTechObjectName, int oldTechObjNumber) - { - EplanDevice.IDeviceManager deviceManager = DeviceManagerMock.DeviceManager; - typeof(Action).GetField("deviceManager", - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) - .SetValue(null, deviceManager); - - var action = new Action(string.Empty, null, string.Empty, null, - null, null); - action.DevicesIndex.AddRange(devIds); - - action.ModifyDevNames(newTechObjectName, newTechObjectNumber, - oldTechObjectName, oldTechObjNumber); - - Assert.AreEqual(expectedDevIds, action.DevicesIndex); - } - - [TestCase(new int[] { 1, 2, 3, 4 }, new int[] { 5, 6, 3, 4 }, 2, 1, "TANK")] - [TestCase(new int[] { 5, 4, 6, 3 }, new int[] { 1, 4, 2, 3 }, 2, 1, "TANK")] - [TestCase(new int[] { 1, 2, 3, 4, 8 }, new int[] { 5, 6, 3, 4, 7 }, 2, -1, "TANK")] - [TestCase(new int[] { 8 }, new int[] { 8 }, 2, 1, "TANK")] - public void ModifyDevNames(int[] devIds, int[] expectedDevIds, - int newTechObjectN, int oldTechObjectN, string techObjectName) - { - EplanDevice.IDeviceManager deviceManager = DeviceManagerMock.DeviceManager; - typeof(Action).GetField("deviceManager", - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) - .SetValue(null, deviceManager); - - var action = new Action(string.Empty, null, string.Empty, null, - null, null); - action.DevicesIndex.AddRange(devIds); - - action.ModifyDevNames(newTechObjectN, oldTechObjectN, - techObjectName); - - Assert.AreEqual(expectedDevIds, action.DevicesIndex); - } - - [TestCase(new int[] { 1, 2, 3, 4 }, new int[] { 5, 6, 3, 4 }, 2, "TANK")] - [TestCase(new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, 3, "TANK")] - public void ModifyDevNames_CheckGenericUpdating(int[] devIds, - int[] expectedDevIds, int newObjID, string techObjectName) - { - EplanDevice.IDeviceManager deviceManager = DeviceManagerMock.DeviceManager; - typeof(Action).GetField("deviceManager", - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) - .SetValue(null, deviceManager); - - var action = new Action(string.Empty, null, string.Empty, null, - null, null); - action.DevicesIndex.AddRange(devIds); - - action.ModifyDevNames(newObjID, -1, techObjectName); - - CollectionAssert.AreEqual(expectedDevIds, action.DevicesIndex); - } + //[TestCase(new int[] { 1, 2, 4, 5, 6 }, + // new int[] { 3, 4, 5, 6 }, "KOAG", "1", "TANK", "1")] + //[TestCase(new int[] { 1, 2, 3, 4 }, + // new int[] { 5, 6, 3, 4 }, "TANK", "2", "TANK", "1")] + //[TestCase(new int[] { 1, 2, 3, 4 }, + // new int[] { 1, 2, 5 }, "TANK", "2", "KOAG", "1")] + //public void ModifyDevNames(int[] devIds, int[] expectedDevIds, + // string newTechObjectName, int newTechObjectNumber, + // string oldTechObjectName, int oldTechObjNumber) + //{ + // EplanDevice.IDeviceManager deviceManager = DeviceManagerMock.DeviceManager; + // typeof(Action).GetField("deviceManager", + // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) + // .SetValue(null, deviceManager); + + // var action = new Action(string.Empty, null, string.Empty, null, + // null, null); + // action.DevicesIndex.AddRange(devIds); + + // action.ModifyDevNames(newTechObjectName, newTechObjectNumber, + // oldTechObjectName, oldTechObjNumber); + + // Assert.AreEqual(expectedDevIds, action.DevicesIndex); + //} + + //[TestCase(new int[] { 1, 2, 3, 4 }, new int[] { 5, 6, 3, 4 }, 2, 1, "TANK")] + //[TestCase(new int[] { 5, 4, 6, 3 }, new int[] { 1, 4, 2, 3 }, 2, 1, "TANK")] + //[TestCase(new int[] { 1, 2, 3, 4, 8 }, new int[] { 5, 6, 3, 4, 7 }, 2, -1, "TANK")] + //[TestCase(new int[] { 8 }, new int[] { 8 }, 2, 1, "TANK")] + //public void ModifyDevNames(int[] devIds, int[] expectedDevIds, + // int newTechObjectN, int oldTechObjectN, string techObjectName) + //{ + // EplanDevice.IDeviceManager deviceManager = DeviceManagerMock.DeviceManager; + // typeof(Action).GetField("deviceManager", + // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) + // .SetValue(null, deviceManager); + + // var action = new Action(string.Empty, null, string.Empty, null, + // null, null); + // action.DevicesIndex.AddRange(devIds); + + // action.ModifyDevNames(newTechObjectN, oldTechObjectN, + // techObjectName); + + // Assert.AreEqual(expectedDevIds, action.DevicesIndex); + //} + + //[TestCase(new int[] { 1, 2, 3, 4 }, new int[] { 5, 6, 3, 4 }, 2, "TANK")] + //[TestCase(new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, 3, "TANK")] + //public void ModifyDevNames_CheckGenericUpdating(int[] devIds, + // int[] expectedDevIds, int newObjID, string techObjectName) + //{ + // EplanDevice.IDeviceManager deviceManager = DeviceManagerMock.DeviceManager; + // typeof(Action).GetField("deviceManager", + // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) + // .SetValue(null, deviceManager); + + // var action = new Action(string.Empty, null, string.Empty, null, + // null, null); + // action.DevicesIndex.AddRange(devIds); + + // action.ModifyDevNames(newObjID, -1, techObjectName); + + // CollectionAssert.AreEqual(expectedDevIds, action.DevicesIndex); + //} [TestCase(new int[] { 1, 3, 5, 7, 9 })] [TestCase(new int[0])] diff --git a/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Equipment.Test.cs b/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Equipment.Test.cs index da590a11..0fd279ca 100644 --- a/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Equipment.Test.cs +++ b/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/UniversalObject.Test/Equipment.Test.cs @@ -12,64 +12,64 @@ namespace TechObjectTests { public class EquipmentTest { - [Test] - public void ModifyDevNames() - { - V OBJ1V1 = new V(nameof(OBJ1V1), "=OBJ1+V1", string.Empty, 1, "OBJ", 1, string.Empty); - V OBJ2V2 = new V(nameof(OBJ2V2), "=OBJ2+V2", string.Empty, 2, "OBJ", 2, string.Empty); - V OBJ3V1 = new V(nameof(OBJ3V1), "=OBJ3+V1", string.Empty, 1, "OBJ", 3, string.Empty); - V OBJ3V2 = new V(nameof(OBJ3V2), "=OBJ3+V2", string.Empty, 2, "OBJ", 3, string.Empty); - V OBJ3V3 = new V(nameof(OBJ3V3), "=OBJ3+V3", string.Empty, 3, "OBJ", 3, string.Empty); + //[Test] + //public void ModifyDevNames() + //{ + // V OBJ1V1 = new V(nameof(OBJ1V1), "=OBJ1+V1", string.Empty, 1, "OBJ", 1, string.Empty); + // V OBJ2V2 = new V(nameof(OBJ2V2), "=OBJ2+V2", string.Empty, 2, "OBJ", 2, string.Empty); + // V OBJ3V1 = new V(nameof(OBJ3V1), "=OBJ3+V1", string.Empty, 1, "OBJ", 3, string.Empty); + // V OBJ3V2 = new V(nameof(OBJ3V2), "=OBJ3+V2", string.Empty, 2, "OBJ", 3, string.Empty); + // V OBJ3V3 = new V(nameof(OBJ3V3), "=OBJ3+V3", string.Empty, 3, "OBJ", 3, string.Empty); - IODevice CAP = new V(string.Empty, string.Empty, StaticHelper.CommonConst.Cap, 1, string.Empty, 1, string.Empty); + // IODevice CAP = new V(string.Empty, string.Empty, StaticHelper.CommonConst.Cap, 1, string.Empty, 1, string.Empty); - var deviceManagerMock = new Mock(); + // var deviceManagerMock = new Mock(); - deviceManagerMock.Setup(dm => dm.GetDevice(It.IsAny())).Returns(CAP); + // deviceManagerMock.Setup(dm => dm.GetDevice(It.IsAny())).Returns(CAP); - deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ1V1))).Returns(OBJ1V1); - deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ2V2))).Returns(OBJ2V2); - deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ3V1))).Returns(OBJ3V1); - deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ3V2))).Returns(OBJ3V2); - deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ3V3))).Returns(OBJ3V3); + // deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ1V1))).Returns(OBJ1V1); + // deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ2V2))).Returns(OBJ2V2); + // deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ3V1))).Returns(OBJ3V1); + // deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ3V2))).Returns(OBJ3V2); + // deviceManagerMock.Setup(dm => dm.GetDevice(nameof(OBJ3V3))).Returns(OBJ3V3); - deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ1V1))).Returns(0); - deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ2V2))).Returns(1); - deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ3V1))).Returns(2); - deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ3V2))).Returns(3); - deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ3V3))).Returns(4); + // deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ1V1))).Returns(0); + // deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ2V2))).Returns(1); + // deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ3V1))).Returns(2); + // deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ3V2))).Returns(3); + // deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ3V3))).Returns(4); - deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(0)).Returns(OBJ1V1); - deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(1)).Returns(OBJ2V2); - deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(2)).Returns(OBJ3V1); - deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(3)).Returns(OBJ3V2); - deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(4)).Returns(OBJ3V3); + // deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(0)).Returns(OBJ1V1); + // deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(1)).Returns(OBJ2V2); + // deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(2)).Returns(OBJ3V1); + // deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(3)).Returns(OBJ3V2); + // deviceManagerMock.Setup(dm => dm.GetDeviceByIndex(4)).Returns(OBJ3V3); - deviceManagerMock.Setup(dm => dm.GetDeviceByEplanName(It.IsAny())).Returns(OBJ3V3); + // deviceManagerMock.Setup(dm => dm.GetDeviceByEplanName(It.IsAny())).Returns(OBJ3V3); - var equipment = new Equipment( - new TechObject.TechObject(string.Empty, GetN => 1, 3, 2, - "OBJ", -1, string.Empty, string.Empty, new BaseTechObject())); + // var equipment = new Equipment( + // new TechObject.TechObject(string.Empty, GetN => 1, 3, 2, + // "OBJ", -1, string.Empty, string.Empty, new BaseTechObject())); - var equipmentParameter = new EquipmentParameter("devs", "устройства", ""); - typeof(BaseParameter).GetField("deviceManager", - System.Reflection.BindingFlags.Static | - System.Reflection.BindingFlags.NonPublic) - .SetValue(null, deviceManagerMock.Object); + // var equipmentParameter = new EquipmentParameter("devs", "устройства", ""); + // typeof(BaseParameter).GetField("deviceManager", + // System.Reflection.BindingFlags.Static | + // System.Reflection.BindingFlags.NonPublic) + // .SetValue(null, deviceManagerMock.Object); - typeof(Equipment).GetProperty("deviceManager", - System.Reflection.BindingFlags.NonPublic | - System.Reflection.BindingFlags.Static) - .SetValue(null, deviceManagerMock.Object); + // typeof(Equipment).GetProperty("deviceManager", + // System.Reflection.BindingFlags.NonPublic | + // System.Reflection.BindingFlags.Static) + // .SetValue(null, deviceManagerMock.Object); - equipment.AddItems(new List() { equipmentParameter }); + // equipment.AddItems(new List() { equipmentParameter }); - equipment.SetEquipmentValue("devs", "OBJ1V1 OBJ2V2 OBJ3V3"); + // equipment.SetEquipmentValue("devs", "OBJ1V1 OBJ2V2 OBJ3V3"); - equipment.ModifyDevNames(); + // equipment.ModifyDevNames(); - Assert.AreEqual($"{nameof(OBJ3V1)} {nameof(OBJ3V2)} {nameof(OBJ3V3)}", equipmentParameter.Value); - } + // Assert.AreEqual($"{nameof(OBJ3V1)} {nameof(OBJ3V2)} {nameof(OBJ3V3)}", equipmentParameter.Value); + //} } } diff --git a/src/Device/DeviceManager.cs b/src/Device/DeviceManager.cs index cdb14d6b..c183150a 100644 --- a/src/Device/DeviceManager.cs +++ b/src/Device/DeviceManager.cs @@ -1167,11 +1167,10 @@ public IDevice GetModifiedDevice(IDevice device, IDevModifyOptions options) { if (ModifyMixproof(device, options) is IDevice mixproof) { - return mixproof.Description == CommonConst.Cap ? null : mixproof; + return mixproof.Description == CommonConst.Cap ? null : mixproof; + // null - удаляем привязку устройства } - IDevice res = null; - if (options.NumberModified && options.OldTechObjectNumber != 0 && // Не модифицировать устройства в типовых объектах device.Description != CommonConst.Cap && @@ -1183,21 +1182,21 @@ public IDevice GetModifiedDevice(IDevice device, IDevModifyOptions options) // Изменяем номер объекта в устройстве в соответствии с изменениями объекта или для типовых объектов: // ( 1 -> 2 ) : OBJ[1]V1 -> OBJ[2]V1 // ( -1 -> 1, 2,... ) : OBJ[x]V1 -> OBJ[1]V1, OBJ[2]V1, ... - для типовых объектов - res = GetDeviceByEplanName($"{device.ObjectName}{options.NewTechObjectNumber}{device.DeviceDesignation}"); + return GetDeviceByEplanName($"{device.ObjectName}{options.NewTechObjectNumber}{device.DeviceDesignation}"); } else if (device.ObjectNumber == options.NewTechObjectNumber) { // Инверсионное изменение номера объекта: когда устройство имеет номер объекта равный новому номеру объекта // ( 1 -> 2 ) : OBJ[2]V1 -> OBJ[1]V1 - res = GetDeviceByEplanName($"{device.ObjectName}{options.OldTechObjectNumber}{device.DeviceDesignation}"); + return GetDeviceByEplanName($"{device.ObjectName}{options.OldTechObjectNumber}{device.DeviceDesignation}"); } } else if (options.NameModified && device.ObjectName == options.OldTechObjectName) { - res = GetDeviceByEplanName($"{options.NewTechObjectName}{device.ObjectNumber}{device.DeviceDesignation}"); + return GetDeviceByEplanName($"{options.NewTechObjectName}{device.ObjectNumber}{device.DeviceDesignation}"); } - return res?.Description == CommonConst.Cap ? null : res; + return device; } /// diff --git a/src/Editor/NewEditorControl.resx b/src/Editor/NewEditorControl.resx index d4af2f37..9b824929 100644 --- a/src/Editor/NewEditorControl.resx +++ b/src/Editor/NewEditorControl.resx @@ -140,7 +140,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACq - bgAAAk1TRnQBSQFMAgEBEAEAAQgBEAEIAhABAAEQAQAE/wEhAQAI/wFCAU0BNgcAATYDAAEoAwABQAMA + bgAAAk1TRnQBSQFMAgEBEAEAASgBEAEoAhABAAEQAQAE/wEhAQAI/wFCAU0BNgcAATYDAAEoAwABQAMA AVADAAEBAQABIAYAAVD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/ACIAAYcBJQGtAf8BLgEs AaoB/wEtASoBqQH/ASwBKQGoAf8BLAEpAagB/wEsASkBqAH/ASwBKQGoAf8BLQEqAakB/wEzAS8BrAH/ AYMBgAGxAf8BiQGHAbYB/wGNAYsBuQH/AZIBkQG8Af8BlQGUAb4B/wGXAZYBvwH/AZwBmwHCAf8BhwEl diff --git a/src/TechObject/Base/BaseParameter.cs b/src/TechObject/Base/BaseParameter.cs index 6f71af3a..15512061 100644 --- a/src/TechObject/Base/BaseParameter.cs +++ b/src/TechObject/Base/BaseParameter.cs @@ -544,26 +544,28 @@ public virtual void Check() } } - public void ModifyDevNames(int newID, int oldID, - string objName) + public virtual void ModifyDevNames(IDevModifyOptions options) { if (!OnlyDevicesInParameter) return; + var devNames = Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - var devices = Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList() - .Select(devname => deviceManager.GetDeviceByEplanName(devname)); - - var notObjectDevices = devices.Where(dev => dev.Description == CommonConst.Cap || dev.ObjectName != objName || dev.ObjectNumber <= 0); - var devicesForModify = devices.Except(notObjectDevices); - - var newValues = devicesForModify - .Select(dev => + var newValues = devNames + .Select(deviceManager.GetDeviceByEplanName) + .Select(dev => deviceManager.GetModifiedDevice(dev, options)) + .Select((dev, index) => { - var modified = deviceManager.GetDeviceByEplanName($"{objName}{(oldID == -1 || oldID == dev.ObjectNumber ? newID : oldID)}{dev.DeviceDesignation}"); - return modified.Description == CommonConst.Cap ? dev : modified; + // Если устройство не определено, + // то оставляем не модифицированный вариант + if (dev?.Description == CommonConst.Cap) + return deviceManager.GetDeviceByEplanName(devNames[index]); + + // Оставляем устройство не измененным (MB null) + return dev; }) - .Concat(notObjectDevices).Select(dev => dev.Name); + .OfType() + .Select(dev => dev.Name); SetNewValue(string.Join(" ", newValues)); } diff --git a/src/TechObject/Base/Properties/ActionParameter.cs b/src/TechObject/Base/Properties/ActionParameter.cs index 99d6f008..dbfa3ff1 100644 --- a/src/TechObject/Base/Properties/ActionParameter.cs +++ b/src/TechObject/Base/Properties/ActionParameter.cs @@ -64,22 +64,15 @@ public override void UpdateOnGenericTechObject(ObjectProperty genericProperty) base.UpdateOnGenericTechObject(genericProperty); } - public void ModifyDevName(int newID, int oldID, string objName) + public override void ModifyDevNames(IDevModifyOptions options) { - var dev = deviceManager.GetDeviceByEplanName(Value); - - if (dev.Description == CommonConst.Cap || - dev.ObjectName != objName || - dev.ObjectNumber <= 0) - return; - - if (dev.ObjectNumber == newID && oldID != -1) + var modified = deviceManager.GetModifiedDevice( + deviceManager.GetDeviceByEplanName(Value), + options); + + if (modified?.Description != CommonConst.Cap) { - SetNewValue($"{objName}{oldID}{dev.DeviceDesignation}"); - } - if (oldID == -1 || oldID == dev.ObjectNumber) - { - SetNewValue($"{objName}{newID}{dev.DeviceDesignation}"); + SetNewValue(modified.Name); } } diff --git a/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs b/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs index 572b7eaf..84d9b12f 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs @@ -12,6 +12,7 @@ using EasyEPlanner; using Editor; using EplanDevice; +using StaticHelper; using TechObject.ActionProcessingStrategy; namespace TechObject @@ -91,13 +92,7 @@ void GetDisplayObjects(out EplanDevice.DeviceType[] validTypes, /// Описание действия в клетке Excel string SaveAsExcel(); - void ModifyDevNames(int newTechObjectN, int oldTechObjectN, - string techObjectName); - - void ModifyDevNames(string newTechObjectName, int newTechObjectNumber, - string oldTechObjectName, int oldTechObjNumber); - - void ModifyDevNames(IDevModifyOptions modifyOptions); + void ModifyDevNames(IDevModifyOptions options); List GetObjectToDrawOnEplanPage(); @@ -219,122 +214,31 @@ public virtual IAction Clone() return clone; } - virtual public void ModifyDevNames(int newTechObjectN, - int oldTechObjectN, string techObjectName) - { - if (oldTechObjectN != 0) - deviceIndex = ModifyDevNamesChangeTechNumbers(newTechObjectN, - oldTechObjectN, techObjectName, deviceIndex); - genericDeviceIndex = ModifyDevNamesChangeTechNumbers(newTechObjectN, - oldTechObjectN, techObjectName, genericDeviceIndex, true); - deviceIndex = IndexesExclude(deviceIndex, genericDeviceIndex); - } - - virtual public void ModifyDevNames(string newTechObjectName, - int newTechObjectNumber, string oldTechObjectName, - int oldTechObjNumber) + public virtual void ModifyDevNames(IDevModifyOptions options) { - List tmpIndex = new List(); - foreach (int index in deviceIndex) - { - tmpIndex.Add(index); - } - - foreach (int index in deviceIndex) - { - var newDevName = string.Empty; - EplanDevice.IDevice device = deviceManager.GetDeviceByIndex(index); - int objNum = newTechObjectNumber; - string objName = device.ObjectName; - - if (objName == oldTechObjectName && - device.ObjectNumber == oldTechObjNumber) - { - newDevName = newTechObjectName + objNum + - device.DeviceType.ToString() + device.DeviceNumber; - } - - if (newDevName != string.Empty) - { - int indexOfDeletingElement = tmpIndex.IndexOf(index); - tmpIndex.Remove(index); - int tmpDevInd = deviceManager.GetDeviceIndex(newDevName); - if (tmpDevInd >= 0) - { - tmpIndex.Insert(indexOfDeletingElement, tmpDevInd); - } - } - } - - deviceIndex = tmpIndex; - } - - private List ModifyDevNamesChangeTechNumbers(int newTechObjectN, - int oldTechObjectN, string techObjectName, List devs, bool isGeneric = false) - { - List tmpDevs = new List(); - tmpDevs.AddRange(devs); - - foreach (int dev in devs) - { - var newDevName = ModifyDevNameChangeTechNumber(techObjectName, dev, newTechObjectN, oldTechObjectN); - - if (string.IsNullOrEmpty(newDevName)) - continue; - - int devIndex = tmpDevs.IndexOf(dev); - int tmpDev = deviceManager.GetDeviceIndex(newDevName); - - if (tmpDev >= 0) - tmpDevs[devIndex] = tmpDev; - else if (isGeneric) - tmpDevs.RemoveAt(devIndex); - } - - return tmpDevs; - } - - private string ModifyDevNameChangeTechNumber(string techObjectName, int index, int newID, int oldID) - { - var newDevName = string.Empty; - EplanDevice.IDevice device = deviceManager.GetDeviceByIndex(index); - int objNum = device.ObjectNumber; - string objName = device.ObjectName; - - if (objNum <= 0 || techObjectName != objName) - return string.Empty; - - //deviceManager.GetModifiedDevice - - //Для устройств в пределах объекта меняем номер объекта. - if (objNum == newID && oldID != -1) - { // 1 -> 2 - COAG2V1 --> COAG1V1 - return $"{objName}{oldID}{device.DeviceDesignation}"; - } - if (oldID == -1 || oldID == objNum) - { // COAG1V1 --> COAG(new_id)V1; COAGxV1 -> COAG1V1, COAG2V1 ... - return $"{objName}{newID}{device.DeviceDesignation}"; - } - - return string.Empty; - } - - public virtual void ModifyDevNames(IDevModifyOptions modifyOptions) - { - //if (modifyOptions.OldTechObjectNumber != 0) - deviceIndex = ModifyDevName(deviceIndex, modifyOptions); - genericDeviceIndex = ModifyDevName(genericDeviceIndex, modifyOptions, true); + deviceIndex = ModifyDevName(deviceIndex, options); + genericDeviceIndex = ModifyDevName(genericDeviceIndex, options, true); deviceIndex = IndexesExclude(deviceIndex, genericDeviceIndex); } - private List ModifyDevName(List DevsIdx, IDevModifyOptions modifyOptions, bool removeUndefined = false) + private List ModifyDevName(List DevsIdx, IDevModifyOptions options, bool removeUndefined = false) { - return DevsIdx.Select(deviceManager.GetDeviceByIndex) - .Select(dev => deviceManager.GetModifiedDevice(dev, modifyOptions)) - .Select((dev, index) => (dev is null && !removeUndefined) ? deviceManager.GetDeviceByIndex(DevsIdx[index]) : dev) - .OfType() - .Select(deviceManager.GetDeviceIndex) + return DevsIdx + .Select(deviceManager.GetDeviceByIndex) //=> устройства по индексу + .Select(dev => deviceManager.GetModifiedDevice(dev, options)) //=> модифицированный вариант устройства + .Select((dev, index) => + { + // Если устройство не определено, + // то удаляем или оставляем не модифицированный вариант + if (dev?.Description == CommonConst.Cap) + return removeUndefined? null : deviceManager.GetDeviceByIndex(DevsIdx[index]); + + // Оставляем устройство не измененным (MB null) + return dev; + }) + .OfType() // исключаем нулевые (удаленные) объекты + .Select(deviceManager.GetDeviceIndex) //=> индексы устройств .ToList(); } @@ -479,11 +383,11 @@ public virtual void UpdateOnGenericTechObject(IAction genericAction) public virtual void CreateGenericByTechObjects(IEnumerable actions) { var refTechObject = actions.First().Owner.Owner.Owner.Owner.Owner; - actions.Skip(1).ToList().ForEach(action - => action.ModifyDevNames(refTechObject.TechNumber, - action.Owner.Owner.Owner.Owner.Owner.TechNumber, - refTechObject.NameEplan)); - + actions.Skip(1).ToList().ForEach(action + => action.ModifyDevNames(new DevModifyOptions(refTechObject, + refTechObject.NameEplan, + action.Owner.Owner.Owner.Owner.Owner.TechNumber + ))); deviceIndex = actions.Skip(1).Aggregate(new HashSet(actions.First().DevicesIndex), (h, e) => { h.IntersectWith(e.DevicesIndex); return h; }).ToList(); } diff --git a/src/TechObject/ObjectsTree/UniversalObject/Actions/ActionWash.cs b/src/TechObject/ObjectsTree/UniversalObject/Actions/ActionWash.cs index f1bd9a25..58023ce1 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Actions/ActionWash.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Actions/ActionWash.cs @@ -251,19 +251,6 @@ public override void AddParam(object val, string paramName, } } - public override void ModifyDevNames(int newTechObjectN, int oldTechObjectN, string techObjectName) - { - Parameters.ForEach(p => - { - if (p is ActionParameter actionParameter) - { - actionParameter.ModifyDevName(newTechObjectN, oldTechObjectN, techObjectName); - } - }); - - base.ModifyDevNames(newTechObjectN, oldTechObjectN, techObjectName); - } - #region Реализация ITreeViewItem override public ITreeViewItem[] Items { diff --git a/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs b/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs index 6e2a32e4..4ee56d73 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs @@ -12,39 +12,12 @@ public GroupableAction(string name, Step owner, string luaName) subActions = new List(); } - override public void ModifyDevNames(int newTechObjectN, - int oldTechObjectN, string techObjectName) + public override void ModifyDevNames(IDevModifyOptions options) { - foreach (IAction subAction in subActions) - { - subAction.ModifyDevNames(newTechObjectN, oldTechObjectN, - techObjectName); - } - } + Parameters?.OfType().ToList() + .ForEach(p => p.ModifyDevNames(options)); - override public void ModifyDevNames(string newTechObjectName, - int newTechObjectNumber, string oldTechObjectName, - int oldTechObjectNumber) - { - foreach (IAction subAction in subActions) - { - subAction.ModifyDevNames(newTechObjectName, - newTechObjectNumber, oldTechObjectName, - oldTechObjectNumber); - } - } - - public override void ModifyDevNames(IDevModifyOptions modifyOptions) - { - //Parameters.ForEach(p => - //{ - // if (p is ActionParameter actionParameter) - // { - // actionParameter.ModifyDevName(modifyOptions); - // } - //}); - - subActions.ForEach(sa => sa.ModifyDevNames(modifyOptions)); + subActions.ForEach(sa => sa.ModifyDevNames(options)); } #region Синхронизация устройств в объекте. diff --git a/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs b/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs index a9631594..30eb258c 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs @@ -4,6 +4,7 @@ using Editor; using Eplan.EplApi.Base; using EplanDevice; +using StaticHelper; namespace TechObject { @@ -123,25 +124,31 @@ public string SaveAsLuaTable(string prefix) return res; } - public void ModifyDevNames(string newTechObjName, int techNumber) - { - var properties = items.Select(x => x as BaseParameter).ToArray(); - foreach (var property in properties) - { - var oldDevsNames = property.Value.Split(' '); - var devices = oldDevsNames - .Select(devName => deviceManager.GetDevice(devName)); - var newDevicesNames = devices - .Where(device => device.Description != StaticHelper.CommonConst.Cap) - .Select(device => $"{newTechObjName}{techNumber}{device.DeviceType}{device.DeviceNumber}") - .Where(newDevName => deviceManager.GetDevice(newDevName).Description != StaticHelper.CommonConst.Cap); - - if (newDevicesNames.Any()) + /// + /// Модификация названий устройств в соответствие тех.объекту + /// + /// + /// Так как в поле "Оборудование" привязывается устройства только данного объекта,
+ /// то нужно устройств заменить только объект на новый. + ///
+ /// Название тех.объекта + /// Тех.номер объекта + public void ModifyDevNames(string techObjName, int techNumber) + { + items.OfType().ToList() + .ForEach(property => { - property.SetNewValue(string.Join(" ", newDevicesNames)); - } - } + var newValues = property.Value.Split(' ') + .Select(deviceManager.GetDeviceByEplanName) + .Select(dev => $"{techObjName}{techNumber}{dev.DeviceDesignation}") + .Where(name => deviceManager.GetDevice(name).Description != CommonConst.Cap); + + if (newValues.Any()) + { + property.SetNewValue(string.Join(" ", newValues)); + } + }); } public void ModifyDevNames() @@ -340,7 +347,7 @@ public override ITreeViewItem Replace(object child, if (objectsNotNull) { property.SetNewValue(copiedObject.Value); - ModifyDevNames(owner.NameEplan, owner.TechNumber); + ModifyDevNames(); property.AddParent(this); return property; diff --git a/src/TechObject/ObjectsTree/UniversalObject/Mode.cs b/src/TechObject/ObjectsTree/UniversalObject/Mode.cs index a0928425..b9641fe9 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Mode.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Mode.cs @@ -133,9 +133,10 @@ public Mode Clone(GetN getN, ModesManager newOwner, string name = "") return clone; } - public void ModifyDevNames(IDevModifyOptions modifyOptions) + public void ModifyDevNames(IDevModifyOptions options) { - stepsMngr.ForEach(state => state.ModifyDevNames(modifyOptions)); + BaseOperation.Properties.ForEach(p => p.ModifyDevNames(options)); + stepsMngr.ForEach(state => state.ModifyDevNames(options)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs b/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs index 385c0841..65079044 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs @@ -34,9 +34,9 @@ public ModesManager Clone(TechObject owner) return clone; } - public void ModifyDevNames(IDevModifyOptions modifyOptions) + public void ModifyDevNames(IDevModifyOptions options) { - modes.ForEach(mode => mode.ModifyDevNames(modifyOptions)); + modes.ForEach(mode => mode.ModifyDevNames(options)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/State.cs b/src/TechObject/ObjectsTree/UniversalObject/State.cs index 630ba8ea..2d8e9b53 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/State.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/State.cs @@ -99,9 +99,9 @@ public State Clone(string name = "") return clone; } - public void ModifyDevNames(IDevModifyOptions modifyOptions) + public void ModifyDevNames(IDevModifyOptions options) { - steps.ForEach(step => step.ModifyDevNames(modifyOptions)); + steps.ForEach(step => step.ModifyDevNames(options)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/Step.cs b/src/TechObject/ObjectsTree/UniversalObject/Step.cs index e60c836f..2e93655d 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Step.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Step.cs @@ -453,9 +453,9 @@ public Step Clone(GetN getN, string name = "") return clone; } - public void ModifyDevNames(IDevModifyOptions modifyOptions) + public void ModifyDevNames(IDevModifyOptions options) { - actions.ForEach(action => action.ModifyDevNames(modifyOptions)); + actions.ForEach(action => action.ModifyDevNames(options)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs b/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs index 8f24818c..56783d23 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs @@ -533,6 +533,7 @@ public Mode GetMode(int i) public void ModifyDevNames(string oldTechObjectName, int? oldTechObjectNumber) { modes.ModifyDevNames(new DevModifyOptions(this, oldTechObjectName ?? NameEplan, oldTechObjectNumber ?? TechNumber)); + equipment.ModifyDevNames(); } /// @@ -956,7 +957,7 @@ override public ITreeViewItem Replace(object child, } } } - equipment.ModifyDevNames(NameEplan, TechNumber); + equipment.ModifyDevNames(); equipment.AddParent(this); return equipment;