Skip to content

Commit

Permalink
fix(Duplicate): duplicate with renewing ids
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed Feb 7, 2024
1 parent 6c21c67 commit 66b6efa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,8 @@ protected IEnumerable<IB_ModelObject> SetObjDupParamsTo(IB_ModelObject IB_obj)
num = Math.Max(ghInt.Value, 0);
}

for (int i = 0; i < num; i++)
{
var newobj = IB_obj.Duplicate();
newobj.SetTrackingID();
objs.Add(newobj);
}

objs = IB_obj.Duplicate(num, renewIDs: true);

return objs;

Expand Down
29 changes: 29 additions & 0 deletions src/Ironbug.HVAC/BaseClass/IB_ModelObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,35 @@ public virtual IB_ModelObject Duplicate()
return this.Duplicate(IB_InitSelf);
}

public IB_ModelObject Duplicate(bool renewId)
{
var dup = this.Duplicate();

if (renewId)
{
dup.SetTrackingID();
foreach (var item in dup.Children)
{
item.SetTrackingID();
}

}

return dup;
}

public virtual List<IB_ModelObject> Duplicate(int number, bool renewIDs = true)
{
var dups = new List<IB_ModelObject>();
for (int i = 0; i < number; i++)
{
var newobj = this.Duplicate(renewIDs);
dups.Add(newobj);
}

return dups;
}


protected T Duplicate<T>(Func<T> func) where T : IB_ModelObject
{
Expand Down

0 comments on commit 66b6efa

Please sign in to comment.