mattercontrol/SlicerConfiguration/SlicerMapping/EngineMappingCura.cs

300 lines
9.2 KiB
C#
Raw Normal View History

/*
Copyright (c) 2014, Lars Brubaker
All rights reserved.
Redistribution and use in source and binary forms, with or without
2015-04-08 15:20:10 -07:00
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
2015-04-08 15:20:10 -07:00
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
2015-04-08 15:20:10 -07:00
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
2015-04-08 15:20:10 -07:00
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.VectorMath;
2016-03-07 14:34:56 -08:00
using System.Collections.Generic;
using System.Linq;
2015-04-08 15:20:10 -07:00
using System.Text;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
2016-03-07 14:34:56 -08:00
public class EngineMappingCura : SliceEngineMapping
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
public static readonly EngineMappingCura Instance = new EngineMappingCura();
2015-04-08 15:20:10 -07:00
2016-03-07 14:34:56 -08:00
private HashSet<string> curaSettingNames;
2015-04-08 15:20:10 -07:00
2016-03-07 14:34:56 -08:00
private MappedSetting[] curaSettings;
2015-04-08 15:20:10 -07:00
2016-03-07 14:34:56 -08:00
// Singleton use only - prevent external construction
private EngineMappingCura() : base("Cura")
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
curaSettings = new MappedSetting[]
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
new ScaledSingleNumber("layer_height", "layerThickness", 1000),
new AsPercentOfReferenceOrDirect("first_layer_height", "initialLayerThickness", "layer_height", 1000),
new ScaledSingleNumber("filament_diameter", "filamentDiameter", 1000),
//filamentFlow
//layer0extrusionWidth
new ScaledSingleNumber("nozzle_diameter", "extrusionWidth", 1000),
new AsCountOrDistance("perimeters", "insetCount", "nozzle_diameter"),
new AsCountOrDistance("bottom_solid_layers", "downSkinCount", "layer_height"),
new AsCountOrDistance("top_solid_layers", "upSkinCount", "layer_height"),
new ScaledSingleNumber("skirt_distance", "skirtDistance", 1000),
new MappedSetting("skirts", "skirtLineCount"),
new SkirtLengthMapping("min_skirt_length", "skirtMinLength"),
2016-03-07 14:34:56 -08:00
new MappedSetting("infill_speed", "printSpeed"),
new MappedSetting("infill_speed", "infillSpeed"),
new MappedSetting("travel_speed", "moveSpeed"),
new AsPercentOfReferenceOrDirect("first_layer_speed", "initialLayerSpeed", "infill_speed"),
2016-03-07 14:34:56 -08:00
new MappedSetting("perimeter_speed", "insetXSpeed"),
new AsPercentOfReferenceOrDirect("external_perimeter_speed", "inset0Speed", "perimeter_speed"),
2016-03-07 14:34:56 -08:00
new ScaledSingleNumber("bottom_clip_amount", "objectSink", 1000),
2014-04-22 09:36:13 -07:00
2016-03-07 14:34:56 -08:00
new MappedSetting("max_fan_speed", "fanSpeedMin"),
new MappedSetting("min_fan_speed", "fanSpeedMax"),
2016-03-07 14:34:56 -08:00
new FanTranslator("disable_fan_first_layers", "fanFullOnLayerNr"),
new MappedSetting("cool_extruder_lift", "coolHeadLift"),
2016-03-07 14:34:56 -08:00
new ScaledSingleNumber("retract_length", "retractionAmount", 1000),
new MapFirstValue("retract_speed", "retractionSpeed"),
new ScaledSingleNumber("retract_before_travel", "retractionMinimalDistance", 1000),
new ScaledSingleNumber("min_extrusion_before_retract", "minimalExtrusionBeforeRetraction", 1000),
2016-03-07 14:34:56 -08:00
new ScaledSingleNumber("retract_lift", "retractionZHop", 1000),
2016-03-07 14:34:56 -08:00
new MappedSetting("spiral_vase", "spiralizeMode"),
new PrintCenterX("print_center", "posx"),
new PrintCenterY("print_center", "posy"),
2016-03-07 14:34:56 -08:00
// needs testing, not working
new ScaledSingleNumber("support_material_spacing", "supportLineDistance", 1000),
new SupportMatterial("support_material", "supportAngle"),
new MappedSetting("support_material_create_internal_support", "supportEverywhere"),
new ScaledSingleNumber("support_material_xy_distance", "supportXYDistance", 1000),
new ScaledSingleNumber("support_material_z_distance", "supportZDistance", 1000),
2016-03-07 14:34:56 -08:00
new SupportTypeMapping("support_type", "supportType"),
2016-03-07 14:34:56 -08:00
new MappedSetting("slowdown_below_layer_time", "minimalLayerTime"),
2016-03-07 14:34:56 -08:00
new InfillTranslator("fill_density", "sparseInfillLineDistance"),
2016-03-07 14:34:56 -08:00
new MapStartGCode("start_gcode", "startCode", true),
new MapEndGCode("end_gcode", "endCode"),
};
2016-03-07 14:34:56 -08:00
curaSettingNames = new HashSet<string>(curaSettings.Select(m => m.CanonicalSettingsName));
}
2016-03-07 14:34:56 -08:00
public override bool HasSetting(string canonicalSettingsName)
{
return curaSettingNames.Contains(canonicalSettingsName)
|| base.applicationLevelSettings.Contains(canonicalSettingsName);
}
2015-04-08 15:20:10 -07:00
public static string GetCuraCommandLineSettings()
{
StringBuilder settings = new StringBuilder();
2016-03-07 14:34:56 -08:00
foreach (MappedSetting mapItem in Instance.curaSettings)
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
if (!string.IsNullOrEmpty(mapItem.Value))
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
settings.AppendFormat("-s {0}=\"{1}\" ", mapItem.ExportedName, mapItem.Value);
2015-04-08 15:20:10 -07:00
}
}
return settings.ToString();
}
2016-03-07 14:34:56 -08:00
public class FanTranslator : MappedSetting
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
public FanTranslator(string canonicalSettingsName, string exportedName)
: base(canonicalSettingsName, exportedName)
{
}
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
2016-03-07 14:34:56 -08:00
int numLayersFanIsDisabledOn = int.Parse(base.Value);
2015-04-08 15:20:10 -07:00
int layerToEnableFanOn = numLayersFanIsDisabledOn + 1;
return layerToEnableFanOn.ToString();
}
}
2016-03-07 14:34:56 -08:00
2015-04-08 15:20:10 -07:00
}
2016-03-07 14:34:56 -08:00
public class SupportTypeMapping : MappedSetting
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
public SupportTypeMapping(string canonicalSettingsName, string exportedName)
: base(canonicalSettingsName, exportedName)
{
}
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
2016-03-07 14:34:56 -08:00
switch (base.Value)
2015-04-08 15:20:10 -07:00
{
case "LINES":
return "1"; // the lines setting from curaengine
default:
return "0"; // the grid setting from curaengine
}
}
}
2016-03-07 14:34:56 -08:00
}
2015-04-08 15:20:10 -07:00
2016-03-07 14:34:56 -08:00
public class SupportMatterial : MappedSetting
{
public SupportMatterial(string canonicalSettingsName, string exportedName)
: base(canonicalSettingsName, exportedName)
2015-04-08 15:20:10 -07:00
{
}
2016-03-07 14:34:56 -08:00
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
2016-03-07 14:34:56 -08:00
string supportMaterial = base.Value;
2015-04-08 15:20:10 -07:00
if (supportMaterial == "0")
{
return "-1";
}
2016-03-07 14:34:56 -08:00
return (90 - ParseDoubleFromRawValue("support_material_threshold")).ToString();
2015-04-08 15:20:10 -07:00
}
}
}
public class InfillTranslator : ScaledSingleNumber
{
2016-03-07 14:34:56 -08:00
public InfillTranslator(string canonicalSettingsName, string exportedName) : base(canonicalSettingsName, exportedName)
{
}
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
2016-03-07 14:34:56 -08:00
double infillRatio0To1 = ParseDouble(base.Value);
2015-04-08 15:20:10 -07:00
// 400 = solid (extruder width)
2016-03-07 14:34:56 -08:00
double nozzle_diameter = ParseDoubleFromRawValue("nozzle_diameter");
2015-04-08 15:20:10 -07:00
double linespacing = 1000;
if (infillRatio0To1 > .01)
{
linespacing = nozzle_diameter / infillRatio0To1;
}
return ((int)(linespacing * 1000)).ToString();
}
}
}
2016-03-07 14:34:56 -08:00
public class PrintCenterX : MappedSetting
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
public PrintCenterX(string canonicalSettingsName, string exportedName)
: base(canonicalSettingsName, exportedName)
{
}
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
Vector2 PrinteCenter = ActiveSliceSettings.Instance.PrintCenter;
return (PrinteCenter.x * 1000).ToString();
}
}
2016-03-07 14:34:56 -08:00
}
2015-04-08 15:20:10 -07:00
2016-03-07 14:34:56 -08:00
public class PrintCenterY : MappedSetting
{
public PrintCenterY(string canonicalSettingsName, string exportedName)
: base(canonicalSettingsName, exportedName)
2015-04-08 15:20:10 -07:00
{
}
2016-03-07 14:34:56 -08:00
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
Vector2 PrinteCenter = ActiveSliceSettings.Instance.PrintCenter;
return (PrinteCenter.y * 1000).ToString();
}
}
}
public class MapEndGCode : InjectGCodeCommands
{
2016-03-07 14:34:56 -08:00
public MapEndGCode(string canonicalSettingsName, string exportedName)
: base(canonicalSettingsName, exportedName)
{
}
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
StringBuilder curaEndGCode = new StringBuilder();
2016-03-07 14:34:56 -08:00
curaEndGCode.Append(GCodeProcessing.ReplaceMacroValues(base.Value));
2015-04-08 15:20:10 -07:00
curaEndGCode.Append("\n; filament used = filament_used_replace_mm (filament_used_replace_cm3)");
return curaEndGCode.ToString();
}
}
}
2016-03-07 14:34:56 -08:00
public class SkirtLengthMapping : MappedSetting
2015-04-08 15:20:10 -07:00
{
2016-03-07 14:34:56 -08:00
public SkirtLengthMapping(string canonicalSettingsName, string exportedName)
: base(canonicalSettingsName, exportedName)
2015-04-08 15:20:10 -07:00
{
}
2016-03-07 14:34:56 -08:00
public override string Value
2015-04-08 15:20:10 -07:00
{
get
{
2016-03-07 14:34:56 -08:00
double lengthToExtrudeMm = ParseDouble(base.Value);
2015-04-08 15:20:10 -07:00
// we need to convert mm of filament to mm of extrusion path
double amountOfFilamentCubicMms = ActiveSliceSettings.Instance.FilamentDiameter * MathHelper.Tau * lengthToExtrudeMm;
double extrusionSquareSize = ActiveSliceSettings.Instance.FirstLayerHeight * ActiveSliceSettings.Instance.NozzleDiameter;
double lineLength = amountOfFilamentCubicMms / extrusionSquareSize;
return (lineLength * 1000).ToString();
}
}
}
}
}