2014-02-15 18:06:03 -08:00
/ *
2016-04-18 11:31:31 -07:00
Copyright ( c ) 2016 , Lars Brubaker , John Lewin
2014-02-15 18:06:03 -08:00
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 :
2014-02-15 18:06:03 -08:00
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 .
2014-02-15 18:06:03 -08:00
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 .
2014-02-15 18:06:03 -08:00
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 ,
2014-02-15 18:06:03 -08:00
either expressed or implied , of the FreeBSD Project .
* /
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg ;
using MatterHackers.Agg.UI ;
2014-02-04 13:30:42 -08:00
using MatterHackers.Localizations ;
2015-04-08 15:20:10 -07:00
using MatterHackers.MatterControl.ContactForm ;
2016-02-04 09:50:00 -08:00
using MatterHackers.MatterControl.PrinterCommunication ;
2015-04-08 15:20:10 -07:00
using MatterHackers.VectorMath ;
2016-04-18 11:31:31 -07:00
using Newtonsoft.Json ;
2015-04-08 15:20:10 -07:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.IO ;
2015-11-30 16:19:32 -08:00
using System.Linq ;
2015-04-08 15:20:10 -07:00
using System.Text ;
2014-01-29 19:09:30 -08:00
2014-02-15 18:06:03 -08:00
namespace MatterHackers.MatterControl.SlicerConfiguration
2014-01-29 19:09:30 -08:00
{
2016-04-18 11:31:31 -07:00
using ConfigurationPage.PrintLeveling ;
using DataStorage ;
using Agg.PlatformAbstract ;
2016-04-30 18:18:15 -07:00
using Newtonsoft.Json.Linq ;
2016-06-16 10:22:38 -07:00
using MeshVisualizer ;
2016-06-20 12:47:10 -07:00
using System.Collections.ObjectModel ;
2016-06-16 14:35:42 -07:00
public static class SettingsKey
2016-06-16 07:23:42 -07:00
{
2016-06-16 14:35:42 -07:00
public const string bed_shape = nameof ( bed_shape ) ;
public const string bed_size = nameof ( bed_size ) ;
public const string bed_temperature = nameof ( bed_temperature ) ;
2016-06-21 09:38:37 -07:00
public const string build_height = nameof ( build_height ) ;
public const string center_part_on_bed = nameof ( center_part_on_bed ) ;
2016-06-16 14:35:42 -07:00
public const string extruder_count = nameof ( extruder_count ) ;
public const string extruders_share_temperature = nameof ( extruders_share_temperature ) ;
public const string fill_density = nameof ( fill_density ) ;
2016-07-12 18:06:06 -07:00
public const string first_layer_extrusion_width = nameof ( first_layer_extrusion_width ) ;
2016-06-21 09:38:37 -07:00
public const string first_layer_height = nameof ( first_layer_height ) ;
public const string has_heated_bed = nameof ( has_heated_bed ) ;
public const string layer_height = nameof ( layer_height ) ;
public const string min_fan_speed = nameof ( min_fan_speed ) ;
public const string nozzle_diameter = nameof ( nozzle_diameter ) ;
public const string print_center = nameof ( print_center ) ;
public const string printer_name = nameof ( printer_name ) ;
2016-07-06 15:05:06 -07:00
public const string make = nameof ( make ) ;
public const string model = nameof ( model ) ;
2016-06-22 14:09:19 -07:00
public const string publish_bed_image = nameof ( publish_bed_image ) ;
2016-06-21 09:38:37 -07:00
public const string resume_position_before_z_home = nameof ( resume_position_before_z_home ) ;
public const string z_homes_to_max = nameof ( z_homes_to_max ) ;
2016-07-12 17:46:48 -07:00
public const string device_token = nameof ( device_token ) ;
public const string baud_rate = nameof ( baud_rate ) ;
public const string com_port = nameof ( com_port ) ;
public const string auto_connect = nameof ( auto_connect ) ;
public const string default_material_presets = nameof ( default_material_presets ) ;
public const string windows_driver = nameof ( windows_driver ) ;
public const string device_type = nameof ( device_type ) ;
public const string cancel_gcode = nameof ( cancel_gcode ) ;
public const string connect_gcode = nameof ( connect_gcode ) ;
public const string has_fan = nameof ( has_fan ) ;
public const string has_hardware_leveling = nameof ( has_hardware_leveling ) ;
public const string has_power_control = nameof ( has_power_control ) ;
public const string has_sd_card_reader = nameof ( has_sd_card_reader ) ;
public const string created_date = nameof ( created_date ) ;
public const string filament_cost = nameof ( filament_cost ) ;
public const string filament_density = nameof ( filament_density ) ;
public const string filament_diameter = nameof ( filament_diameter ) ;
2016-06-16 07:23:42 -07:00
} ;
2016-04-18 11:31:31 -07:00
public class SettingsProfile
2015-04-08 15:20:10 -07:00
{
private static string configFileExtension = "slice" ;
2016-04-18 11:31:31 -07:00
public RootedObjectEventHandler DoPrintLevelingChanged = new RootedObjectEventHandler ( ) ;
2015-04-08 15:20:10 -07:00
2016-06-15 14:50:12 -07:00
private PrinterSettings layeredProfile ;
2015-04-08 15:20:10 -07:00
2016-06-28 16:51:59 -07:00
public bool PrinterSelected = > layeredProfile . OemLayer ? . Keys . Count > 0 ;
2016-04-18 11:31:31 -07:00
2016-06-15 14:50:12 -07:00
internal SettingsProfile ( PrinterSettings profile )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
layeredProfile = profile ;
2015-04-08 15:20:10 -07:00
}
2016-06-16 13:20:38 -07:00
#region LayeredProfile Proxies
2016-06-11 16:24:30 -07:00
public string ID
{
get
{
return layeredProfile . ID ;
}
set
{
layeredProfile . ID = value ;
}
}
2016-05-16 16:21:42 -07:00
2015-04-08 15:20:10 -07:00
2016-04-18 11:31:31 -07:00
public string ActiveQualityKey
{
get
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
return layeredProfile . ActiveQualityKey ;
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
set
{
layeredProfile . ActiveQualityKey = value ;
}
}
2015-04-08 15:20:10 -07:00
2016-06-16 13:20:38 -07:00
public PrinterSettingsLayer BaseLayer = > layeredProfile . BaseLayer ;
2016-06-27 15:38:45 -07:00
public PrinterSettingsLayer OemLayer = > layeredProfile . OemLayer ;
2016-06-16 13:20:38 -07:00
public PrinterSettingsLayer UserLayer = > layeredProfile . UserLayer ;
2016-06-20 12:47:10 -07:00
public ObservableCollection < PrinterSettingsLayer > MaterialLayers = > layeredProfile . MaterialLayers ;
2016-06-16 13:20:38 -07:00
2016-06-20 12:47:10 -07:00
public ObservableCollection < PrinterSettingsLayer > QualityLayers = > layeredProfile . QualityLayers ;
2016-06-16 13:20:38 -07:00
public List < GCodeMacro > Macros = > layeredProfile . Macros ;
///<summary>
///Returns the first matching value discovered while enumerating the settings layers
///</summary>
public string GetValue ( string sliceSetting , IEnumerable < PrinterSettingsLayer > layerCascade = null )
{
return layeredProfile . GetValue ( sliceSetting , layerCascade ) ;
}
2016-06-17 10:38:22 -07:00
public void SetActiveValue ( string sliceSetting , string sliceValue , PrinterSettingsLayer persistenceLayer = null )
2016-06-16 13:20:38 -07:00
{
2016-06-16 14:35:42 -07:00
layeredProfile . SetValue ( sliceSetting , sliceValue , persistenceLayer ) ;
2016-06-16 13:20:38 -07:00
}
2016-06-17 10:38:22 -07:00
public void ClearValue ( string sliceSetting , PrinterSettingsLayer persistenceLayer = null )
2016-06-16 13:20:38 -07:00
{
layeredProfile . ClearValue ( sliceSetting , persistenceLayer ) ;
}
internal void SaveChanges ( )
{
layeredProfile . Save ( ) ;
}
internal void SetMaterialPreset ( int extruderIndex , string text )
{
layeredProfile . SetMaterialPreset ( extruderIndex , text ) ;
}
internal List < string > MaterialSettingsKeys ( )
{
return layeredProfile . MaterialSettingsKeys ;
}
internal string MaterialPresetKey ( int extruderIndex )
{
return layeredProfile . GetMaterialPresetKey ( extruderIndex ) ;
}
#endregion
2016-04-18 11:31:31 -07:00
internal void RunInTransaction ( Action < SettingsProfile > action )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
// TODO: Implement RunInTransaction
// Suspend writes
action ( this ) ;
// Commit
2015-04-08 15:20:10 -07:00
}
2016-06-16 13:20:38 -07:00
/ * jlewin - delete after confirmation
2016-04-18 11:31:31 -07:00
public class SettingsConverter
{
public static void LoadConfigurationSettingsFromFileAsUnsaved ( string pathAndFileName )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
try
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
if ( File . Exists ( pathAndFileName ) )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
string [ ] lines = System . IO . File . ReadAllLines ( pathAndFileName ) ;
foreach ( string line in lines )
{
//Ignore commented lines
if ( line . Trim ( ) ! = "" & & ! line . StartsWith ( "#" ) )
{
string [ ] settingLine = line . Split ( '=' ) ;
if ( settingLine . Length > 1 )
{
string keyName = settingLine [ 0 ] . Trim ( ) ;
string settingDefaultValue = settingLine [ 1 ] . Trim ( ) ;
//Add the setting to the active layer
//SaveValue(keyName, settingDefaultValue);
throw new NotImplementedException ( "load to dictionary" ) ;
}
}
}
2015-04-08 15:20:10 -07:00
}
}
2016-04-18 11:31:31 -07:00
catch ( Exception e )
{
Debug . Print ( e . Message ) ;
GuiWidget . BreakInDebugger ( ) ;
Debug . WriteLine ( string . Format ( "Error loading configuration: {0}" , e ) ) ;
}
2015-04-08 15:20:10 -07:00
}
2016-06-16 13:20:38 -07:00
} * /
2015-04-08 15:20:10 -07:00
2016-06-11 16:24:30 -07:00
public void ClearUserOverrides ( )
{
var userOverrides = this . UserLayer . Keys . ToArray ( ) ;
// Leave user layer items that have no Organizer definition and thus cannot be changed by the user
var keysToRetain = new HashSet < string > ( userOverrides . Except ( this . KnownSettings ) ) ;
foreach ( var item in SliceSettingsOrganizer . Instance . SettingsData . Where ( settingsItem = > ! settingsItem . ShowAsOverride ) )
{
switch ( item . SlicerConfigName )
{
2016-07-12 17:46:48 -07:00
case SettingsKey . baud_rate :
case SettingsKey . auto_connect :
2016-06-11 16:24:30 -07:00
// These items are marked as not being overrides but should be cleared on 'reset to defaults'
break ;
default :
// All other non-overrides should be retained
keysToRetain . Add ( item . SlicerConfigName ) ;
break ;
}
}
var keysToRemove = ( from keyValue in this . UserLayer
where ! keysToRetain . Contains ( keyValue . Key )
select keyValue . Key ) . ToList ( ) ;
foreach ( string key in keysToRemove )
{
this . UserLayer . Remove ( key ) ;
}
}
2016-04-27 18:57:51 -07:00
public string ExtruderTemperature ( int extruderIndex )
2016-04-18 11:31:31 -07:00
{
if ( extruderIndex > = layeredProfile . MaterialSettingsKeys . Count )
2015-04-08 15:20:10 -07:00
{
2016-05-03 10:59:37 -07:00
// MaterialSettingsKeys is empty or lacks a value for the given extruder index
//
// If extruder index zero was requested, return the layer cascade temperature value, otherwise null
return ( extruderIndex = = 0 ) ? layeredProfile . GetValue ( "temperature" ) : null ;
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
string materialKey = layeredProfile . MaterialSettingsKeys [ extruderIndex ] ;
2016-05-03 10:59:37 -07:00
if ( extruderIndex = = 0 & & ( string . IsNullOrEmpty ( materialKey ) | | layeredProfile . UserLayer . ContainsKey ( "temperature" ) ) )
{
// In the case where a user override exists or MaterialSettingsKeys is populated with multiple extruder
// positions but position 0 is empty and thus unassigned, use layer cascade to resolve temp
return layeredProfile . GetValue ( "temperature" ) ;
}
// Otherwise, use the SettingsLayers that is bound to this extruder
2016-06-15 14:50:12 -07:00
PrinterSettingsLayer layer = layeredProfile . GetMaterialLayer ( materialKey ) ;
2016-04-18 11:31:31 -07:00
2016-04-28 11:53:01 -07:00
string result = "0" ;
layer ? . TryGetValue ( "temperature" , out result ) ;
2016-04-18 11:31:31 -07:00
return result ;
2015-04-08 15:20:10 -07:00
}
2016-04-27 18:57:51 -07:00
public int [ ] LayerToPauseOn ( )
2015-11-30 16:19:32 -08:00
{
2016-06-15 17:18:39 -07:00
string [ ] userValues = GetValue ( "layer_to_pause" ) . Split ( ';' ) ;
2015-11-30 16:19:32 -08:00
2016-04-27 18:57:51 -07:00
int temp ;
return userValues . Where ( v = > int . TryParse ( v , out temp ) ) . Select ( v = >
{
2016-06-16 07:23:42 -07:00
//Convert from 0 based index to 1 based index
int val = int . Parse ( v ) ;
2015-12-29 12:57:24 -08:00
2016-06-16 07:23:42 -07:00
// Special case for user entered zero that pushes 0 to 1, otherwise val = val - 1 for 1 based index
return val = = 0 ? 1 : val - 1 ;
2016-04-27 18:57:51 -07:00
} ) . ToArray ( ) ;
2015-11-30 16:19:32 -08:00
}
2015-04-08 15:20:10 -07:00
private static double ParseDouble ( string firstLayerValueString )
{
double firstLayerValue ;
if ( ! double . TryParse ( firstLayerValueString , out firstLayerValue ) )
{
throw new Exception ( string . Format ( "Format cannot be parsed. FirstLayerHeight '{0}'" , firstLayerValueString ) ) ;
}
return firstLayerValue ;
}
2016-04-27 18:57:51 -07:00
public Vector2 ExtruderOffset ( int extruderIndex )
2015-04-08 15:20:10 -07:00
{
2016-06-15 17:18:39 -07:00
string currentOffsets = GetValue ( "extruder_offset" ) ;
2015-04-08 15:20:10 -07:00
string [ ] offsets = currentOffsets . Split ( ',' ) ;
int count = 0 ;
foreach ( string offset in offsets )
{
if ( count = = extruderIndex )
{
string [ ] xy = offset . Split ( 'x' ) ;
return new Vector2 ( double . Parse ( xy [ 0 ] ) , double . Parse ( xy [ 1 ] ) ) ;
}
count + + ;
}
return Vector2 . Zero ;
}
2016-04-18 11:31:31 -07:00
private PrintLevelingData printLevelingData = null ;
2016-04-28 09:41:27 -07:00
public PrintLevelingData GetPrintLevelingData ( )
2015-04-08 15:20:10 -07:00
{
2016-04-28 09:41:27 -07:00
if ( printLevelingData = = null )
2015-04-08 15:20:10 -07:00
{
2016-04-28 09:41:27 -07:00
printLevelingData = PrintLevelingData . Create (
ActiveSliceSettings . Instance ,
2016-06-16 16:35:10 -07:00
layeredProfile . GetValue ( "print_leveling_data" ) ,
2016-04-28 09:41:27 -07:00
layeredProfile . GetValue ( "MatterControl.PrintLevelingProbePositions" ) ) ;
2015-04-08 15:20:10 -07:00
2016-04-28 09:41:27 -07:00
PrintLevelingPlane . Instance . SetPrintLevelingEquation (
printLevelingData . SampledPosition0 ,
printLevelingData . SampledPosition1 ,
printLevelingData . SampledPosition2 ,
2016-06-21 09:38:37 -07:00
ActiveSliceSettings . Instance . GetValue < Vector2 > ( SettingsKey . print_center ) ) ;
2016-04-22 13:19:26 -07:00
}
2016-04-28 09:41:27 -07:00
return printLevelingData ;
2016-04-22 13:19:26 -07:00
}
2016-04-28 09:41:27 -07:00
public void SetPrintLevelingData ( PrintLevelingData data )
2015-04-08 15:20:10 -07:00
{
2016-04-28 09:41:27 -07:00
printLevelingData = data ;
2016-06-16 16:35:10 -07:00
layeredProfile . SetValue ( "print_leveling_data" , JsonConvert . SerializeObject ( data ) ) ;
2015-04-08 15:20:10 -07:00
2016-04-28 09:41:27 -07:00
}
2016-05-02 14:59:26 -07:00
public void DoPrintLeveling ( bool doLeveling )
2016-04-28 09:41:27 -07:00
{
// Early exit if already set
2016-06-16 16:35:10 -07:00
if ( doLeveling = = this . GetValue < bool > ( "print_leveling_enabled" ) )
2015-04-08 15:20:10 -07:00
{
2016-04-28 09:41:27 -07:00
return ;
}
2016-04-18 11:31:31 -07:00
2016-06-16 16:35:10 -07:00
layeredProfile . SetValue ( "print_leveling_enabled" , doLeveling ? "1" : "0" ) ;
2016-04-18 11:31:31 -07:00
2016-04-28 09:41:27 -07:00
DoPrintLevelingChanged . CallEvents ( this , null ) ;
2016-04-18 11:31:31 -07:00
2016-05-02 14:59:26 -07:00
if ( doLeveling )
2016-04-28 09:41:27 -07:00
{
PrintLevelingData levelingData = ActiveSliceSettings . Instance . GetPrintLevelingData ( ) ;
PrintLevelingPlane . Instance . SetPrintLevelingEquation (
levelingData . SampledPosition0 ,
levelingData . SampledPosition1 ,
levelingData . SampledPosition2 ,
2016-06-21 09:38:37 -07:00
ActiveSliceSettings . Instance . GetValue < Vector2 > ( SettingsKey . print_center ) ) ;
2015-04-08 15:20:10 -07:00
}
}
2016-04-18 11:31:31 -07:00
private static readonly SlicingEngineTypes defaultEngineType = SlicingEngineTypes . MatterSlice ;
2016-04-28 09:41:27 -07:00
public SlicingEngineTypes ActiveSliceEngineType ( )
2015-04-08 15:20:10 -07:00
{
2016-06-16 16:56:17 -07:00
string engineType = layeredProfile . GetValue ( "slicing_engine" ) ;
2016-06-16 07:23:42 -07:00
if ( string . IsNullOrEmpty ( engineType ) )
{
return defaultEngineType ;
}
2015-04-08 15:20:10 -07:00
2016-06-16 07:23:42 -07:00
var engine = ( SlicingEngineTypes ) Enum . Parse ( typeof ( SlicingEngineTypes ) , engineType ) ;
return engine ;
2016-04-28 09:41:27 -07:00
}
public void ActiveSliceEngineType ( SlicingEngineTypes type )
{
2016-06-16 16:56:17 -07:00
SetActiveValue ( "slicing_engine" , type . ToString ( ) ) ;
2015-04-08 15:20:10 -07:00
}
2016-04-27 18:57:51 -07:00
public SliceEngineMapping ActiveSliceEngine ( )
2015-04-08 15:20:10 -07:00
{
2016-04-28 09:41:27 -07:00
switch ( ActiveSliceEngineType ( ) )
2015-04-08 15:20:10 -07:00
{
2016-04-27 18:57:51 -07:00
case SlicingEngineTypes . CuraEngine :
return EngineMappingCura . Instance ;
2016-04-18 11:31:31 -07:00
2016-04-27 18:57:51 -07:00
case SlicingEngineTypes . MatterSlice :
return EngineMappingsMatterSlice . Instance ;
2016-04-18 11:31:31 -07:00
2016-04-27 18:57:51 -07:00
case SlicingEngineTypes . Slic3r :
return Slic3rEngineMappings . Instance ;
2015-04-08 15:20:10 -07:00
2016-04-27 18:57:51 -07:00
default :
return null ;
2016-04-18 11:31:31 -07:00
}
2015-04-08 15:20:10 -07:00
}
2016-06-16 13:20:38 -07:00
#region Migrate to LayeredProfile
2016-07-13 09:36:33 -07:00
static Dictionary < string , Type > expectedMappingTypes = new Dictionary < string , Type > ( )
{
[SettingsKey.extruders_share_temperature] = typeof ( int ) ,
[SettingsKey.extruder_count] = typeof ( int ) ,
[SettingsKey.extruders_share_temperature] = typeof ( bool ) ,
[SettingsKey.has_heated_bed] = typeof ( bool ) ,
[SettingsKey.nozzle_diameter] = typeof ( double ) ,
[SettingsKey.bed_temperature] = typeof ( double ) ,
} ;
void ValidateType < T > ( string settingsKey )
{
if ( expectedMappingTypes . ContainsKey ( settingsKey ) )
{
if ( expectedMappingTypes [ settingsKey ] ! = typeof ( T ) )
{
throw new Exception ( "You must request the correct type of this settingsKey." ) ;
}
}
if ( settingsKey . Contains ( "%" ) )
{
if ( typeof ( T ) ! = typeof ( double ) )
{
throw new Exception ( "To get processing of a % you must request the type as double." ) ;
}
}
}
2016-04-18 11:31:31 -07:00
///<summary>
///Returns the first matching value discovered while enumerating the settings layers
///</summary>
2016-06-15 14:50:12 -07:00
public T GetValue < T > ( string settingsKey ) where T : IConvertible
{
2016-07-13 09:36:33 -07:00
#if DEBUG
ValidateType < T > ( settingsKey ) ;
#endif
2016-06-15 14:50:12 -07:00
if ( typeof ( T ) = = typeof ( bool ) )
{
2016-06-16 10:22:38 -07:00
return ( T ) ( object ) ( this . GetValue ( settingsKey ) = = "1" ) ;
2016-06-15 14:50:12 -07:00
}
else if ( typeof ( T ) = = typeof ( int ) )
{
2016-06-16 14:35:42 -07:00
if ( settingsKey = = SettingsKey . extruder_count
2016-06-16 10:31:18 -07:00
& & this . GetValue < bool > ( SettingsKey . extruders_share_temperature ) )
{
return ( T ) ( object ) 1 ;
}
2016-06-15 14:50:12 -07:00
int result ;
2016-06-15 17:18:39 -07:00
int . TryParse ( this . GetValue ( settingsKey ) , out result ) ;
2016-06-15 14:50:12 -07:00
return ( T ) ( object ) ( result ) ;
}
2016-06-16 10:22:38 -07:00
else if ( typeof ( T ) = = typeof ( Vector2 ) )
2016-06-16 06:58:28 -07:00
{
string [ ] twoValues = GetValue ( settingsKey ) . Split ( ',' ) ;
if ( twoValues . Length ! = 2 )
{
throw new Exception ( string . Format ( "Not parsing {0} as a Vector2" , settingsKey ) ) ;
}
Vector2 valueAsVector2 = new Vector2 ( ) ;
valueAsVector2 . x = ParseDouble ( twoValues [ 0 ] ) ;
valueAsVector2 . y = ParseDouble ( twoValues [ 1 ] ) ;
return ( T ) ( object ) ( valueAsVector2 ) ;
}
2016-06-15 14:50:12 -07:00
else if ( typeof ( T ) = = typeof ( double ) )
{
2016-06-15 17:18:39 -07:00
string settingsStringh = GetValue ( settingsKey ) ;
2016-06-15 14:50:12 -07:00
if ( settingsStringh . Contains ( "%" ) )
{
string onlyNumber = settingsStringh . Replace ( "%" , "" ) ;
double ratio = ParseDouble ( onlyNumber ) / 100 ;
2016-06-21 09:38:37 -07:00
if ( settingsKey = = SettingsKey . first_layer_height )
2016-06-15 14:50:12 -07:00
{
2016-06-21 09:38:37 -07:00
return ( T ) ( object ) ( GetValue < double > ( SettingsKey . layer_height ) * ratio ) ;
2016-06-16 06:58:28 -07:00
}
2016-07-12 18:06:06 -07:00
else if ( settingsKey = = SettingsKey . first_layer_extrusion_width )
2016-06-16 06:58:28 -07:00
{
2016-07-12 16:43:39 -07:00
return ( T ) ( object ) ( GetValue < double > ( SettingsKey . nozzle_diameter ) * ratio ) ;
2016-06-15 14:50:12 -07:00
}
return ( T ) ( object ) ( ratio ) ;
}
2016-07-12 18:06:06 -07:00
else if ( settingsKey = = SettingsKey . first_layer_extrusion_width )
2016-07-12 16:43:39 -07:00
{
double extrusionResult ;
double . TryParse ( this . GetValue ( settingsKey ) , out extrusionResult ) ;
return ( T ) ( object ) ( extrusionResult = = 0 ? GetValue < double > ( SettingsKey . nozzle_diameter ) : extrusionResult ) ;
}
2016-06-15 14:50:12 -07:00
2016-06-16 14:35:42 -07:00
if ( settingsKey = = SettingsKey . bed_temperature
2016-06-21 09:38:37 -07:00
& & ! this . GetValue < bool > ( SettingsKey . has_heated_bed ) )
2016-06-16 10:22:38 -07:00
{
2016-06-17 15:07:43 -07:00
return ( T ) Convert . ChangeType ( 0 , typeof ( double ) ) ;
2016-06-16 10:22:38 -07:00
}
2016-06-15 14:50:12 -07:00
double result ;
2016-06-15 17:18:39 -07:00
double . TryParse ( this . GetValue ( settingsKey ) , out result ) ;
2016-06-15 14:50:12 -07:00
return ( T ) ( object ) ( result ) ;
}
2016-06-16 10:22:38 -07:00
else if ( typeof ( T ) = = typeof ( BedShape ) )
{
2016-06-16 14:35:42 -07:00
switch ( GetValue ( settingsKey ) )
2016-06-16 10:22:38 -07:00
{
case "rectangular" :
2016-06-16 12:19:13 -07:00
return ( T ) ( object ) BedShape . Rectangular ;
2016-06-16 10:22:38 -07:00
case "circular" :
2016-06-16 12:19:13 -07:00
return ( T ) ( object ) BedShape . Circular ;
2016-06-16 10:22:38 -07:00
default :
#if DEBUG
2016-06-21 09:38:37 -07:00
throw new NotImplementedException ( string . Format ( "'{0}' is not a known bed_shape." , GetValue ( SettingsKey . bed_shape ) ) ) ;
2016-06-16 10:22:38 -07:00
#else
2016-06-16 12:19:13 -07:00
return ( T ) ( object ) BedShape . Rectangular ;
2016-06-16 10:22:38 -07:00
#endif
}
}
2016-06-15 14:50:12 -07:00
return ( T ) default ( T ) ;
}
2016-04-18 11:31:31 -07:00
/// <summary>
/// Returns whether or not the setting is overridden by the active layer
/// </summary>
public bool SettingExistsInLayer ( string sliceSetting , NamedSettingsLayers layer )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
if ( layeredProfile = = null )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
return false ;
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
switch ( layer )
{
case NamedSettingsLayers . Quality :
return layeredProfile ? . QualityLayer ? . ContainsKey ( sliceSetting ) = = true ;
case NamedSettingsLayers . Material :
return layeredProfile ? . MaterialLayer ? . ContainsKey ( sliceSetting ) = = true ;
case NamedSettingsLayers . User :
return layeredProfile ? . UserLayer ? . ContainsKey ( sliceSetting ) = = true ;
default :
return false ;
2015-04-08 15:20:10 -07:00
}
}
2016-06-09 14:58:39 -07:00
public void ExportAsMatterControlConfig ( )
2015-04-08 15:20:10 -07:00
{
2016-06-09 14:58:39 -07:00
FileDialog . SaveFileDialog (
new SaveFileDialogParams ( "MatterControl Printer Export|*.printer" , title : "Export Printer Settings" ) ,
( saveParams ) = >
{
File . WriteAllText ( saveParams . FileName , JsonConvert . SerializeObject ( layeredProfile , Formatting . Indented ) ) ;
} ) ;
2015-04-08 15:20:10 -07:00
}
2014-01-29 19:09:30 -08:00
2016-06-09 14:58:39 -07:00
public void ExportAsSlic3rConfig ( )
2014-10-09 12:23:31 -07:00
{
2016-06-09 14:58:39 -07:00
FileDialog . SaveFileDialog (
new SaveFileDialogParams ( "Save Slice Configuration" . Localize ( ) + "|*." + configFileExtension )
{
FileName = "default_settings.ini"
} ,
( saveParams ) = >
{
if ( ! string . IsNullOrEmpty ( saveParams . FileName ) )
{
GenerateConfigFile ( saveParams . FileName , false ) ;
}
} ) ;
}
public void ExportAsCuraConfig ( )
{
throw new NotImplementedException ( ) ;
2015-04-08 15:20:10 -07:00
}
2014-10-09 12:23:31 -07:00
2016-05-03 11:26:41 -07:00
public long GetLongHashCode ( )
2015-04-08 15:20:10 -07:00
{
2016-05-02 16:34:13 -07:00
var bigStringForHashCode = new StringBuilder ( ) ;
foreach ( var keyValue in this . BaseLayer )
2015-04-08 15:20:10 -07:00
{
2016-07-18 10:52:36 -07:00
SliceSettingData data = SliceSettingsOrganizer . Instance . GetSettingsData ( keyValue . Key ) ;
if ( data . RebuildGCodeOnChange )
{
string activeValue = GetValue ( keyValue . Key ) ;
bigStringForHashCode . Append ( keyValue . Key ) ;
bigStringForHashCode . Append ( activeValue ) ;
}
2016-05-02 16:34:13 -07:00
}
2016-04-18 11:31:31 -07:00
2016-05-03 11:10:35 -07:00
string value = bigStringForHashCode . ToString ( ) ;
2016-04-18 11:31:31 -07:00
2016-05-03 11:26:41 -07:00
return agg_basics . ComputeHash ( bigStringForHashCode . ToString ( ) ) ;
2014-10-09 12:23:31 -07:00
}
2016-04-25 16:49:55 -07:00
public void GenerateConfigFile ( string fileName , bool replaceMacroValues )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
using ( var outstream = new StreamWriter ( fileName ) )
2015-04-08 15:20:10 -07:00
{
2016-05-31 17:58:47 -07:00
foreach ( var key in this . KnownSettings . Where ( k = > ! k . StartsWith ( "MatterControl." ) ) )
2016-04-25 16:49:55 -07:00
{
2016-06-15 17:18:39 -07:00
string activeValue = GetValue ( key ) ;
2016-04-18 11:31:31 -07:00
if ( replaceMacroValues )
{
activeValue = GCodeProcessing . ReplaceMacroValues ( activeValue ) ;
}
2016-05-31 17:58:47 -07:00
outstream . Write ( string . Format ( "{0} = {1}\n" , key , activeValue ) ) ;
2016-04-25 16:49:55 -07:00
activeValue = GCodeProcessing . ReplaceMacroValues ( activeValue ) ;
}
2015-04-08 15:20:10 -07:00
}
}
public bool IsValid ( )
{
try
{
2016-06-21 09:38:37 -07:00
if ( GetValue < double > ( SettingsKey . layer_height ) > GetValue < double > ( SettingsKey . nozzle_diameter ) )
2015-04-08 15:20:10 -07:00
{
string error = "'Layer Height' must be less than or equal to the 'Nozzle Diameter'." . Localize ( ) ;
2016-06-21 09:38:37 -07:00
string details = string . Format ( "Layer Height = {0}\nNozzle Diameter = {1}" . Localize ( ) , GetValue < double > ( SettingsKey . layer_height ) , GetValue < double > ( SettingsKey . nozzle_diameter ) ) ;
2015-06-09 11:30:14 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'General' -> 'Layers/Surface'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-06-21 09:38:37 -07:00
else if ( GetValue < double > ( SettingsKey . first_layer_height ) > GetValue < double > ( SettingsKey . nozzle_diameter ) )
2015-04-08 15:20:10 -07:00
{
2016-02-09 15:05:03 -08:00
string error = "'First Layer Height' must be less than or equal to the 'Nozzle Diameter'." . Localize ( ) ;
2016-06-21 09:38:37 -07:00
string details = string . Format ( "First Layer Height = {0}\nNozzle Diameter = {1}" . Localize ( ) , GetValue < double > ( SettingsKey . first_layer_height ) , GetValue < double > ( SettingsKey . nozzle_diameter ) ) ;
2015-06-09 11:30:14 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'General' -> 'Layers/Surface'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-02-04 09:50:00 -08:00
// If we have print leveling turned on then make sure we don't have any leveling commands in the start gcode.
2016-06-16 16:35:10 -07:00
if ( PrinterConnectionAndCommunication . Instance . ActivePrinter . GetValue < bool > ( "print_leveling_enabled" ) )
2016-02-04 09:50:00 -08:00
{
2016-06-15 17:18:39 -07:00
string [ ] startGCode = GetValue ( "start_gcode" ) . Replace ( "\\n" , "\n" ) . Split ( '\n' ) ;
2016-02-04 09:50:00 -08:00
foreach ( string startGCodeLine in startGCode )
{
if ( startGCodeLine . StartsWith ( "G29" ) )
{
string error = "Start G-Code cannot contain G29 if Print Leveling is enabled." . Localize ( ) ;
string details = "Your Start G-Code should not contain a G29 if you are planning on using print leveling. Change your start G-Code or turn off print leveling" . Localize ( ) ;
2016-03-21 14:41:32 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'Printer' -> 'Custom G-Code' -> 'Start G-Code'" . Localize ( ) ;
2016-02-04 09:50:00 -08:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
if ( startGCodeLine . StartsWith ( "G30" ) )
{
string error = "Start G-Code cannot contain G30 if Print Leveling is enabled." . Localize ( ) ;
string details = "Your Start G-Code should not contain a G30 if you are planning on using print leveling. Change your start G-Code or turn off print leveling" . Localize ( ) ;
2016-03-21 14:41:32 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'Printer' -> 'Custom G-Code' -> 'Start G-Code'" . Localize ( ) ;
2016-02-04 09:50:00 -08:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
}
}
2016-07-12 18:06:06 -07:00
if ( GetValue < double > ( SettingsKey . first_layer_extrusion_width ) > GetValue < double > ( SettingsKey . nozzle_diameter ) * 4 )
2015-04-08 15:20:10 -07:00
{
2016-02-09 15:05:03 -08:00
string error = "'First Layer Extrusion Width' must be less than or equal to the 'Nozzle Diameter' * 4." . Localize ( ) ;
2016-07-12 18:06:06 -07:00
string details = string . Format ( "First Layer Extrusion Width = {0}\nNozzle Diameter = {1}" . Localize ( ) , GetValue ( SettingsKey . first_layer_extrusion_width ) , GetValue < double > ( SettingsKey . nozzle_diameter ) ) ;
2015-07-31 12:22:32 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Extrusion' -> 'First Layer'" . Localize ( ) ;
2015-06-09 11:30:14 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-07-12 18:06:06 -07:00
if ( GetValue < double > ( SettingsKey . first_layer_extrusion_width ) < = 0 )
2015-06-09 11:30:14 -07:00
{
2016-02-09 15:05:03 -08:00
string error = "'First Layer Extrusion Width' must be greater than 0." . Localize ( ) ;
2016-07-12 18:06:06 -07:00
string details = string . Format ( "First Layer Extrusion Width = {0}" . Localize ( ) , GetValue ( SettingsKey . first_layer_extrusion_width ) ) ;
2015-07-31 12:22:32 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Extrusion' -> 'First Layer'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-06-16 10:22:38 -07:00
if ( GetValue < double > ( SettingsKey . min_fan_speed ) > 100 )
2015-04-08 15:20:10 -07:00
{
2016-02-09 15:05:03 -08:00
string error = "The Minimum Fan Speed can only go as high as 100%." . Localize ( ) ;
2016-06-16 10:22:38 -07:00
string details = string . Format ( "It is currently set to {0}." . Localize ( ) , GetValue < double > ( SettingsKey . min_fan_speed ) ) ;
2016-02-09 15:05:03 -08:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Cooling'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-06-16 06:58:28 -07:00
if ( GetValue < double > ( "max_fan_speed" ) > 100 )
2015-04-08 15:20:10 -07:00
{
2016-02-09 15:05:03 -08:00
string error = "The Maximum Fan Speed can only go as high as 100%." . Localize ( ) ;
2016-06-16 06:58:28 -07:00
string details = string . Format ( "It is currently set to {0}." . Localize ( ) , GetValue < double > ( "max_fan_speed" ) ) ;
2016-02-09 15:05:03 -08:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Cooling'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-06-16 10:31:18 -07:00
if ( GetValue < int > ( SettingsKey . extruder_count ) < 1 )
2015-04-08 15:20:10 -07:00
{
string error = "The Extruder Count must be at least 1." . Localize ( ) ;
2016-06-16 10:31:18 -07:00
string details = string . Format ( "It is currently set to {0}." . Localize ( ) , GetValue < int > ( SettingsKey . extruder_count ) ) ;
2016-02-09 15:05:03 -08:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'Printer' -> 'Features'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-06-16 10:51:18 -07:00
if ( GetValue < double > ( SettingsKey . fill_density ) < 0 | | GetValue < double > ( SettingsKey . fill_density ) > 1 )
2015-04-08 15:20:10 -07:00
{
2016-02-09 15:05:03 -08:00
string error = "The Fill Density must be between 0 and 1." . Localize ( ) ;
2016-06-16 10:51:18 -07:00
string details = string . Format ( "It is currently set to {0}." . Localize ( ) , GetValue < double > ( SettingsKey . fill_density ) ) ;
2015-06-09 11:30:14 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'General' -> 'Infill'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return false ;
}
2016-06-16 10:51:18 -07:00
if ( GetValue < double > ( SettingsKey . fill_density ) = = 1
2016-06-15 17:18:39 -07:00
& & GetValue ( "infill_type" ) ! = "LINES" )
2015-10-20 15:39:59 -07:00
{
string error = "Solid Infill works best when set to LINES." . Localize ( ) ;
2016-06-15 17:18:39 -07:00
string details = string . Format ( "It is currently set to {0}." . Localize ( ) , GetValue ( "infill_type" ) ) ;
2015-10-20 15:39:59 -07:00
string location = "Location: 'Settings & Controls' -> 'Settings' -> 'General' -> 'Infill Type'" . Localize ( ) ;
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2}" , error , details , location ) , "Slice Error" . Localize ( ) ) ;
return true ;
}
2016-03-04 11:11:20 -08:00
2015-06-09 11:30:14 -07:00
string normalSpeedLocation = "Location: 'Settings & Controls' -> 'Settings' -> 'General' -> 'Speed'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
// If the given speed is part of the current slice engine then check that it is greater than 0.
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "bridge_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "external_perimeter_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "first_layer_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "gap_fill_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "infill_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "perimeter_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "small_perimeter_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "solid_infill_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "support_material_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "top_solid_infill_speed" , normalSpeedLocation ) ) return false ;
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "travel_speed" , normalSpeedLocation ) ) return false ;
2015-06-09 11:30:14 -07:00
string retractSpeedLocation = "Location: 'Settings & Controls' -> 'Settings' -> 'Filament' -> 'Filament' -> 'Retraction'" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
if ( ! ValidateGoodSpeedSettingGreaterThan0 ( "retract_speed" , retractSpeedLocation ) ) return false ;
}
catch ( Exception e )
{
2015-09-11 10:48:24 -07:00
Debug . Print ( e . Message ) ;
2015-09-17 13:45:26 -07:00
GuiWidget . BreakInDebugger ( ) ;
2015-04-08 15:20:10 -07:00
string stackTraceNoBackslashRs = e . StackTrace . Replace ( "\r" , "" ) ;
ContactFormWindow . Open ( "Parse Error while slicing" . Localize ( ) , e . Message + stackTraceNoBackslashRs ) ;
return false ;
}
return true ;
}
private bool ValidateGoodSpeedSettingGreaterThan0 ( string speedSetting , string speedLocation )
{
2016-06-15 17:18:39 -07:00
string actualSpeedValueString = GetValue ( speedSetting ) ;
2015-04-08 15:20:10 -07:00
string speedValueString = actualSpeedValueString ;
if ( speedValueString . EndsWith ( "%" ) )
{
speedValueString = speedValueString . Substring ( 0 , speedValueString . Length - 1 ) ;
}
bool valueWasNumber = true ;
double speedToCheck ;
if ( ! double . TryParse ( speedValueString , out speedToCheck ) )
{
valueWasNumber = false ;
}
if ( ! valueWasNumber
2016-04-27 18:57:51 -07:00
| | ( ActiveSliceSettings . Instance . ActiveSliceEngine ( ) . MapContains ( speedSetting )
2015-04-08 15:20:10 -07:00
& & speedToCheck < = 0 ) )
{
2016-06-13 13:44:53 -07:00
SliceSettingData data = SliceSettingsOrganizer . Instance . GetSettingsData ( speedSetting ) ;
2015-04-08 15:20:10 -07:00
if ( data ! = null )
{
string error = string . Format ( "The '{0}' must be greater than 0." . Localize ( ) , data . PresentationName ) ;
string details = string . Format ( "It is currently set to {0}." . Localize ( ) , actualSpeedValueString ) ;
StyledMessageBox . ShowMessageBox ( null , string . Format ( "{0}\n\n{1}\n\n{2} -> '{3}'" , error , details , speedLocation , data . PresentationName ) , "Slice Error" . Localize ( ) ) ;
}
return false ;
}
return true ;
}
2016-04-18 11:31:31 -07:00
2016-06-17 09:29:11 -07:00
public Vector3 ManualMovementSpeeds ( )
{
Vector3 feedRate = new Vector3 ( 3000 , 3000 , 315 ) ;
string savedSettings = ActiveSliceSettings . Instance . GetValue ( "manual_movement_speeds" ) ;
if ( ! string . IsNullOrEmpty ( savedSettings ) )
{
var segments = savedSettings . Split ( ',' ) ;
feedRate . x = double . Parse ( segments [ 1 ] ) ;
feedRate . y = double . Parse ( segments [ 3 ] ) ;
feedRate . z = double . Parse ( segments [ 5 ] ) ;
}
return feedRate ;
}
public Dictionary < string , double > GetMovementSpeeds ( )
{
Dictionary < string , double > speeds = new Dictionary < string , double > ( ) ;
string movementSpeedsString = GetMovementSpeedsString ( ) ;
string [ ] allSpeeds = movementSpeedsString . Split ( ',' ) ;
for ( int i = 0 ; i < allSpeeds . Length / 2 ; i + + )
{
speeds . Add ( allSpeeds [ i * 2 + 0 ] , double . Parse ( allSpeeds [ i * 2 + 1 ] ) ) ;
}
return speeds ;
}
public string GetMovementSpeedsString ( )
{
string presets = "x,3000,y,3000,z,315,e0,150" ; // stored x,value,y,value,z,value,e1,value,e2,value,e3,value,...
if ( PrinterConnectionAndCommunication . Instance ! = null )
{
string savedSettings = GetValue ( "manual_movement_speeds" ) ;
if ( ! string . IsNullOrEmpty ( savedSettings ) )
{
presets = savedSettings ;
}
}
return presets ;
}
2016-06-16 13:20:38 -07:00
#endregion
2016-06-15 12:58:36 -07:00
public void SetMarkedForDelete ( bool markedForDelete )
{
2016-06-16 10:38:37 -07:00
var printerInfo = ProfileManager . Instance . ActiveProfile ;
if ( printerInfo ! = null )
{
printerInfo . MarkedForDelete = markedForDelete ;
ProfileManager . Instance . Save ( ) ;
}
// Clear selected printer state
UserSettings . Instance . set ( "ActiveProfileID" , "" ) ;
2016-06-15 12:58:36 -07:00
UiThread . RunOnIdle ( ( ) = > ActiveSliceSettings . Instance = ProfileManager . LoadEmptyProfile ( ) ) ;
}
2016-05-02 14:59:26 -07:00
public void SetBaudRate ( string baudRate )
2016-04-18 11:31:31 -07:00
{
2016-07-12 17:46:48 -07:00
layeredProfile . SetValue ( SettingsKey . baud_rate , baudRate ) ;
2016-04-18 11:31:31 -07:00
}
2016-04-28 09:41:27 -07:00
public string ComPort ( )
2016-04-18 11:31:31 -07:00
{
2016-06-16 17:04:57 -07:00
return layeredProfile . GetValue ( $"{Environment.MachineName}_com_port" ) ;
2016-04-18 11:31:31 -07:00
}
2016-04-28 09:41:27 -07:00
public void SetComPort ( string port )
2016-04-18 11:31:31 -07:00
{
2016-06-16 17:04:57 -07:00
layeredProfile . SetValue ( $"{Environment.MachineName}_com_port" , port ) ;
2016-04-28 09:41:27 -07:00
}
2016-06-15 14:50:12 -07:00
public void SetComPort ( string port , PrinterSettingsLayer layer )
2016-05-06 18:50:38 -07:00
{
2016-06-16 17:04:57 -07:00
layeredProfile . SetValue ( $"{Environment.MachineName}_com_port" , port , layer ) ;
2016-05-06 18:50:38 -07:00
}
2016-04-28 09:41:27 -07:00
public void SetSlicingEngine ( string engine )
{
2016-06-16 16:56:17 -07:00
layeredProfile . SetValue ( "slicing_engine" , engine ) ;
2016-04-28 09:41:27 -07:00
}
public void SetDriverType ( string driver )
{
2016-06-16 17:09:50 -07:00
layeredProfile . SetValue ( "driver_type" , driver ) ;
2016-04-28 09:41:27 -07:00
}
public void SetDeviceToken ( string token )
{
2016-07-12 17:46:48 -07:00
if ( layeredProfile . GetValue ( SettingsKey . device_token ) ! = token )
2016-06-15 12:58:36 -07:00
{
2016-07-12 17:46:48 -07:00
layeredProfile . SetValue ( SettingsKey . device_token , token ) ;
2016-06-15 12:58:36 -07:00
}
2016-04-18 11:31:31 -07:00
}
2016-04-28 09:41:27 -07:00
public void SetName ( string name )
2016-04-18 11:31:31 -07:00
{
2016-06-16 16:35:10 -07:00
layeredProfile . SetValue ( SettingsKey . printer_name , name ) ;
2016-04-28 09:41:27 -07:00
}
2016-06-15 17:59:52 -07:00
HashSet < string > knownSettings = null ;
2016-04-18 11:31:31 -07:00
2016-06-15 14:50:12 -07:00
[JsonIgnore]
2016-04-30 18:18:15 -07:00
public HashSet < string > KnownSettings
{
get
{
if ( knownSettings = = null )
{
string propertiesJson = StaticData . Instance . ReadAllText ( Path . Combine ( "SliceSettings" , "Properties.json" ) ) ;
var settingsData = JArray . Parse ( propertiesJson ) ;
knownSettings = new HashSet < string > ( settingsData . Select ( s = > s [ "SlicerConfigName" ] . Value < string > ( ) ) ) ;
}
return knownSettings ;
}
}
2016-04-28 09:41:27 -07:00
public void SetManualMovementSpeeds ( string speed )
{
2016-06-16 16:35:10 -07:00
layeredProfile . SetValue ( "manual_movement_speeds" , speed ) ;
2016-04-28 09:41:27 -07:00
}
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
public class PrinterInfo
{
public string ComPort { get ; set ; }
2016-06-15 12:58:36 -07:00
public string ID { get ; set ; }
2016-06-14 11:28:13 -07:00
public string Name { get ; set ; }
2016-07-14 16:48:18 -07:00
public string Make { get ; set ; }
public string Model { get ; set ; }
2016-07-01 17:11:05 -07:00
public string DeviceToken { get ; set ; }
public bool IsDirty { get ; set ; } = false ;
public bool MarkedForDelete { get ; set ; } = false ;
public string SHA1 { get ; set ; }
public void ChangeID ( string newID )
{
2016-07-15 13:32:02 -07:00
if ( ActiveSliceSettings . Instance . ID = = this . ID )
{
ActiveSliceSettings . Instance . ID = newID ;
}
2016-07-01 17:11:05 -07:00
string existingProfile = ProfilePath ;
if ( File . Exists ( existingProfile ) )
{
this . ID = newID ;
File . Move ( existingProfile , ProfilePath ) ;
}
var profile = ProfileManager . LoadProfile ( newID ) ;
profile . ID = newID ;
2016-07-12 17:46:48 -07:00
profile . SetActiveValue ( SettingsKey . device_token , newID ) ;
2016-07-01 17:11:05 -07:00
ProfileManager . Instance . Save ( ) ;
}
2016-06-23 15:27:19 -07:00
[JsonIgnore]
2016-07-14 11:19:13 -07:00
public string ProfilePath = > ProfileManager . Instance . ProfilePath ( this ) ;
2016-04-18 11:31:31 -07:00
}
2015-04-08 15:20:10 -07:00
}