diff --git a/settings/AdditiveSettings.cs b/settings/AdditiveSettings.cs index b5dedbe..83ec95f 100644 --- a/settings/AdditiveSettings.cs +++ b/settings/AdditiveSettings.cs @@ -27,17 +27,6 @@ public abstract class MachineInfo public abstract T CloneAs() where T : class; - protected virtual void CopyFieldsTo(MachineInfo to) - { - to.ManufacturerName = this.ManufacturerName; - to.ManufacturerUUID = this.ManufacturerUUID; - to.ModelIdentifier = this.ModelIdentifier; - to.ModelUUID = this.ModelUUID; - to.Class = this.Class; - to.BedSizeXMM = this.BedSizeXMM; - to.BedSizeYMM = this.BedSizeYMM; - to.MaxHeightMM = this.MaxHeightMM; - } } @@ -93,40 +82,9 @@ public class FFFMachineInfo : MachineInfo public override T CloneAs() { - FFFMachineInfo fi = new FFFMachineInfo(); - this.CopyFieldsTo(fi); + var fi = MemberwiseClone(); return fi as T; } - protected virtual void CopyFieldsTo(FFFMachineInfo to) - { - base.CopyFieldsTo(to); - - to.NozzleDiamMM = this.NozzleDiamMM; - to.FilamentDiamMM = this.FilamentDiamMM; - to.MinLayerHeightMM = this.MinLayerHeightMM; - to.MaxHeightMM = this.MaxHeightMM; - to.MinExtruderTempC = this.MaxExtruderTempC; - to.HasHeatedBed = this.HasHeatedBed; - to.MinBedTempC = this.MinBedTempC; - to.MaxBedTempC = this.MaxBedTempC; - to.MaxExtrudeSpeedMMM = this.MaxExtrudeSpeedMMM; - to.MaxTravelSpeedMMM = this.MaxTravelSpeedMMM; - to.MaxZTravelSpeedMMM = this.MaxZTravelSpeedMMM; - to.MaxRetractSpeedMMM = this.MaxRetractSpeedMMM; - to.MinPointSpacingMM = this.MinPointSpacingMM; - - to.EnableAutoBedLeveling = this.EnableAutoBedLeveling; - to.HasAutoBedLeveling = this.HasAutoBedLeveling; - - to.ManufacturerName = this.ManufacturerName; - to.ManufacturerUUID = this.ManufacturerUUID; - to.ModelIdentifier = this.ModelIdentifier; - to.ModelUUID = this.ModelUUID; - to.Class = this.Class; - to.BedSizeXMM = this.BedSizeXMM; - to.BedSizeYMM = this.BedSizeYMM; - to.MaxHeightMM = this.MaxHeightMM; - } } @@ -149,11 +107,6 @@ public string ClassTypeName { public abstract MachineInfo BaseMachine { get; set; } public abstract T CloneAs() where T : class; - protected virtual void CopyFieldsTo(PlanarAdditiveSettings to) - { - to.Identifier = this.Identifier; - to.LayerHeightMM = this.LayerHeightMM; - } } @@ -320,73 +273,14 @@ public double BridgeFillPathSpacingMM() { public override T CloneAs() { - SingleMaterialFFFSettings copy = new SingleMaterialFFFSettings(); - this.CopyFieldsTo(copy); - return copy as T; - } - protected virtual void CopyFieldsTo(SingleMaterialFFFSettings to) - { - base.CopyFieldsTo(to); - to.machineInfo = this.machineInfo.CloneAs(); - - to.ExtruderTempC = this.ExtruderTempC; - to.HeatedBedTempC = this.HeatedBedTempC; - to.EnableRetraction = this.EnableRetraction; - to.RetractDistanceMM = this.RetractDistanceMM; - to.MinRetractTravelLength = this.MinRetractTravelLength; - - to.RetractSpeed = this.RetractSpeed; - to.ZTravelSpeed = this.ZTravelSpeed; - to.RapidTravelSpeed = this.RapidTravelSpeed; - to.CarefulExtrudeSpeed = this.CarefulExtrudeSpeed; - to.RapidExtrudeSpeed = this.RapidExtrudeSpeed; - to.MinExtrudeSpeed = this.MinExtrudeSpeed; - to.OuterPerimeterSpeedX = this.OuterPerimeterSpeedX; - to.FanSpeedX = this.FanSpeedX; - - to.Shells = this.Shells; - to.InteriorSolidRegionShells = this.InteriorSolidRegionShells; - to.OuterShellLast = this.OuterShellLast; - to.RoofLayers = this.RoofLayers; - to.FloorLayers = this.FloorLayers; - - to.ShellsFillNozzleDiamStepX = this.ShellsFillNozzleDiamStepX; - to.SolidFillNozzleDiamStepX = this.SolidFillNozzleDiamStepX; - to.SolidFillBorderOverlapX = this.SolidFillBorderOverlapX; - - to.SparseLinearInfillStepX = this.SparseLinearInfillStepX; - to.SparseFillBorderOverlapX = this.SparseFillBorderOverlapX; - - to.StartLayers = this.StartLayers; - to.StartLayerHeightMM = this.StartLayerHeightMM; - - to.GenerateSupport = this.GenerateSupport; - to.SupportOverhangAngleDeg = this.SupportOverhangAngleDeg; - to.SupportSpacingStepX = this.SupportSpacingStepX; - to.SupportVolumeScale = this.SupportVolumeScale; - to.EnableSupportShell = this.EnableSupportShell; - to.SupportAreaOffsetX = this.SupportAreaOffsetX; - to.SupportSolidSpace = this.SupportSolidSpace; - to.SupportRegionJoinTolX = this.SupportRegionJoinTolX; - to.EnableSupportReleaseOpt = this.EnableSupportReleaseOpt; - to.SupportReleaseGap = this.SupportReleaseGap; - to.SupportMinDimension = this.SupportMinDimension; - to.SupportMinZTips = this.SupportMinZTips; - to.SupportPointDiam = this.SupportPointDiam; - to.SupportPointSides = this.SupportPointSides; - - to.EnableBridging = this.EnableBridging; - to.MaxBridgeWidthMM = this.MaxBridgeWidthMM; - to.BridgeFillNozzleDiamStepX = this.BridgeFillNozzleDiamStepX; - to.BridgeVolumeScale = this.BridgeVolumeScale; - to.BridgeExtrudeSpeedX = this.BridgeExtrudeSpeedX; - - - to.MinLayerTime = this.MinLayerTime; - to.ClipSelfOverlaps = this.ClipSelfOverlaps; - to.SelfOverlapToleranceX = this.SelfOverlapToleranceX; - - to.LayerRangeFilter = this.LayerRangeFilter; + var clone = (SingleMaterialFFFSettings) MemberwiseClone(); + + // NOTE: If you add reference type members to the class, + // you need to create copies here, otherwise they will be copied by reference. + // `string` members are okay because they are readonly. + clone.Machine = this.machineInfo.CloneAs(); + + return clone as T; } } @@ -404,9 +298,9 @@ public override AssemblerFactoryF AssemblerType() { public override T CloneAs() { - GenericRepRapSettings copy = new GenericRepRapSettings(); - this.CopyFieldsTo(copy); - return copy as T; + var clone = (GenericRepRapSettings)MemberwiseClone(); + clone.Machine = this.machineInfo.CloneAs(); + return clone as T; } diff --git a/settings/FlashforgeSettings.cs b/settings/FlashforgeSettings.cs index 8afb6e7..622f075 100644 --- a/settings/FlashforgeSettings.cs +++ b/settings/FlashforgeSettings.cs @@ -38,10 +38,11 @@ public FlashforgeSettings(Flashforge.Models model = Flashforge.Models.CreatorPro } - public override T CloneAs() { - FlashforgeSettings copy = new FlashforgeSettings(this.ModelEnum); - this.CopyFieldsTo(copy); - return copy as T; + public override T CloneAs() + { + var clone = (FlashforgeSettings)MemberwiseClone(); + clone.Machine = this.machineInfo.CloneAs(); + return clone as T; } diff --git a/settings/MakerbotSettings.cs b/settings/MakerbotSettings.cs index cb04ea8..69292fe 100644 --- a/settings/MakerbotSettings.cs +++ b/settings/MakerbotSettings.cs @@ -47,10 +47,11 @@ public MakerbotSettings(Makerbot.Models model = Makerbot.Models.Replicator2) { } - public override T CloneAs() { - MakerbotSettings copy = new MakerbotSettings(this.ModelEnum); - this.CopyFieldsTo(copy); - return copy as T; + public override T CloneAs() + { + var clone = (MakerbotSettings)MemberwiseClone(); + clone.Machine = this.machineInfo.CloneAs(); + return clone as T; } diff --git a/settings/MonopriceSettings.cs b/settings/MonopriceSettings.cs index 42ec93a..735c632 100644 --- a/settings/MonopriceSettings.cs +++ b/settings/MonopriceSettings.cs @@ -37,10 +37,11 @@ public MonopriceSettings(Monoprice.Models model) { configure_unknown(); } - public override T CloneAs() { - MonopriceSettings copy = new MonopriceSettings(this.ModelEnum); - this.CopyFieldsTo(copy); - return copy as T; + public override T CloneAs() + { + var clone = (MonopriceSettings)MemberwiseClone(); + clone.Machine = this.machineInfo.CloneAs(); + return clone as T; } public static IEnumerable EnumerateDefaults() diff --git a/settings/PrintrbotSettings.cs b/settings/PrintrbotSettings.cs index f54294e..a5c4a54 100644 --- a/settings/PrintrbotSettings.cs +++ b/settings/PrintrbotSettings.cs @@ -38,9 +38,10 @@ public PrintrbotSettings(Printrbot.Models model) { } public override T CloneAs() { - PrintrbotSettings copy = new PrintrbotSettings(this.ModelEnum); - this.CopyFieldsTo(copy); - return copy as T; + + var clone = (PrintrbotSettings)MemberwiseClone(); + clone.Machine = this.machineInfo.CloneAs(); + return clone as T; } diff --git a/settings/PrusaSettings.cs b/settings/PrusaSettings.cs index e66ae0b..8d72965 100644 --- a/settings/PrusaSettings.cs +++ b/settings/PrusaSettings.cs @@ -37,10 +37,11 @@ public PrusaSettings(Prusa.Models model) { configure_unknown(); } - public override T CloneAs() { - PrusaSettings copy = new PrusaSettings(this.ModelEnum); - this.CopyFieldsTo(copy); - return copy as T; + public override T CloneAs() + { + var clone = (PrusaSettings)MemberwiseClone(); + clone.Machine = this.machineInfo.CloneAs(); + return clone as T; } diff --git a/settings/RepRapSettings.cs b/settings/RepRapSettings.cs index 417d315..56a4893 100644 --- a/settings/RepRapSettings.cs +++ b/settings/RepRapSettings.cs @@ -33,10 +33,11 @@ public RepRapSettings(RepRap.Models model) { configure_unknown(); } - public override T CloneAs() { - RepRapSettings copy = new RepRapSettings(this.ModelEnum); - this.CopyFieldsTo(copy); - return copy as T; + public override T CloneAs() + { + var clone = (RepRapSettings)MemberwiseClone(); + clone.Machine = this.machineInfo.CloneAs(); + return clone as T; } public static IEnumerable EnumerateDefaults()