From 88bc675f8a58d6f5ba9ba67845f65c4fc6fee52c Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Wed, 31 Jul 2024 16:56:10 +0300 Subject: [PATCH 01/10] Unification of modify device name --- src/Device/DeviceManager.cs | 88 +++++++++++++++++++ src/EasyEPlanner.csproj | 1 + src/TechObject/Base/BaseParameter.cs | 26 ++++++ src/TechObject/DevModifyOptions.cs | 61 +++++++++++++ .../UniversalObject/Actions/Action.cs | 24 +++++ .../Actions/GroupableAction.cs | 13 +++ .../UniversalObject/GenericTechObject.cs | 2 +- .../ObjectsTree/UniversalObject/Mode.cs | 21 +---- .../UniversalObject/ModesManager.cs | 30 ++----- .../ObjectsTree/UniversalObject/State.cs | 20 +---- .../ObjectsTree/UniversalObject/Step.cs | 20 +---- .../ObjectsTree/UniversalObject/TechObject.cs | 21 ++--- 12 files changed, 235 insertions(+), 92 deletions(-) create mode 100644 src/TechObject/DevModifyOptions.cs diff --git a/src/Device/DeviceManager.cs b/src/Device/DeviceManager.cs index 592e9cc0..cdb14d6b 100644 --- a/src/Device/DeviceManager.cs +++ b/src/Device/DeviceManager.cs @@ -7,6 +7,9 @@ using EasyEPlanner; using System.Text; using System.Security.Cryptography; +using TechObject; +using StaticHelper; +using static System.Windows.Forms.Design.AxImporter; /// /// Пространство имен технологических устройств проекта (клапана, насосы...). @@ -22,6 +25,8 @@ public interface IDeviceManager /// int GetDeviceIndex(string devName); + int GetDeviceIndex(IDevice dev); + /// /// Возвращает устройство по его имени в Eplan /// @@ -70,6 +75,16 @@ public interface IDeviceManager /// Имя устройства. /// Устройство с заданными именем или заглушка. IODevice GetDevice(string devName); + + /// + /// Получить модифицированное устройство + /// + /// + /// + /// + /// + /// + IDevice GetModifiedDevice(IDevice device, IDevModifyOptions modifyOptions); } /// @@ -311,6 +326,11 @@ public int GetDeviceIndex(string devName) return resDevN; } + public int GetDeviceIndex(IDevice dev) + { + return devices.IndexOf(dev as IODevice); + } + /// /// Шаблон для разбора имени для привязки устройств @@ -1112,6 +1132,74 @@ private bool IsPIDControl(string type) return isPID; } + private IDevice ModifyMixproof(IDevice device, IDevModifyOptions options) + { + var mixproofRegex = new Regex($@"(.+V\d*)(?:{options.OldTechObjectNumber})"); + + if (options.NumberModified && + options.IsUnit && + options.OldTechObjectName != device.ObjectName && + (device as IIODevice)?.AllowedType(DeviceType.V) is true && + (device as IIODevice)?.AllowedSubtype( + DeviceSubType.V_DO1_DI2, + DeviceSubType.V_DO2_DI2, + DeviceSubType.V_DO2_DI2_BISTABLE, + DeviceSubType.V_MIXPROOF, + DeviceSubType.V_BOTTOM_MIXPROOF, + DeviceSubType.V_IOLINK_MIXPROOF, + DeviceSubType.V_AS_MIXPROOF, + DeviceSubType.V_AS_DO1_DI2, + DeviceSubType.V_IOLINK_DO1_DI2, + DeviceSubType.V_IOL_TERMINAL_MIXPROOF_DO3) is true) + { // Если клапан-mixproof привязан к Аппарату и имеет отличное от его ОУ + var match = mixproofRegex.Match(device.Name); + if (match.Success) + { + var mixproofP = match.Groups[1].Value; + return GetDeviceByEplanName($"{mixproofP}{options.NewTechObjectNumber}"); + } + } + + return null; + } + + public IDevice GetModifiedDevice(IDevice device, IDevModifyOptions options) + { + if (ModifyMixproof(device, options) is IDevice mixproof) + { + return mixproof.Description == CommonConst.Cap ? null : mixproof; + } + + IDevice res = null; + + if (options.NumberModified && + options.OldTechObjectNumber != 0 && // Не модифицировать устройства в типовых объектах + device.Description != CommonConst.Cap && + device.ObjectName == options.OldTechObjectName && + device.ObjectNumber > 0) + { + if (options.OldTechObjectNumber == -1 || device.ObjectNumber == options.OldTechObjectNumber) + { + // Изменяем номер объекта в устройстве в соответствии с изменениями объекта или для типовых объектов: + // ( 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}"); + } + else if (device.ObjectNumber == options.NewTechObjectNumber) + { + // Инверсионное изменение номера объекта: когда устройство имеет номер объекта равный новому номеру объекта + // ( 1 -> 2 ) : OBJ[2]V1 -> OBJ[1]V1 + res = GetDeviceByEplanName($"{device.ObjectName}{options.OldTechObjectNumber}{device.DeviceDesignation}"); + } + } + else if (options.NameModified && device.ObjectName == options.OldTechObjectName) + { + res = GetDeviceByEplanName($"{options.NewTechObjectName}{device.ObjectNumber}{device.DeviceDesignation}"); + } + + return res?.Description == CommonConst.Cap ? null : res; + } + /// /// Шаблон для получение ОУ устройства. /// diff --git a/src/EasyEPlanner.csproj b/src/EasyEPlanner.csproj index 2dde0fe2..e604896e 100644 --- a/src/EasyEPlanner.csproj +++ b/src/EasyEPlanner.csproj @@ -348,6 +348,7 @@ + diff --git a/src/TechObject/Base/BaseParameter.cs b/src/TechObject/Base/BaseParameter.cs index 8b08ba46..6f71af3a 100644 --- a/src/TechObject/Base/BaseParameter.cs +++ b/src/TechObject/Base/BaseParameter.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using EasyEPlanner; using EplanDevice; +using StaticHelper; namespace TechObject { @@ -542,6 +544,30 @@ public virtual void Check() } } + public void ModifyDevNames(int newID, int oldID, + string objName) + { + if (!OnlyDevicesInParameter) + return; + + + 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 modified = deviceManager.GetDeviceByEplanName($"{objName}{(oldID == -1 || oldID == dev.ObjectNumber ? newID : oldID)}{dev.DeviceDesignation}"); + return modified.Description == CommonConst.Cap ? dev : modified; + }) + .Concat(notObjectDevices).Select(dev => dev.Name); + + SetNewValue(string.Join(" ", newValues)); + } + /// /// Текущий тип значений, принимаемый параметром /// diff --git a/src/TechObject/DevModifyOptions.cs b/src/TechObject/DevModifyOptions.cs new file mode 100644 index 00000000..513220ce --- /dev/null +++ b/src/TechObject/DevModifyOptions.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace TechObject +{ + public interface IDevModifyOptions + { + bool IsUnit { get; } + + bool IsGeneric { get; } + + bool NumberModified { get; } + + bool NameModified { get; } + + string OldTechObjectName { get; } + + int OldTechObjectNumber { get; } + + string NewTechObjectName { get; } + + int NewTechObjectNumber { get; } + } + + + public class DevModifyOptions : IDevModifyOptions + { + private TechObject techObject; + private string oldTechObjectName; + private int oldTechObjectNumber; + + public DevModifyOptions(TechObject techObject, string oldTechObjectName, int oldTechObjectNumber) + { + this.techObject = techObject; + this.oldTechObjectName = oldTechObjectName; + this.oldTechObjectNumber = oldTechObjectNumber; + } + + + public bool NumberModified => OldTechObjectNumber != NewTechObjectNumber; + + public bool IsGeneric => techObject is GenericTechObject; + + public bool NameModified => OldTechObjectName != NewTechObjectName; + + public bool IsUnit => techObject.BaseTechObject.S88Level == (int)BaseTechObjectManager.ObjectType.Unit; + + public string OldTechObjectName => oldTechObjectName; + + public int OldTechObjectNumber => oldTechObjectNumber; + + public string NewTechObjectName => techObject.NameEplan; + + public int NewTechObjectNumber => techObject.TechNumber; + + } +} diff --git a/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs b/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs index f5700426..572b7eaf 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs @@ -11,6 +11,7 @@ using BrightIdeasSoftware; using EasyEPlanner; using Editor; +using EplanDevice; using TechObject.ActionProcessingStrategy; namespace TechObject @@ -96,6 +97,8 @@ void ModifyDevNames(int newTechObjectN, int oldTechObjectN, void ModifyDevNames(string newTechObjectName, int newTechObjectNumber, string oldTechObjectName, int oldTechObjNumber); + void ModifyDevNames(IDevModifyOptions modifyOptions); + List GetObjectToDrawOnEplanPage(); DrawInfo.Style DrawStyle { get; set; } @@ -301,6 +304,8 @@ private string ModifyDevNameChangeTechNumber(string techObjectName, int index, i if (objNum <= 0 || techObjectName != objName) return string.Empty; + //deviceManager.GetModifiedDevice + //Для устройств в пределах объекта меняем номер объекта. if (objNum == newID && oldID != -1) { // 1 -> 2 - COAG2V1 --> COAG1V1 @@ -314,6 +319,25 @@ private string ModifyDevNameChangeTechNumber(string techObjectName, int index, i return string.Empty; } + public virtual void ModifyDevNames(IDevModifyOptions modifyOptions) + { + //if (modifyOptions.OldTechObjectNumber != 0) + deviceIndex = ModifyDevName(deviceIndex, modifyOptions); + genericDeviceIndex = ModifyDevName(genericDeviceIndex, modifyOptions, true); + + deviceIndex = IndexesExclude(deviceIndex, genericDeviceIndex); + } + + private List ModifyDevName(List DevsIdx, IDevModifyOptions modifyOptions, 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) + .ToList(); + } + public virtual string SaveAsLuaTable(string prefix) { if (GetAllDeviceIndex().Count == 0) diff --git a/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs b/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs index d187a4d1..6e2a32e4 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Actions/GroupableAction.cs @@ -34,6 +34,19 @@ override public void ModifyDevNames(string newTechObjectName, } } + public override void ModifyDevNames(IDevModifyOptions modifyOptions) + { + //Parameters.ForEach(p => + //{ + // if (p is ActionParameter actionParameter) + // { + // actionParameter.ModifyDevName(modifyOptions); + // } + //}); + + subActions.ForEach(sa => sa.ModifyDevNames(modifyOptions)); + } + #region Синхронизация устройств в объекте. /// /// Синхронизация индексов устройств. diff --git a/src/TechObject/ObjectsTree/UniversalObject/GenericTechObject.cs b/src/TechObject/ObjectsTree/UniversalObject/GenericTechObject.cs index 6c6fd343..a8a194a3 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/GenericTechObject.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/GenericTechObject.cs @@ -132,7 +132,7 @@ private void UpdateObjectGroups(object sender) private void UpdateModesManager(object sender) { InheritedTechObjects.ForEach(to => to.ModesManager.UpdateOnGenericTechObject(ModesManager)); - InheritedTechObjects.ForEach(to => to.ModifyDevNames(-1)); + InheritedTechObjects.ForEach(to => to.ModifyDevNames(null, -1)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/Mode.cs b/src/TechObject/ObjectsTree/UniversalObject/Mode.cs index 3fda47dd..a0928425 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Mode.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Mode.cs @@ -133,26 +133,9 @@ public Mode Clone(GetN getN, ModesManager newOwner, string name = "") return clone; } - public void ModifyDevNames(int newTechObjectN, int oldTechObjectN, - string techObjectName) + public void ModifyDevNames(IDevModifyOptions modifyOptions) { - foreach (State stpsMngr in stepsMngr) - { - stpsMngr.ModifyDevNames(newTechObjectN, oldTechObjectN, - techObjectName); - } - } - - public void ModifyDevNames(string newTechObjectName, - int newTechObjectNumber, string oldTechObjectName, - int oldTechObjectNumber) - { - foreach (State stpsMngr in stepsMngr) - { - stpsMngr.ModifyDevNames(newTechObjectName, - newTechObjectNumber, oldTechObjectName, - oldTechObjectNumber); - } + stepsMngr.ForEach(state => state.ModifyDevNames(modifyOptions)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs b/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs index defba7c4..385c0841 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs @@ -34,23 +34,9 @@ public ModesManager Clone(TechObject owner) return clone; } - public void ModifyDevNames(int oldTechObjectN) + public void ModifyDevNames(IDevModifyOptions modifyOptions) { - foreach (Mode mode in modes) - { - mode.ModifyDevNames(owner.TechNumber, oldTechObjectN, - owner.NameEplan); - } - } - - public void ModifyDevNames(string newTechObjectName, - int newTechObjectNumber) - { - foreach (Mode mode in modes) - { - mode.ModifyDevNames(newTechObjectName, newTechObjectNumber, - owner.NameEplan, owner.TechNumber); - } + modes.ForEach(mode => mode.ModifyDevNames(modifyOptions)); } /// @@ -431,13 +417,11 @@ override public ITreeViewItem Replace(object child, int copyObjTechObjNumber = copyMode.Owner.Owner.TechNumber; if (modeTechObjName == copyObjTechObjName) { - newMode.ModifyDevNames(owner.TechNumber, -1, - owner.NameEplan); + newMode.ModifyDevNames(new DevModifyOptions(Owner, Owner.NameEplan, -1)); } else { - newMode.ModifyDevNames(modeTechObjName, modeTechObjNumber, - copyObjTechObjName, copyObjTechObjNumber); + newMode.ModifyDevNames(new DevModifyOptions(Owner, copyObjTechObjName, Owner.TechNumber)); } ChangeRestrictionModeOwner(newMode); @@ -476,13 +460,11 @@ override public ITreeViewItem InsertCopy(object obj) int objMobeTechObjectNumber = objMode.Owner.Owner.TechNumber; if (owner.NameEplan == objModeTechObjectName) { - newMode.ModifyDevNames(owner.TechNumber, -1, - owner.NameEplan); + newMode.ModifyDevNames(new DevModifyOptions(Owner, Owner.NameEplan, -1)); } else { - newMode.ModifyDevNames(owner.NameEplan, owner.TechNumber, - objModeTechObjectName, objMobeTechObjectNumber); + newMode.ModifyDevNames(new DevModifyOptions(Owner, objModeTechObjectName, Owner.TechNumber)); } ChangeRestrictionModeOwner(newMode); diff --git a/src/TechObject/ObjectsTree/UniversalObject/State.cs b/src/TechObject/ObjectsTree/UniversalObject/State.cs index 443bd4a1..630ba8ea 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/State.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/State.cs @@ -99,25 +99,9 @@ public State Clone(string name = "") return clone; } - public void ModifyDevNames(int newTechObjectN, int oldTechObjectN, - string techObjectName) + public void ModifyDevNames(IDevModifyOptions modifyOptions) { - foreach (Step step in steps) - { - step.ModifyDevNames(newTechObjectN, oldTechObjectN, - techObjectName); - } - } - - public void ModifyDevNames(string newTechObjectName, - int newTechObjectNumber, string oldTechObjectName, - int oldTechObjectNumber) - { - foreach (Step step in steps) - { - step.ModifyDevNames(newTechObjectName, newTechObjectNumber, - oldTechObjectName, oldTechObjectNumber); - } + steps.ForEach(step => step.ModifyDevNames(modifyOptions)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/Step.cs b/src/TechObject/ObjectsTree/UniversalObject/Step.cs index a47b2850..e60c836f 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Step.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Step.cs @@ -453,25 +453,9 @@ public Step Clone(GetN getN, string name = "") return clone; } - public void ModifyDevNames(int newTechObjectN, int oldTechObjectN, - string techObjectName) + public void ModifyDevNames(IDevModifyOptions modifyOptions) { - foreach (IAction action in actions) - { - action.ModifyDevNames(newTechObjectN, - oldTechObjectN, techObjectName); - } - } - - public void ModifyDevNames(string newTechObjectName, - int newTechObjectNumber, string oldTechObjectName, - int oldTechObjectNumber) - { - foreach (IAction action in actions) - { - action.ModifyDevNames(newTechObjectName, newTechObjectNumber, - oldTechObjectName, oldTechObjectNumber); - } + actions.ForEach(action => action.ModifyDevNames(modifyOptions)); } /// diff --git a/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs b/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs index eb78f68c..8f24818c 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/TechObject.cs @@ -42,10 +42,13 @@ public override bool SetNewValue(string newValue) StaticHelper.CommonConst.RusAsEngPattern, StaticHelper.CommonConst.RusAsEngEvaluator); - owner.ModifyDevNames(newValue); + var oldValue = Value.ToString(); + base.SetNewValue(newValue); owner.CompareEplanNames(); + owner.ModifyDevNames(oldValue, null); + return true; } @@ -89,7 +92,7 @@ public override bool SetNewValue(string newValue) bool res = base.SetNewValue(newValue); if (res) { - techObject.ModifyDevNames(oldNumber); + techObject.ModifyDevNames(null, oldNumber); } return true; } @@ -375,7 +378,8 @@ public TechObject Clone(GetN getLocalNum, int newNumber, clone.systemParams = systemParams.Clone(); clone.modes = modes.Clone(clone); - clone.modes.ModifyDevNames(TechNumber); + clone.modes.ModifyDevNames(new DevModifyOptions(clone, clone.NameEplan, TechNumber)); + clone.modes.ModifyRestrictObj(oldGlobalNum, newGlobalNum); clone.equipment = equipment.Clone(clone); @@ -526,16 +530,9 @@ public Mode GetMode(int i) return null; } - public void ModifyDevNames(int oldNumber) - { - modes.ModifyDevNames(oldNumber); - equipment.ModifyDevNames(); - } - - public void ModifyDevNames(string newTechObjectName) + public void ModifyDevNames(string oldTechObjectName, int? oldTechObjectNumber) { - modes.ModifyDevNames(newTechObjectName, this.TechNumber); - equipment.ModifyDevNames(newTechObjectName, this.TechNumber); + modes.ModifyDevNames(new DevModifyOptions(this, oldTechObjectName ?? NameEplan, oldTechObjectNumber ?? TechNumber)); } /// From afe1853f769b06cac1813a192125cec10978ff7a Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Thu, 1 Aug 2024 17:01:27 +0300 Subject: [PATCH 02/10] 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; From ad6ee1314703d029f51d7af04371ccdadb9d454e Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Fri, 2 Aug 2024 09:17:25 +0300 Subject: [PATCH 03/10] Tests --- .../EplanDevice.Test/DeviceManager.Test.cs | 77 ++++++++++++++++ .../Properties.Test/ActionParameter.Test.cs | 41 --------- .../Actions.Test/Action.Test.cs | 66 -------------- .../UniversalObject.Test/Equipment.Test.cs | 90 +++++++++---------- src/Device/DeviceManager.cs | 6 +- src/TechObject/DevModifyOptions.cs | 4 - 6 files changed, 125 insertions(+), 159 deletions(-) diff --git a/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs b/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs index 8fc4f281..96a1827b 100644 --- a/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs +++ b/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs @@ -1,6 +1,10 @@ using EplanDevice; +using Moq; using NUnit.Framework; +using StaticHelper; using System; +using System.Windows.Forms; +using TechObject; namespace Tests.EplanDevices { @@ -46,6 +50,28 @@ public void SetUpDevices() var C_THLD = new C("OBJ1C2", "+OBJ1-C2", string.Empty, 2, "OBJ", 1); C_THLD.SetSubType("C_THLD"); devManager.Devices.Add(C_THLD); + + + // .GetModifiedDevice() + var mixproof_1 = new V("NOOBJ1V111", "+NOOBJ1-V111", "", 111, "NOOBJ", 1, ""); + mixproof_1.SetSubType("V_AS_MIXPROOF"); + devManager.Devices.Add(mixproof_1); + + var mixproof_2 = new V("NOOBJ1V112", "+NOOBJ1-V112", "", 112, "NOOBJ", 1, ""); + mixproof_2.SetSubType("V_AS_MIXPROOF"); + devManager.Devices.Add(mixproof_2); + + var dev_1 = new V("OBJ1V1", "+OBJ1-V1", "", 1, "OBJ", 1, ""); + devManager.Devices.Add(dev_1); + + var dev_2 = new V("OBJ2V1", "+OBJ2-V1", "", 1, "OBJ", 2, ""); + devManager.Devices.Add(dev_2); + + var dev_3 = new V("OTHER1V1", "+OTHER1-V1", "", 1, "OTHER", 1, ""); + devManager.Devices.Add(dev_3); + + var dev_4 = new V("OTHER2V1", "+OTHER2-V1", "", 1, "OTHER", 2, ""); + devManager.Devices.Add(dev_4); } [TestCase("+LINE1-V2", false)] @@ -203,5 +229,56 @@ public void CheckControllerIOProperties_EmptyAllowedDevice() Assert.AreEqual(string.Empty, res); } + + [TestCaseSource(nameof(GetModifiedDevice_TestCaseSource))] + public void GetModifiedDevice( + string oldObjName, int oldTechNumber, + string newObjName, int newTechNumber, + string modify, string expectedModified, + bool isCap) + { + var manager = DeviceManager.GetInstance(); + var optionsMock = new Mock(); + + optionsMock.Setup(o => o.IsUnit).Returns(true); + optionsMock.Setup(o => o.NameModified).Returns(oldObjName != newObjName); + optionsMock.Setup(o => o.NumberModified).Returns(oldTechNumber != newTechNumber); + optionsMock.Setup(o => o.OldTechObjectName).Returns(oldObjName); + optionsMock.Setup(o => o.OldTechObjectNumber).Returns(oldTechNumber); + optionsMock.Setup(o => o.NewTechObjectName).Returns(newObjName); + optionsMock.Setup(o => o.NewTechObjectNumber).Returns(newTechNumber); + + var modified = manager.GetModifiedDevice( + manager.GetDeviceByEplanName(modify), + optionsMock.Object); + + Assert.Multiple(() => + { + Assert.AreEqual(expectedModified, modified?.Name); + Assert.AreEqual(isCap, modified?.Description == CommonConst.Cap); + }); + } + + private static readonly object[] GetModifiedDevice_TestCaseSource = new object[] + { + new object[] { "OBJ", 11, "OBJ", 12, "NOOBJ1V111", "NOOBJ1V112", false }, + new object[] { "OBJ", 11, "OBJ", 13, "NOOBJ1V111", null, false }, + new object[] { "OBJ", 11, "OBJECT", 11, "NOOBJ1V111", "NOOBJ1V111", false }, + new object[] { "OBJ", 12, "OBJ", 11, "NOOBJ1V111", "NOOBJ1V111", false }, + + new object[] { "OBJ", 1, "OBJ", 2, "OBJ1V1", "OBJ2V1", false }, + new object[] { "OBJ", 2, "OBJ", 3, "OBJ2V1", "OBJ3V1", true }, + new object[] { "OBJ", 1, "OBJ", 2, "OBJ2V1", "OBJ1V1", false }, + new object[] { "OBJ", 3, "OBJ", 2, "OBJ1V1", "OBJ1V1", false }, + + new object[] { "OBJ", 1, "OTHER", 1, "OBJ1V1", "OTHER1V1", false }, + new object[] { "OBJ", 1, "OTHER", 1, "OTHER1V1", "OTHER1V1", false }, + + new object[] { "OBJ", -1, "OBJ", 1, "OBJ2V1", "OBJ1V1", false }, + new object[] { "OBJ", -1, "OBJ", 2, "OBJ2V1", "OBJ2V1", false }, + new object[] { "OBJ", -1, "OBJ", 3, "OBJ2V1", "OBJ3V1", true }, + + new object[] { "OTHER", 1, "OTHER", 1, "OTHER1V1", "OTHER1V1", false }, + }; } } 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 1d7b94b7..73c9816e 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 @@ -68,46 +68,5 @@ public void SetNewValue_and_DisplayText_DisplayParameter() Assert.IsNull(actionParameter.Parameter); }); } - - //[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, ""); - - // 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.GetDeviceByIndex(0)).Returns(dev1); - // deviceManagerMock.Setup(m => m.GetDeviceByIndex(1)).Returns(dev2); - - // 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()); - //} } } 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 c2b8b20a..c49254c4 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,72 +551,6 @@ 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, 3, 5, 7, 9 })] [TestCase(new int[0])] public void Clone_NewAction_ReturnsCopy(int[] devIds) 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 0fd279ca..2cc02ddf 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); - - // equipment.AddItems(new List() { equipmentParameter }); + typeof(Equipment).GetProperty("deviceManager", + System.Reflection.BindingFlags.NonPublic | + System.Reflection.BindingFlags.Static) + .SetValue(null, deviceManagerMock.Object); - // equipment.SetEquipmentValue("devs", "OBJ1V1 OBJ2V2 OBJ3V3"); + equipment.AddItems(new List() { equipmentParameter }); - // equipment.ModifyDevNames(); + equipment.SetEquipmentValue("devs", "OBJ1V1 OBJ2V2 OBJ3V3"); - // Assert.AreEqual($"{nameof(OBJ3V1)} {nameof(OBJ3V2)} {nameof(OBJ3V3)}", equipmentParameter.Value); - //} + equipment.ModifyDevNames(); + + Assert.AreEqual($"{nameof(OBJ3V1)} {nameof(OBJ3V2)} {nameof(OBJ3V3)}", equipmentParameter.Value); + } } } diff --git a/src/Device/DeviceManager.cs b/src/Device/DeviceManager.cs index c183150a..22eb56f2 100644 --- a/src/Device/DeviceManager.cs +++ b/src/Device/DeviceManager.cs @@ -1137,7 +1137,7 @@ private IDevice ModifyMixproof(IDevice device, IDevModifyOptions options) var mixproofRegex = new Regex($@"(.+V\d*)(?:{options.OldTechObjectNumber})"); if (options.NumberModified && - options.IsUnit && + options.IsUnit && options.OldTechObjectName != device.ObjectName && (device as IIODevice)?.AllowedType(DeviceType.V) is true && (device as IIODevice)?.AllowedSubtype( @@ -1158,6 +1158,7 @@ private IDevice ModifyMixproof(IDevice device, IDevModifyOptions options) var mixproofP = match.Groups[1].Value; return GetDeviceByEplanName($"{mixproofP}{options.NewTechObjectNumber}"); } + else return device; } return null; @@ -1167,8 +1168,7 @@ public IDevice GetModifiedDevice(IDevice device, IDevModifyOptions options) { if (ModifyMixproof(device, options) is IDevice mixproof) { - return mixproof.Description == CommonConst.Cap ? null : mixproof; - // null - удаляем привязку устройства + return mixproof.Description == CommonConst.Cap ? null : mixproof; // null - удаляем привязку устройства } if (options.NumberModified && diff --git a/src/TechObject/DevModifyOptions.cs b/src/TechObject/DevModifyOptions.cs index 513220ce..1ef992c7 100644 --- a/src/TechObject/DevModifyOptions.cs +++ b/src/TechObject/DevModifyOptions.cs @@ -11,8 +11,6 @@ public interface IDevModifyOptions { bool IsUnit { get; } - bool IsGeneric { get; } - bool NumberModified { get; } bool NameModified { get; } @@ -43,8 +41,6 @@ public DevModifyOptions(TechObject techObject, string oldTechObjectName, int old public bool NumberModified => OldTechObjectNumber != NewTechObjectNumber; - public bool IsGeneric => techObject is GenericTechObject; - public bool NameModified => OldTechObjectName != NewTechObjectName; public bool IsUnit => techObject.BaseTechObject.S88Level == (int)BaseTechObjectManager.ObjectType.Unit; From f5bc950d65e1d7e79744526ffa3dd01852434888 Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Fri, 2 Aug 2024 10:56:56 +0300 Subject: [PATCH 04/10] Fix tests and comments --- .../ObjectsTree.Test/BaseObject.Test.cs | 18 +++++----- .../UniversalObject.Test/Equipment.Test.cs | 25 ++++++-------- src/Device/DeviceManager.cs | 13 ++++--- .../Base/Properties/ActionParameter.cs | 10 +++--- src/TechObject/DevModifyOptions.cs | 34 ++++++++++++++++++- .../UniversalObject/Actions/Action.cs | 4 +++ .../ObjectsTree/UniversalObject/Equipment.cs | 2 +- 7 files changed, 72 insertions(+), 34 deletions(-) diff --git a/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/BaseObject.Test.cs b/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/BaseObject.Test.cs index 114891c2..d7f41b38 100644 --- a/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/BaseObject.Test.cs +++ b/EasyEplanner.Tests/TechObject.Test/ObjectsTree.Test/BaseObject.Test.cs @@ -489,7 +489,6 @@ public void CreateGenericGroup_FromManyTechObjects() Assert.AreEqual(expT1Step.GetStepName(), steps[1].GetStepName()); CollectionAssert.AreEqual(new[] { "TANK1V1", "DO1" }, actionOnDevices.DevicesNames); CollectionAssert.AreEqual(new[] { "TANK1V1" }, actionDelayOnDevices.SubActions[0].SubActions[0].DevicesNames); - CollectionAssert.AreEqual(new[] { "TANK1V1" }, actionDelayOnDevices.SubActions[0].SubActions[0].DevicesNames); }); } @@ -503,28 +502,31 @@ private void SetupDeviceManagerMock() var TANK1V1 = new V("TANK1V1", "+TANK1-V1", "desc", 1, "TANK", 1, ""); var TANK2V1 = new V("TANK2V1", "+TANK2-V1", "desc", 1, "TANK", 2, ""); - + deviceManagerMock.Setup(m => m.GetDeviceByEplanName(It.IsAny())).Returns(capDevice); deviceManagerMock.Setup(m => m.GetDeviceByEplanName("LS1")).Returns(LS1); deviceManagerMock.Setup(m => m.GetDeviceByEplanName("TANK1V1")).Returns(TANK1V1); deviceManagerMock.Setup(m => m.GetDeviceByEplanName("TANK2V1")).Returns(TANK2V1); deviceManagerMock.Setup(m => m.GetDeviceByEplanName("DO1")).Returns(DO1); - deviceManagerMock.Setup(m => m.GetDeviceByEplanName(It.IsAny())).Returns(capDevice); - - deviceManagerMock.Setup(m => m.GetDevice("LS1")).Returns(LS1); - deviceManagerMock.Setup(m => m.GetDevice("TANK1V1")).Returns(TANK1V1); - deviceManagerMock.Setup(m => m.GetDevice("TANK2V1")).Returns(TANK2V1); - deviceManagerMock.Setup(m => m.GetDevice("DO1")).Returns(DO1); deviceManagerMock.Setup(m => m.GetDeviceIndex("LS1")).Returns(0); deviceManagerMock.Setup(m => m.GetDeviceIndex("TANK1V1")).Returns(1); deviceManagerMock.Setup(m => m.GetDeviceIndex("TANK2V1")).Returns(2); deviceManagerMock.Setup(m => m.GetDeviceIndex("DO1")).Returns(3); + deviceManagerMock.Setup(m => m.GetDeviceIndex(LS1)).Returns(0); + deviceManagerMock.Setup(m => m.GetDeviceIndex(TANK1V1)).Returns(1); + deviceManagerMock.Setup(m => m.GetDeviceIndex(TANK2V1)).Returns(2); + deviceManagerMock.Setup(m => m.GetDeviceIndex(DO1)).Returns(3); + deviceManagerMock.Setup(m => m.GetDeviceByIndex(0)).Returns(LS1); deviceManagerMock.Setup(m => m.GetDeviceByIndex(1)).Returns(TANK1V1); deviceManagerMock.Setup(m => m.GetDeviceByIndex(2)).Returns(TANK2V1); deviceManagerMock.Setup(m => m.GetDeviceByIndex(3)).Returns(DO1); + deviceManagerMock.Setup(m => m.GetModifiedDevice(TANK1V1, It.IsAny())).Returns(TANK1V1); + deviceManagerMock.Setup(m => m.GetModifiedDevice(TANK2V1, It.IsAny())).Returns(TANK1V1); + deviceManagerMock.Setup(m => m.GetModifiedDevice(LS1, It.IsAny())).Returns(LS1); + deviceManagerMock.Setup(m => m.GetModifiedDevice(DO1, It.IsAny())).Returns(DO1); typeof(BaseParameter).GetField("deviceManager", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) 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 2cc02ddf..76eec381 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 @@ -15,23 +15,23 @@ 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); + 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); var deviceManagerMock = new Mock(); - deviceManagerMock.Setup(dm => dm.GetDevice(It.IsAny())).Returns(CAP); + deviceManagerMock.Setup(dm => dm.GetDeviceByEplanName(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.GetDeviceByEplanName(nameof(OBJ1V1))).Returns(OBJ1V1); + deviceManagerMock.Setup(dm => dm.GetDeviceByEplanName(nameof(OBJ2V2))).Returns(OBJ2V2); + deviceManagerMock.Setup(dm => dm.GetDeviceByEplanName(nameof(OBJ3V1))).Returns(OBJ3V1); + deviceManagerMock.Setup(dm => dm.GetDeviceByEplanName(nameof(OBJ3V2))).Returns(OBJ3V2); + deviceManagerMock.Setup(dm => dm.GetDeviceByEplanName(nameof(OBJ3V3))).Returns(OBJ3V3); deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ1V1))).Returns(0); deviceManagerMock.Setup(dm => dm.GetDeviceIndex(nameof(OBJ2V2))).Returns(1); @@ -45,9 +45,6 @@ public void ModifyDevNames() 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); - - var equipment = new Equipment( new TechObject.TechObject(string.Empty, GetN => 1, 3, 2, "OBJ", -1, string.Empty, string.Empty, new BaseTechObject())); diff --git a/src/Device/DeviceManager.cs b/src/Device/DeviceManager.cs index 22eb56f2..ae9bf967 100644 --- a/src/Device/DeviceManager.cs +++ b/src/Device/DeviceManager.cs @@ -79,11 +79,14 @@ public interface IDeviceManager /// /// Получить модифицированное устройство /// - /// - /// - /// - /// - /// + /// Исходное устройство для модификации + /// Опции модификации + /// + /// IDevice - модифицированное устройство
+ /// IDevice EQ device - исходное устройство без модификации
+ /// .DEscription == CAP - неопределенное устройство (в дальнейшем может быть как и удалено из привязки, так и заменено на исходное)
+ /// null - удаление устройства из привязки
+ ///
IDevice GetModifiedDevice(IDevice device, IDevModifyOptions modifyOptions); } diff --git a/src/TechObject/Base/Properties/ActionParameter.cs b/src/TechObject/Base/Properties/ActionParameter.cs index dbfa3ff1..87c8f391 100644 --- a/src/TechObject/Base/Properties/ActionParameter.cs +++ b/src/TechObject/Base/Properties/ActionParameter.cs @@ -69,11 +69,11 @@ public override void ModifyDevNames(IDevModifyOptions options) var modified = deviceManager.GetModifiedDevice( deviceManager.GetDeviceByEplanName(Value), options); - - if (modified?.Description != CommonConst.Cap) - { - SetNewValue(modified.Name); - } + + if (modified is null || modified.Description == CommonConst.Cap) + return; + + SetNewValue(modified.Name); } public override string Value diff --git a/src/TechObject/DevModifyOptions.cs b/src/TechObject/DevModifyOptions.cs index 1ef992c7..6a798112 100644 --- a/src/TechObject/DevModifyOptions.cs +++ b/src/TechObject/DevModifyOptions.cs @@ -7,30 +7,63 @@ namespace TechObject { + /// + /// Опции модификации устройств + /// public interface IDevModifyOptions { + /// + /// Тип модифицированного объекта - Аппарат
+ ///
+ /// + /// Используется при модификации MIXPROOF + /// bool IsUnit { get; } + /// + /// Модифицируется номер тех.объекта + /// bool NumberModified { get; } + /// + /// Модифицируется ОУ тех.объекта + /// bool NameModified { get; } + /// + /// Старое ОУ тех.объекта + /// string OldTechObjectName { get; } + /// + /// Старый номер тех.объекта + /// int OldTechObjectNumber { get; } + /// + /// Новое(текущее) ОУ тех.объекта + /// string NewTechObjectName { get; } + /// + /// Новый(текущий) номер тех.объекта + /// int NewTechObjectNumber { get; } } + /// + /// Опции модификации устройств + /// public class DevModifyOptions : IDevModifyOptions { private TechObject techObject; private string oldTechObjectName; private int oldTechObjectNumber; + /// Модифицируемый тех.объект + /// Старое ОУ теъ.объекта + /// Старый номер тех.объекта public DevModifyOptions(TechObject techObject, string oldTechObjectName, int oldTechObjectNumber) { this.techObject = techObject; @@ -38,7 +71,6 @@ public DevModifyOptions(TechObject techObject, string oldTechObjectName, int old this.oldTechObjectNumber = oldTechObjectNumber; } - public bool NumberModified => OldTechObjectNumber != NewTechObjectNumber; public bool NameModified => OldTechObjectName != NewTechObjectName; diff --git a/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs b/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs index 84d9b12f..3a3e51c8 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Actions/Action.cs @@ -92,6 +92,10 @@ void GetDisplayObjects(out EplanDevice.DeviceType[] validTypes, /// Описание действия в клетке Excel string SaveAsExcel(); + /// + /// Модифицировать название устройств в соответствие объекту + /// + /// Опции модификации устройств void ModifyDevNames(IDevModifyOptions options); List GetObjectToDrawOnEplanPage(); diff --git a/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs b/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs index 30eb258c..6806dcca 100644 --- a/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs +++ b/src/TechObject/ObjectsTree/UniversalObject/Equipment.cs @@ -142,7 +142,7 @@ public void ModifyDevNames(string techObjName, int techNumber) var newValues = property.Value.Split(' ') .Select(deviceManager.GetDeviceByEplanName) .Select(dev => $"{techObjName}{techNumber}{dev.DeviceDesignation}") - .Where(name => deviceManager.GetDevice(name).Description != CommonConst.Cap); + .Where(name => deviceManager.GetDeviceByEplanName(name).Description != CommonConst.Cap); if (newValues.Any()) { From 192610a26fea7e14061a814b25a69a6befea9656 Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Fri, 2 Aug 2024 13:00:26 +0300 Subject: [PATCH 05/10] Add tests --- .../EplanDevice.Test/DeviceManager.Test.cs | 18 ++--- .../Base.Test/BaseParameter.Test.cs | 70 +++++++++++++++---- .../TechObject.Test/DevModifyOptions.Test.cs | 34 +++++++++ 3 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 EasyEplanner.Tests/TechObject.Test/DevModifyOptions.Test.cs diff --git a/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs b/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs index 96a1827b..bb50a6ac 100644 --- a/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs +++ b/EasyEplanner.Tests/EplanDevice.Test/DeviceManager.Test.cs @@ -238,19 +238,19 @@ public void GetModifiedDevice( bool isCap) { var manager = DeviceManager.GetInstance(); - var optionsMock = new Mock(); - optionsMock.Setup(o => o.IsUnit).Returns(true); - optionsMock.Setup(o => o.NameModified).Returns(oldObjName != newObjName); - optionsMock.Setup(o => o.NumberModified).Returns(oldTechNumber != newTechNumber); - optionsMock.Setup(o => o.OldTechObjectName).Returns(oldObjName); - optionsMock.Setup(o => o.OldTechObjectNumber).Returns(oldTechNumber); - optionsMock.Setup(o => o.NewTechObjectName).Returns(newObjName); - optionsMock.Setup(o => o.NewTechObjectNumber).Returns(newTechNumber); + var options = Mock.Of(o => + o.IsUnit == true && + o.NameModified == (oldObjName != newObjName) && + o.NumberModified == (oldTechNumber != newTechNumber) && + o.OldTechObjectName == oldObjName && + o.OldTechObjectNumber == oldTechNumber && + o.NewTechObjectName == newObjName && + o.NewTechObjectNumber == newTechNumber); var modified = manager.GetModifiedDevice( manager.GetDeviceByEplanName(modify), - optionsMock.Object); + options); Assert.Multiple(() => { diff --git a/EasyEplanner.Tests/TechObject.Test/Base.Test/BaseParameter.Test.cs b/EasyEplanner.Tests/TechObject.Test/Base.Test/BaseParameter.Test.cs index 41611984..131d42b3 100644 --- a/EasyEplanner.Tests/TechObject.Test/Base.Test/BaseParameter.Test.cs +++ b/EasyEplanner.Tests/TechObject.Test/Base.Test/BaseParameter.Test.cs @@ -439,17 +439,41 @@ public void SaveToPrgLua_CheckActiveBoolParameter(string value, string prefix, s Assert.AreEqual(expected, res); } + [TestCase("NORM1DEV2", "NORM", 2, "NORM2DEV2")] + [TestCase("NORM1DEV2", "OTHER", 1, "OTHER1DEV2")] + public void ModifyDevNames( + string source, + string newName, int newNumber, + string expected) + { + var parameter = new ActiveParameter("LuaName", "Name"); + parameter.SetNewValue(source); + + var options = Mock.Of(o => + o.NewTechObjectName == newName && + o.NewTechObjectNumber == newNumber); + + parameter.ModifyDevNames(options); + + Assert.AreEqual(expected, parameter.Value); + } + private EplanDevice.IDeviceManager GetMoqForSetValuesAndDisplayTextTest() { string stubDev1Name = "STUB1DEV1"; string stubDev2Name = "STUB1DEV2"; - string normDev1Name = "NORM1DEV1"; - string normDev2Name = "NORM1DEV2"; + string norm_1_dev_1_name = "NORM1DEV1"; + string norm_1_dev_2_name = "NORM1DEV2"; + string norm_2_dev_2_name = "NORM2DEV2"; + string other_1_dev_2_name = "OTHER1DEV2"; + - int normDev1Index = 1; + int norm_1_dev_1_index = 1; int stubDev1Index = 2; - int normDev2Index = 3; + int norm_1_dev_2_index = 3; int stubDev2Index = 4; + int norm_2_dev_2_index = 5; + int other_1_dev_2_index = 6; var stubDevice1 = Mock.Of( dev => dev.Name == stubDev1Name && @@ -458,29 +482,45 @@ private EplanDevice.IDeviceManager GetMoqForSetValuesAndDisplayTextTest() dev => dev.Name == stubDev2Name && dev.Description == StaticHelper.CommonConst.Cap); - var okDevice1 = Mock.Of( - dev => dev.Name == normDev1Name && + var norm_1_dev_1 = Mock.Of( + dev => dev.Name == norm_1_dev_1_name && dev.Description == "Description 1"); - var okDevice2 = Mock.Of( - dev => dev.Name == normDev2Name && + var norm_1_dev_2 = Mock.Of( + dev => dev.Name == norm_1_dev_2_name && dev.Description == "Description 2"); + var norm_2_dev_2 = Mock.Of( + dev => dev.Name == norm_2_dev_2_name && + dev.Description == "Description"); + + var other_1_dev_2 = Mock.Of( + dev => dev.Name == other_1_dev_2_name && + dev.Description == "Description"); + var deviceManagerMock = Mock.Of( d => d.GetDeviceByEplanName(stubDev1Name) == stubDevice1 && d.GetDeviceByEplanName(It.IsAny()) == stubDevice1 && d.GetDeviceByEplanName(stubDev2Name) == stubDevice2 && - d.GetDeviceByEplanName(normDev1Name) == okDevice1 && - d.GetDeviceByEplanName(normDev2Name) == okDevice2 && + d.GetDeviceByEplanName(norm_1_dev_1_name) == norm_1_dev_1 && + d.GetDeviceByEplanName(norm_1_dev_2_name) == norm_1_dev_2 && + d.GetDeviceByEplanName(norm_2_dev_2_name) == norm_2_dev_2 && + d.GetDeviceByEplanName(other_1_dev_2_name) == other_1_dev_2 && d.GetDeviceByIndex(It.IsAny()) == stubDevice1 && - d.GetDeviceByIndex(normDev1Index) == okDevice1 && - d.GetDeviceByIndex(normDev2Index) == okDevice2 && + d.GetDeviceByIndex(norm_1_dev_1_index) == norm_1_dev_1 && + d.GetDeviceByIndex(norm_1_dev_2_index) == norm_1_dev_2 && d.GetDeviceByIndex(stubDev1Index) == stubDevice1 && d.GetDeviceByIndex(stubDev2Index) == stubDevice2 && + d.GetDeviceByIndex(norm_2_dev_2_index) == norm_2_dev_2 && + d.GetDeviceByIndex(other_1_dev_2_index) == other_1_dev_2 && d.GetDeviceIndex(It.IsAny()) == -1 && - d.GetDeviceIndex(normDev1Name) == normDev1Index && - d.GetDeviceIndex(normDev2Name) == normDev2Index && + d.GetDeviceIndex(norm_1_dev_1_name) == norm_1_dev_1_index && + d.GetDeviceIndex(norm_1_dev_2_name) == norm_1_dev_2_index && d.GetDeviceIndex(stubDev1Name) == stubDev1Index && - d.GetDeviceIndex(stubDev2Name) == stubDev2Index); + d.GetDeviceIndex(stubDev2Name) == stubDev2Index && + d.GetDeviceIndex(norm_2_dev_2_name) == norm_2_dev_2_index && + d.GetDeviceIndex(other_1_dev_2_name) == other_1_dev_2_index && + d.GetModifiedDevice(norm_1_dev_2, It.Is(o => o.NewTechObjectNumber == 2)) == norm_2_dev_2 && + d.GetModifiedDevice(norm_1_dev_2, It.Is(o => o.NewTechObjectName == "OTHER")) == other_1_dev_2); return deviceManagerMock; } diff --git a/EasyEplanner.Tests/TechObject.Test/DevModifyOptions.Test.cs b/EasyEplanner.Tests/TechObject.Test/DevModifyOptions.Test.cs new file mode 100644 index 00000000..432a3a11 --- /dev/null +++ b/EasyEplanner.Tests/TechObject.Test/DevModifyOptions.Test.cs @@ -0,0 +1,34 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TechObject; + +namespace TechObjectTests +{ + public class DevModifyOptionsTest + { + [Test] + public void Constructor() + { + + var techObject = new TechObject.TechObject("", getN => 2, 2, 2, "OBJ", -1, "", "", + new BaseTechObject() { S88Level = (int)BaseTechObjectManager.ObjectType.Unit }); + var options = new DevModifyOptions(techObject, "OBJ", 1); + + Assert.Multiple(() => + { + Assert.IsTrue(options.IsUnit); + Assert.IsTrue(options.NumberModified); + Assert.IsFalse(options.NameModified); + Assert.AreEqual("OBJ", options.OldTechObjectName); + Assert.AreEqual("OBJ", options.NewTechObjectName); + Assert.AreEqual(1, options.OldTechObjectNumber); + Assert.AreEqual(2, options.NewTechObjectNumber); + }); + } + + } +} From 1e9fa325b49b730d6b1528d592b06a54be9d8cd7 Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Fri, 2 Aug 2024 14:16:51 +0300 Subject: [PATCH 06/10] Fix smells --- src/Device/DeviceManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Device/DeviceManager.cs b/src/Device/DeviceManager.cs index ae9bf967..8e67ffee 100644 --- a/src/Device/DeviceManager.cs +++ b/src/Device/DeviceManager.cs @@ -1137,7 +1137,8 @@ private bool IsPIDControl(string type) private IDevice ModifyMixproof(IDevice device, IDevModifyOptions options) { - var mixproofRegex = new Regex($@"(.+V\d*)(?:{options.OldTechObjectNumber})"); + var mixproofRegex = new Regex($@"(.+V\d*)(?:{options.OldTechObjectNumber})", + RegexOptions.Singleline, TimeSpan.FromMilliseconds(100)); if (options.NumberModified && options.IsUnit && From fb017c6459f87a15ab097af6c8d8247754bf9210 Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Fri, 2 Aug 2024 14:47:27 +0300 Subject: [PATCH 07/10] Fix smells --- src/Device/DeviceManager.cs | 4 ++-- src/TechObject/DevModifyOptions.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Device/DeviceManager.cs b/src/Device/DeviceManager.cs index 8e67ffee..ea78278b 100644 --- a/src/Device/DeviceManager.cs +++ b/src/Device/DeviceManager.cs @@ -80,14 +80,14 @@ public interface IDeviceManager /// Получить модифицированное устройство ///
/// Исходное устройство для модификации - /// Опции модификации + /// Опции модификации /// /// IDevice - модифицированное устройство
/// IDevice EQ device - исходное устройство без модификации
/// .DEscription == CAP - неопределенное устройство (в дальнейшем может быть как и удалено из привязки, так и заменено на исходное)
/// null - удаление устройства из привязки
///
- IDevice GetModifiedDevice(IDevice device, IDevModifyOptions modifyOptions); + IDevice GetModifiedDevice(IDevice device, IDevModifyOptions options); } /// diff --git a/src/TechObject/DevModifyOptions.cs b/src/TechObject/DevModifyOptions.cs index 6a798112..f0917abf 100644 --- a/src/TechObject/DevModifyOptions.cs +++ b/src/TechObject/DevModifyOptions.cs @@ -57,9 +57,9 @@ public interface IDevModifyOptions /// public class DevModifyOptions : IDevModifyOptions { - private TechObject techObject; - private string oldTechObjectName; - private int oldTechObjectNumber; + private readonly TechObject techObject; + private readonly string oldTechObjectName; + private readonly int oldTechObjectNumber; /// Модифицируемый тех.объект /// Старое ОУ теъ.объекта From 7020be81a180f3071d5e37dc6b8738847d582146 Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Fri, 2 Aug 2024 16:21:26 +0300 Subject: [PATCH 08/10] Edit manual --- docs/user_manual/ReadMe.md | 41 ++++++++++++++++++++++++++++++++++++- src/Device/DeviceManager.cs | 4 ++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/docs/user_manual/ReadMe.md b/docs/user_manual/ReadMe.md index 1473829b..e6aee60a 100644 --- a/docs/user_manual/ReadMe.md +++ b/docs/user_manual/ReadMe.md @@ -82,6 +82,7 @@ + [Добавление устройств в операции в табличном режиме](#718-Добавление-устройств-в-операции-в-табличном-режиме) + [Сохранение результатов редактирования](#719-Сохранение-результатов-редактирования) + [Использование параметров в объекте](#7110-Использование-параметров-в-объекте) + + [Модификация названий устройств](#7111-модификация-названий-устройств) + [Описание действий](#72-Описание-действий) + [Использование функциональности базового объекта и базовой операции](#73-Использование-функциональности-базового-объекта-и-базовой-операции) + [Привязка базовых объектов друг к другу](#731-Привязка-базовых-объектов-друг-к-другу) @@ -1312,10 +1313,15 @@ ProjectTestEnabled=True * Быстрое выделение элементов (выделяются все элементы одного типа относящиеся к одной группе, технологические объекты выделяются также по одному технологическому типу) – Ctrl+2xЛКМ; * При копировании – вставке/замене объекта копируются все поля исходного объекта необходимо учитывать следующие нюансы: * Номер объекта меняется на номер объекта, на место которого вставляем объект - * Копируется полный список операций и происходит копирование устройств, которые используются в операции. При этом происходит корректная замена номера объекта на новый. Это происходит в случае совпадения у двух объектов поля ОУ. Так при копировании операций из объекта __Танк 1__ с устройством __TANK1V1__ и заменой в объекте __Танк 3__ устройство изменит свое имя на __TANK3V1__. + * Копируется полный список операций и происходит копирование устройств, которые используются в операции. При этом происходит корректная замена номера объекта на новый (Подробнее описано [здесь](#7111-модификация-названий-устройств)). Это происходит в случае совпадения у двух объектов поля ОУ. Так при копировании операций из объекта __Танк 1__ с устройством __TANK1V1__ и заменой в объекте __Танк 3__ устройство изменит свое имя на __TANK3V1__. * При копировании операций происходит копирование ограничений, описанных в операции. Для ограничений, относящихся к данному объекту (_«Ограничения внутри объекта», «Ограничения на последующие операции»_), происходит замена старого номера объекта на новый. * Можно копировать не только отдельные строки параметров, операций, а также целые группы параметров, ограничений, операций. +##### Модификация названий устройств ##### + + + + #### 7.1.1 Неопознанные объекты при загрузке описания проекта ####

