Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify AdditiveSettings CloneAs method to use MemberwiseClone #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 12 additions & 118 deletions settings/AdditiveSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ public abstract class MachineInfo


public abstract T CloneAs<T>() 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;
}
}


Expand Down Expand Up @@ -93,40 +82,9 @@ public class FFFMachineInfo : MachineInfo

public override T CloneAs<T>()
{
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;
}
}


Expand All @@ -149,11 +107,6 @@ public string ClassTypeName {
public abstract MachineInfo BaseMachine { get; set; }

public abstract T CloneAs<T>() where T : class;
protected virtual void CopyFieldsTo(PlanarAdditiveSettings to)
{
to.Identifier = this.Identifier;
to.LayerHeightMM = this.LayerHeightMM;
}
}


Expand Down Expand Up @@ -320,73 +273,14 @@ public double BridgeFillPathSpacingMM() {

public override T CloneAs<T>()
{
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<FFFMachineInfo>();

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<FFFMachineInfo>();

return clone as T;
}

}
Expand All @@ -404,9 +298,9 @@ public override AssemblerFactoryF AssemblerType() {

public override T CloneAs<T>()
{
GenericRepRapSettings copy = new GenericRepRapSettings();
this.CopyFieldsTo(copy);
return copy as T;
var clone = (GenericRepRapSettings)MemberwiseClone();
clone.Machine = this.machineInfo.CloneAs<FFFMachineInfo>();
return clone as T;
}


Expand Down
9 changes: 5 additions & 4 deletions settings/FlashforgeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public FlashforgeSettings(Flashforge.Models model = Flashforge.Models.CreatorPro
}


public override T CloneAs<T>() {
FlashforgeSettings copy = new FlashforgeSettings(this.ModelEnum);
this.CopyFieldsTo(copy);
return copy as T;
public override T CloneAs<T>()
{
var clone = (FlashforgeSettings)MemberwiseClone();
clone.Machine = this.machineInfo.CloneAs<FFFMachineInfo>();
return clone as T;
}


Expand Down
9 changes: 5 additions & 4 deletions settings/MakerbotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public MakerbotSettings(Makerbot.Models model = Makerbot.Models.Replicator2) {
}


public override T CloneAs<T>() {
MakerbotSettings copy = new MakerbotSettings(this.ModelEnum);
this.CopyFieldsTo(copy);
return copy as T;
public override T CloneAs<T>()
{
var clone = (MakerbotSettings)MemberwiseClone();
clone.Machine = this.machineInfo.CloneAs<FFFMachineInfo>();
return clone as T;
}


Expand Down
9 changes: 5 additions & 4 deletions settings/MonopriceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public MonopriceSettings(Monoprice.Models model) {
configure_unknown();
}

public override T CloneAs<T>() {
MonopriceSettings copy = new MonopriceSettings(this.ModelEnum);
this.CopyFieldsTo(copy);
return copy as T;
public override T CloneAs<T>()
{
var clone = (MonopriceSettings)MemberwiseClone();
clone.Machine = this.machineInfo.CloneAs<FFFMachineInfo>();
return clone as T;
}

public static IEnumerable<SingleMaterialFFFSettings> EnumerateDefaults()
Expand Down
7 changes: 4 additions & 3 deletions settings/PrintrbotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public PrintrbotSettings(Printrbot.Models model) {
}

public override T CloneAs<T>() {
PrintrbotSettings copy = new PrintrbotSettings(this.ModelEnum);
this.CopyFieldsTo(copy);
return copy as T;

var clone = (PrintrbotSettings)MemberwiseClone();
clone.Machine = this.machineInfo.CloneAs<FFFMachineInfo>();
return clone as T;
}


Expand Down
9 changes: 5 additions & 4 deletions settings/PrusaSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public PrusaSettings(Prusa.Models model) {
configure_unknown();
}

public override T CloneAs<T>() {
PrusaSettings copy = new PrusaSettings(this.ModelEnum);
this.CopyFieldsTo(copy);
return copy as T;
public override T CloneAs<T>()
{
var clone = (PrusaSettings)MemberwiseClone();
clone.Machine = this.machineInfo.CloneAs<FFFMachineInfo>();
return clone as T;
}


Expand Down
9 changes: 5 additions & 4 deletions settings/RepRapSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public RepRapSettings(RepRap.Models model) {
configure_unknown();
}

public override T CloneAs<T>() {
RepRapSettings copy = new RepRapSettings(this.ModelEnum);
this.CopyFieldsTo(copy);
return copy as T;
public override T CloneAs<T>()
{
var clone = (RepRapSettings)MemberwiseClone();
clone.Machine = this.machineInfo.CloneAs<FFFMachineInfo>();
return clone as T;
}

public static IEnumerable<SingleMaterialFFFSettings> EnumerateDefaults()
Expand Down