Skip to content

Commit 62825aa

Browse files
authored
Fix LT-21904: Allow duplicating a phonological rule (#342)
* Fix LT-21904: Allow duplicating a phonological rule * Do a deep copy of PhRegularRule and PhMetathesisRule
1 parent 7481ccc commit 62825aa

File tree

1 file changed

+66
-12
lines changed

1 file changed

+66
-12
lines changed

src/SIL.LCModel/DomainImpl/OverridesLing_Lex.cs

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
// This file holds the overrides of the generated classes for the Ling module.
77
// </remarks>
88

9-
using System;
10-
using System.Collections.Generic;
11-
using System.Collections.Specialized;
12-
using System.Diagnostics;
13-
using System.Drawing;
14-
using System.Globalization;
15-
using System.Linq;
16-
using System.Text;
17-
using System.Text.RegularExpressions;
18-
using System.Xml;
199
using SIL.LCModel.Application;
2010
using SIL.LCModel.Core.Cellar;
2111
using SIL.LCModel.Core.KernelInterfaces;
@@ -27,6 +17,16 @@
2717
using SIL.LCModel.Infrastructure.Impl;
2818
using SIL.LCModel.Utils;
2919
using SIL.ObjectModel;
20+
using System;
21+
using System.Collections.Generic;
22+
using System.Collections.Specialized;
23+
using System.Diagnostics;
24+
using System.Drawing;
25+
using System.Globalization;
26+
using System.Linq;
27+
using System.Text;
28+
using System.Text.RegularExpressions;
29+
using System.Xml;
3030

3131
namespace SIL.LCModel.DomainImpl
3232
{
@@ -7528,7 +7528,7 @@ public int OrderNumber
75287528
}
75297529
}
75307530

7531-
internal partial class PhRegularRule
7531+
internal partial class PhRegularRule : ICloneableCmObject
75327532
{
75337533
/// <summary>
75347534
/// Gets all of the feature constraints in this rule.
@@ -7670,6 +7670,34 @@ protected override void RemoveObjectSideEffectsInternal(RemoveObjectEventArgs e)
76707670
}
76717671
}
76727672
}
7673+
7674+
#region ICloneableCmObject Members
7675+
/// ------------------------------------------------------------------------------------
7676+
/// <summary>
7677+
/// Clones this instance.
7678+
/// </summary>
7679+
/// <param name="clone">Destination object for clone operation</param>
7680+
/// ------------------------------------------------------------------------------------
7681+
public void SetCloneProperties(ICmObject clone)
7682+
{
7683+
IPhRegularRule rule = clone as IPhRegularRule;
7684+
if (rule == null)
7685+
throw new ApplicationException("Failed to copy regular phonological rule: the target is not a regular phonological rule.");
7686+
7687+
rule.Description.CopyAlternatives(Description);
7688+
rule.Direction = Direction;
7689+
rule.Disabled = Disabled;
7690+
rule.Name.CopyAlternatives(Name);
7691+
// FeatureConstraints is synthetic.
7692+
rule.FinalStratumRA = FinalStratumRA;
7693+
rule.InitialStratumRA = InitialStratumRA;
7694+
rule.RightHandSidesOS.Clear(); // Remove default.
7695+
CopyObject<IPhSegRuleRHS>.CloneLcmObjects(RightHandSidesOS, newRhs =>
7696+
rule.RightHandSidesOS.Add(newRhs));
7697+
CopyObject<IPhSimpleContext>.CloneLcmObjects(StrucDescOS, newDesc =>
7698+
rule.StrucDescOS.Add(newDesc));
7699+
}
7700+
#endregion
76737701
}
76747702

76757703
internal partial class PhSegRuleRHS
@@ -7734,7 +7762,7 @@ private void CollectInflectionClassesAndSubclasses(List<ICmObject> result, IEnum
77347762
}
77357763
}
77367764

7737-
internal partial class PhMetathesisRule
7765+
internal partial class PhMetathesisRule : ICloneableCmObject
77387766
{
77397767
/// <summary>
77407768
/// Gets the structural change indices.
@@ -8135,6 +8163,32 @@ protected override void SetDefaultValuesAfterInit()
81358163
base.SetDefaultValuesAfterInit();
81368164
SetStrucChangeIndices(new int[] { -1, -1, -1, -1, -1 }, true);
81378165
}
8166+
8167+
#region ICloneableCmObject Members
8168+
/// ------------------------------------------------------------------------------------
8169+
/// <summary>
8170+
/// Clones this instance.
8171+
/// </summary>
8172+
/// <param name="clone">Destination object for clone operation</param>
8173+
/// ------------------------------------------------------------------------------------
8174+
public void SetCloneProperties(ICmObject clone)
8175+
{
8176+
IPhMetathesisRule rule = clone as IPhMetathesisRule;
8177+
if (rule == null)
8178+
throw new ApplicationException("Failed to copy metathesis phonological rule: the target is not a regular metathesis rule.");
8179+
8180+
rule.Description.CopyAlternatives(Description);
8181+
rule.Direction = Direction;
8182+
rule.Disabled = Disabled;
8183+
rule.Name.CopyAlternatives(Name);
8184+
// FeatureConstraints is synthetic.
8185+
rule.FinalStratumRA = FinalStratumRA;
8186+
rule.InitialStratumRA = InitialStratumRA;
8187+
rule.StrucChange = StrucChange;
8188+
CopyObject<IPhSimpleContext>.CloneLcmObjects(StrucDescOS, newDesc =>
8189+
rule.StrucDescOS.Add(newDesc));
8190+
}
8191+
#endregion
81388192
}
81398193

81408194
internal partial class PhIterationContext

0 commit comments

Comments
 (0)