Если базовый объект будет не распознан системой, добавляемый при загрузке объект будет добавлен в группу "Неопознанные объекты". Пример на рисунке ниже.

@@ -1455,6 +1461,39 @@ ProjectTestEnabled=True

Рисунок - Пример отображения параметров в операции

+#### 7.1.11 Модификация названий устройств #### + +

Модификация названий привязанных устройств выполняется при изменении названия или номера технологического объекта, которое происходит в следствии редактирования полей, вставке или замене объекта. Так же модификация проводится при открытии и сохранении проекта.

+ +В модификации привязаных устройств учавствуют следующие поля в технологическом объекта: + - Все поля дейтсвий; + - Параметры действий(если к ним привязано устройство); + - Элементы поля `Доп.свойства`(в операциях); + - Элементы поля `Оборудование`. + +##### Правила модификации устройств ##### + +Устройства в поле оборудования всегда соответсвуют технологическому объекту, поэтому там правило простое: подставляется устройство с соответствующим объектом или удаляется; + +Для остальных полей модификация устройств проводится по следующим правилам: + - Если у привязанного устройства объект совпадает с изменяемым тех.объектом, то устройство модифицируется в соответсвии с изменением имени/номера объекта (или остается прежним в случае отсутсвия такого устройства): + * (имя: "OBJ" => "OTHER") : `[OBJ]1V1` => `[OTHER]1V1`; [*][modify] + * (номер: 1 => 2) : `OBJ[1]V1` => `OBJ[2]V1`; [*][modify] + - В случае если совпадает название объекта, но номер **НЕ** совпадает и при этом он совпадает с новым номером объекта, то он изменяется на противоположный: + * (номер: 1 => 2) : `OBJ[2]V1` => `OBJ[1]V2`; [*][modify] + - Если устройства взяты из типового объекта, то в случае их отсутствия они удаляются; + - Модификация клапанов **MIXPROOF**-типов осуществляется в следующих условиях: + * Модифицируемый объкта - **Аппарат**; + * Имя устойства объекта не совпадат с ОУ тех.объекта; + * Устройство имеет тип **MIXPROOF** или похожий; + + При этом модифицируется не номер объекта, а номер устройства (точнее, его часть свопадающая с номером тех.объекта), если такого устройства нет, оно удаляется из привязки: + * (номер: 1 => 2) : `NO_UNIT1V[1]` => `NO_UNIT1V[2]` [*][modify] + * (номер: 13 => 14) : `NO_UNIT1V2[13]` => `NO_UNIT1V2[14]` [*][modify] + +[modify]: ## "В круглых скобках указывается изменение объекта, далее черех двоеточие результат модификации устройства, где в квадратных скобках указано, что именно изменяется." + + ### 7.2 Описание действий #### Список реализованных действий: diff --git a/src/Device/DeviceManager.cs b/src/Device/DeviceManager.cs index ea78278b..f8617d15 100644 --- a/src/Device/DeviceManager.cs +++ b/src/Device/DeviceManager.cs @@ -1159,8 +1159,8 @@ private IDevice ModifyMixproof(IDevice device, IDevModifyOptions options) var match = mixproofRegex.Match(device.Name); if (match.Success) { - var mixproofP = match.Groups[1].Value; - return GetDeviceByEplanName($"{mixproofP}{options.NewTechObjectNumber}"); + var mixproofPart = match.Groups[1].Value; + return GetDeviceByEplanName($"{mixproofPart}{options.NewTechObjectNumber}"); } else return device; } From 42f189806dd4b2c08e745419823be69c5691232b Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Mon, 5 Aug 2024 09:56:08 +0300 Subject: [PATCH 09/10] [manual] add subtypes --- docs/user_manual/ReadMe.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/user_manual/ReadMe.md b/docs/user_manual/ReadMe.md index e6aee60a..736b9d08 100644 --- a/docs/user_manual/ReadMe.md +++ b/docs/user_manual/ReadMe.md @@ -1482,10 +1482,20 @@ ProjectTestEnabled=True - В случае если совпадает название объекта, но номер **НЕ** совпадает и при этом он совпадает с новым номером объекта, то он изменяется на противоположный: * (номер: 1 => 2) : `OBJ[2]V1` => `OBJ[1]V2`; [*][modify] - Если устройства взяты из типового объекта, то в случае их отсутствия они удаляются; - - Модификация клапанов **MIXPROOF**-типов осуществляется в следующих условиях: + - Модификация клапанов **MIXPROOF** и других подтипов осуществляется в следующих условиях: * Модифицируемый объкта - **Аппарат**; * Имя устойства объекта не совпадат с ОУ тех.объекта; - * Устройство имеет тип **MIXPROOF** или похожий; + * Устройство имеет тип **MIXPROOF** или схожий, а именно: + + `V_DO1_DI2` + + `V_DO2_DI2` + + `V_DO2_DI2_BISTABLE` + + `V_MIXPROOF` + + `V_BOTTOM_MIXPROOF` + + `V_IOLINK_MIXPROOF` + + `V_AS_MIXPROOF` + + `V_AS_DO1_DI2` + + `V_IOLINK_DO1_DI2` + + `V_IOL_TERMINAL_MIXPROOF_DO3` При этом модифицируется не номер объекта, а номер устройства (точнее, его часть свопадающая с номером тех.объекта), если такого устройства нет, оно удаляется из привязки: * (номер: 1 => 2) : `NO_UNIT1V[1]` => `NO_UNIT1V[2]` [*][modify] From af4ea2b9d73374e027755c09e05a5b9be93b5a12 Mon Sep 17 00:00:00 2001 From: KirillGutyrchik Date: Mon, 5 Aug 2024 09:59:21 +0300 Subject: [PATCH 10/10] [manual] edit style --- docs/user_manual/ReadMe.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/user_manual/ReadMe.md b/docs/user_manual/ReadMe.md index 736b9d08..2feb33c1 100644 --- a/docs/user_manual/ReadMe.md +++ b/docs/user_manual/ReadMe.md @@ -1486,16 +1486,16 @@ ProjectTestEnabled=True * Модифицируемый объкта - **Аппарат**; * Имя устойства объекта не совпадат с ОУ тех.объекта; * Устройство имеет тип **MIXPROOF** или схожий, а именно: - + `V_DO1_DI2` - + `V_DO2_DI2` - + `V_DO2_DI2_BISTABLE` - + `V_MIXPROOF` - + `V_BOTTOM_MIXPROOF` - + `V_IOLINK_MIXPROOF` - + `V_AS_MIXPROOF` - + `V_AS_DO1_DI2` - + `V_IOLINK_DO1_DI2` - + `V_IOL_TERMINAL_MIXPROOF_DO3` + + `V_DO1_DI2` + + `V_DO2_DI2` + + `V_DO2_DI2_BISTABLE` + + `V_MIXPROOF` + + `V_BOTTOM_MIXPROOF` + + `V_IOLINK_MIXPROOF` + + `V_AS_MIXPROOF` + + `V_AS_DO1_DI2` + + `V_IOLINK_DO1_DI2` + + `V_IOL_TERMINAL_MIXPROOF_DO3` При этом модифицируется не номер объекта, а номер устройства (точнее, его часть свопадающая с номером тех.объекта), если такого устройства нет, оно удаляется из привязки: * (номер: 1 => 2) : `NO_UNIT1V[1]` => `NO_UNIT1V[2]` [*][modify]