Skip to content

Commit ecd9147

Browse files
authoredJan 27, 2025··
[Techobject] Fix assigned of owner when replacing operation (#1529)
Fixes #1502. ```ChangeLog Исправлена ошибка сохранения номера операции привязанного агрегата в prg.lua при копировании операций между объектами; ```
1 parent 705ba6d commit ecd9147

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed
 

‎EasyEplanner.Tests/TechObject.Test/Base.Test/BaseOperation.Test.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -615,15 +615,17 @@ public void Clone_StateUnderTestSource_ReturnsCopy()
615615
};
616616
operation.AddProperties(objParams, baseTechObj);
617617

618-
BaseOperation cloned = operation.Clone();
618+
var mode = new Mode("", getN => 1, new ModesManager(null));
619+
620+
BaseOperation cloned = operation.Clone(mode);
619621

620622
Assert.Multiple(() =>
621623
{
622624
Assert.AreEqual(operation.DefaultPosition,
623625
cloned.DefaultPosition);
624626
Assert.AreEqual(operation.Name, cloned.Name);
625627
Assert.AreEqual(operation.LuaName, cloned.LuaName);
626-
Assert.IsNull(cloned.Owner);
628+
Assert.AreEqual(mode, cloned.Owner);
627629

628630
foreach (var property in operation.Properties)
629631
{

‎src/TechObject/Base/BaseOperation.cs

+10-21
Original file line numberDiff line numberDiff line change
@@ -503,30 +503,22 @@ property.Owner is BaseTechObject &&
503503
}
504504
}
505505

506-
public BaseOperation Clone(Mode owner)
507-
{
508-
var operation = Clone();
509-
operation.owner = owner;
510-
return operation;
511-
}
512-
513506
/// <summary>
514507
/// Копирование объекта
515508
/// </summary>
516509
/// <returns></returns>
517-
public BaseOperation Clone()
510+
public BaseOperation Clone(Mode owner)
518511
{
519512
var operation = EmptyOperation();
520-
List<BaseParameter> properties = CloneProperties(operation);
521-
Dictionary<string, List<BaseStep>> states = CloneStates(operation);
522513

523514
operation.Name = operationName;
524515
operation.LuaName = luaOperationName;
525-
operation.Properties = properties;
526-
operation.states = states;
527-
operation.owner = Owner;
516+
operation.owner = owner ?? Owner;
528517
operation.DefaultPosition = DefaultPosition;
529518

519+
operation.Properties = CloneProperties(operation);
520+
operation.states = CloneStates(operation);
521+
530522
operation.SetItems();
531523

532524
Properties.ForEach(prop => prop.ValueChanged +=
@@ -535,6 +527,8 @@ public BaseOperation Clone()
535527
return operation;
536528
}
537529

530+
public BaseOperation Clone() => Clone(null);
531+
538532
/// <summary>
539533
/// Копирование доп. свойств базовой операции
540534
/// </summary>
@@ -544,17 +538,12 @@ private List<BaseParameter> CloneProperties(BaseOperation newOwner)
544538
{
545539
var properties = new List<BaseParameter>();
546540

547-
for (int i = 0; i < baseOperationProperties.Count; i++)
541+
foreach (BaseParameter oldProperty in baseOperationProperties)
548542
{
549-
BaseParameter oldProperty = baseOperationProperties[i];
550543
BaseParameter newProperty = oldProperty.Clone();
551-
if (oldProperty.Owner is BaseTechObject)
544+
if (oldProperty.Owner is BaseTechObject obj && obj.IsAttachable)
552545
{
553-
var obj = oldProperty.Owner as BaseTechObject;
554-
if (obj.IsAttachable)
555-
{
556-
newProperty.Owner = oldProperty.Owner;
557-
}
546+
newProperty.Owner = obj.Clone(newOwner.Owner.Owner.Owner);
558547
}
559548
else
560549
{

‎src/TechObject/ObjectsTree/UniversalObject/ModesManager.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,9 @@ private void SwapModes(int index1, int index2)
392392
Editor.Editor.GetInstance().RefreshObject(this);
393393
}
394394

395-
override public ITreeViewItem Replace(object child,
396-
object copyObject)
395+
override public ITreeViewItem Replace(object child, object copyObject)
397396
{
398-
var targetOperation = child as Mode;
399-
var copiedOperation = copyObject as Mode;
400-
401-
if (targetOperation is null || copiedOperation is null)
397+
if (!(child is Mode targetOperation && copyObject is Mode copiedOperation))
402398
return null;
403399

404400
Mode newOperation = copiedOperation.Clone(GetModeN, this, copiedOperation.Name);

0 commit comments

Comments
 (0)
Please sign in to comment.