diff --git a/OpenNest.Core/Part.cs b/OpenNest.Core/Part.cs
index e0c3b0d..b47793c 100644
--- a/OpenNest.Core/Part.cs
+++ b/OpenNest.Core/Part.cs
@@ -20,6 +20,7 @@ namespace OpenNest
public class Part : IPart, IBoundable
{
private Vector location;
+ private bool ownsProgram;
public readonly Drawing BaseDrawing;
@@ -32,6 +33,7 @@ namespace OpenNest
{
BaseDrawing = baseDrawing;
Program = baseDrawing.Program.Clone() as Program;
+ ownsProgram = true;
this.location = location;
UpdateBounds();
}
@@ -67,6 +69,7 @@ namespace OpenNest
/// Angle of rotation in radians.
public void Rotate(double angle)
{
+ EnsureOwnedProgram();
Program.Rotate(angle);
location = Location.Rotate(angle);
UpdateBounds();
@@ -79,6 +82,7 @@ namespace OpenNest
/// The origin to rotate the part around.
public void Rotate(double angle, Vector origin)
{
+ EnsureOwnedProgram();
Program.Rotate(angle);
location = Location.Rotate(angle, origin);
UpdateBounds();
@@ -222,6 +226,15 @@ namespace OpenNest
return part;
}
+ private void EnsureOwnedProgram()
+ {
+ if (!ownsProgram)
+ {
+ Program = Program.Clone() as Program;
+ ownsProgram = true;
+ }
+ }
+
private Part(Drawing baseDrawing, Program program, Vector location, Box boundingBox)
{
BaseDrawing = baseDrawing;