From 0ba8a78dc5b1af6dda50babcd3e79513046685d8 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 27 Apr 2016 17:34:33 -0700 Subject: [PATCH] Fixed connection issues Got rid of AnchoredDropDownList Put in BaudRate user edit field --- ConfigurationPage/PrinterConfigurationPage.cs | 4 +- CustomWidgets/StyledDropDownList.cs | 24 ----------- .../Classic/ClassicSqlitePrinterProfiles.cs | 34 +++++++++------- .../PrinterConnectionAndCommunication.cs | 40 +++++++------------ .../Settings/ActiveSliceSettings.cs | 19 ++++++++- .../Settings/SettingsProfile.cs | 38 ++++++++++++++++++ .../SettingsControlSelectors.cs | 18 +++++++-- .../SlicerMapping/EngineMapingBase.cs | 1 + StaticData/PrinterSettings/config.ini | 1 + StaticData/SliceSettings/Layouts.txt | 3 +- StaticData/SliceSettings/Properties.json | 7 ++++ Submodules/agg-sharp | 2 +- 12 files changed, 119 insertions(+), 72 deletions(-) diff --git a/ConfigurationPage/PrinterConfigurationPage.cs b/ConfigurationPage/PrinterConfigurationPage.cs index 35735c6ae..28363f4f0 100644 --- a/ConfigurationPage/PrinterConfigurationPage.cs +++ b/ConfigurationPage/PrinterConfigurationPage.cs @@ -165,7 +165,7 @@ namespace MatterHackers.MatterControl FlowLayoutWidget controlsContainer = new FlowLayoutWidget(); controlsContainer.HAnchor |= HAnchor.ParentCenter; - AnchoredDropDownList releaseOptionsDropList = new AnchoredDropDownList("Development"); + var releaseOptionsDropList = new StyledDropDownList("Development"); releaseOptionsDropList.Margin = new BorderDouble(0, 3); MenuItem releaseOptionsDropDownItem = releaseOptionsDropList.AddItem("Release", "release"); @@ -203,7 +203,7 @@ namespace MatterHackers.MatterControl private void ReleaseOptionsDropList_SelectionChanged(object sender, EventArgs e) { - string releaseCode = ((AnchoredDropDownList)sender).SelectedValue; + string releaseCode = ((StyledDropDownList)sender).SelectedValue; if (releaseCode != UserSettings.Instance.get("UpdateFeedType")) { UserSettings.Instance.set("UpdateFeedType", releaseCode); diff --git a/CustomWidgets/StyledDropDownList.cs b/CustomWidgets/StyledDropDownList.cs index b5c41f4d3..4d232d9cb 100644 --- a/CustomWidgets/StyledDropDownList.cs +++ b/CustomWidgets/StyledDropDownList.cs @@ -53,28 +53,4 @@ namespace MatterHackers.MatterControl this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 0); } } - - public class AnchoredDropDownList : DropDownList - { - private static RGBA_Bytes whiteSemiTransparent = new RGBA_Bytes(255, 255, 255, 100); - private static RGBA_Bytes whiteTransparent = new RGBA_Bytes(255, 255, 255, 0); - - public AnchoredDropDownList(string noSelectionString, Direction direction = Direction.Down, double maxHeight = 0) - : base(noSelectionString, whiteTransparent, whiteSemiTransparent, direction, maxHeight) - { - this.HAnchor = HAnchor.ParentLeftRight; - this.TextColor = ActiveTheme.Instance.PrimaryTextColor; - - this.MenuItemsBorderWidth = 1; - this.MenuItemsBackgroundColor = RGBA_Bytes.White; - this.MenuItemsBorderColor = ActiveTheme.Instance.SecondaryTextColor; - this.MenuItemsPadding = new BorderDouble(10, 4, 10, 6); - this.MenuItemsBackgroundHoverColor = ActiveTheme.Instance.PrimaryAccentColor; - this.MenuItemsTextHoverColor = ActiveTheme.Instance.PrimaryTextColor; - this.BorderWidth = 1; - this.BorderColor = ActiveTheme.Instance.SecondaryTextColor; - this.HoverColor = whiteSemiTransparent; - this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 0); - } - } } \ No newline at end of file diff --git a/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs b/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs index 59e3c4e3f..ac49d44c0 100644 --- a/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs +++ b/DataStorage/Classic/ClassicSqlitePrinterProfiles.cs @@ -49,7 +49,6 @@ namespace MatterHackers.MatterControl.DataStorage.ClassicDB { public class ClassicSqlitePrinterProfiles { - public class ClassicSettingsLayer { //Container class representing a collection of setting along with the meta info for that collection @@ -93,24 +92,32 @@ namespace MatterHackers.MatterControl.DataStorage.ClassicDB string fullProfilePath = Path.Combine(profilePath, printer.Id + ".json"); + layeredProfile.UserLayer["MatterControl.Make"] = printer.Make ?? ""; + layeredProfile.UserLayer["MatterControl.Model"] = printer.Model ?? ""; + layeredProfile.UserLayer["MatterControl.BaudRate"] = printer.BaudRate ?? ""; + layeredProfile.UserLayer["MatterControl.ComPort"] = printer.ComPort ?? ""; + layeredProfile.UserLayer["MatterControl.DefaultMaterialPresets"] = printer.MaterialCollectionIds ?? ""; + layeredProfile.UserLayer["MatterControl.WindowsDriver"] = printer.DriverType ?? ""; + layeredProfile.UserLayer["MatterControl.DeviceToken"] = printer.DeviceToken ?? ""; + layeredProfile.UserLayer["MatterControl.DeviceType"] = printer.DeviceType ?? ""; + + // TODO: Where should this be collected from or stored to? + //layeredProfile.SetActiveValue("MatterControl.<<<<>>>>", printer.PrintLevelingJsonData); + + // TODO: Where can we find CalibrationFiiles in the current model? + //layeredProfile.SetActiveValue("MatterControl.CalibrationFiles", printer.Make); + File.WriteAllText(fullProfilePath, JsonConvert.SerializeObject(layeredProfile, Formatting.Indented)); - //GET LEVELING DATA from DB - - //PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(printer); - - /* - PrintLevelingPlane.Instance.SetPrintLevelingEquation( - levelingData.SampledPosition0, - levelingData.SampledPosition1, - levelingData.SampledPosition2, - ActiveSliceSettings.Instance.PrintCenter); */ - } private static void LoadMaterialSettings(LayeredProfile layeredProfile, Printer printer) { - var materialAssignments = printer.MaterialCollectionIds.Split(','); + var materialAssignments = printer.MaterialCollectionIds?.Split(','); + if(materialAssignments == null) + { + return; + } var collections = Datastore.Instance.dbSQLite.Table().Where(v => v.PrinterId == printer.Id && v.Tag == "material"); foreach (var collection in collections) @@ -176,7 +183,6 @@ namespace MatterHackers.MatterControl.DataStorage.ClassicDB settings.Add(defaultSettingsLayer); } - private static ClassicSettingsLayer LoadConfigurationSettingsFromFile(string pathAndFileName, SliceSettingsCollection collection) { Dictionary settingsDictionary = new Dictionary(); diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index 6bc3e6e8c..90eed30ac 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -396,9 +396,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication { try { - if (this.ActivePrinter.BaudRate != null) + if (ActiveSliceSettings.Instance.BaudRate != null) { - baudRate = Convert.ToInt32(this.ActivePrinter.BaudRate); + baudRate = Convert.ToInt32(ActiveSliceSettings.Instance.BaudRate); } } catch @@ -513,18 +513,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - public string ComPort - { - get - { - string comPort = null; - if (this.ActivePrinter != null) - { - comPort = this.ActivePrinter.ComPort; - } - return comPort; - } - } + public string ComPort => ActiveSliceSettings.Instance?.ComPort; + + public string DriverType => ActiveSliceSettings.Instance?.DriverType; public bool AtxPowerEnabled { @@ -1537,7 +1528,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication // current approach results in unpredictable behavior if the caller fails to close the connection if (serialPort == null && this.ActivePrinter != null) { - IFrostedSerialPort resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.ActivePrinter.DriverType).Create(this.ActivePrinter.ComPort); + IFrostedSerialPort resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).Create(this.ComPort); resetSerialPort.Open(); Thread.Sleep(500); @@ -1829,7 +1820,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication { // We reset the board while attempting to connect, so now we don't have a serial port. // Create one and do the DTR to reset - var resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.ActivePrinter.DriverType).Create(this.ActivePrinter.ComPort); + var resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).Create(this.ComPort); resetSerialPort.Open(); Thread.Sleep(500); @@ -2191,7 +2182,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication } bool serialPortIsAvailable = SerialPortIsAvailable(serialPortName); - bool serialPortIsAlreadyOpen = FrostedSerialPortFactory.GetAppropriateFactory(this.ActivePrinter.DriverType).SerialPortAlreadyOpen(serialPortName); + bool serialPortIsAlreadyOpen = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).SerialPortAlreadyOpen(serialPortName); if (serialPortIsAvailable && !serialPortIsAlreadyOpen) { @@ -2199,7 +2190,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication { try { - serialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.ActivePrinter.DriverType).CreateAndOpen(serialPortName, baudRate, true); + serialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).CreateAndOpen(serialPortName, baudRate, true); #if __ANDROID__ ToggleHighLowHeigh(serialPort); #endif @@ -2238,7 +2229,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication // If the serial port isn't available (i.e. the specified port name wasn't found in GetPortNames()) or the serial // port is already opened in another instance or process, then report the connection problem back to the user connectionFailureMessage = (serialPortIsAlreadyOpen ? - string.Format("{0} in use", PrinterConnectionAndCommunication.Instance.ActivePrinter.ComPort) : + string.Format("{0} in use", this.ComPort) : LocalizedString.Get("Port not found")); OnConnectionFailed(null); @@ -2262,8 +2253,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication //Debug.WriteLine("Open ports: {0}".FormatWith(portNames.Length)); if (portNames.Length > 0) { - //Debug.WriteLine("Connecting to: {0} {1}".FormatWith(this.ActivePrinter.ComPort, this.BaudRate)); - AttemptToConnect(this.ActivePrinter.ComPort, this.BaudRate); + AttemptToConnect(this.ComPort, this.BaudRate); if (CommunicationState == CommunicationStates.FailedToConnect) { OnConnectionFailed(null); @@ -2305,11 +2295,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication if (!string.IsNullOrEmpty(currentPortName)) { - this.ActivePrinter.ComPort = currentPortName; + this.ComPort = currentPortName; } #endif - if (SerialPortIsAvailable(this.ActivePrinter.ComPort)) + if (SerialPortIsAvailable(this.ComPort)) { //Create a timed callback to determine whether connection succeeded Timer connectionTimer = new Timer(new TimerCallback(ConnectionCallbackTimer)); @@ -2323,11 +2313,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication } else { - Debug.WriteLine("Connection failed: {0}".FormatWith(this.ActivePrinter.ComPort)); + Debug.WriteLine("Connection failed: {0}".FormatWith(this.ComPort)); connectionFailureMessage = string.Format( "{0} is not available".Localize(), - this.ActivePrinter.ComPort); + this.ComPort); OnConnectionFailed(null); } diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index 187367ed7..1b43999b9 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -35,6 +35,8 @@ using Newtonsoft.Json; using MatterHackers.MatterControl.SettingsManagement; using MatterHackers.Agg; using System.Linq; +using System.Collections.Generic; +using MatterHackers.Agg.PlatformAbstract; namespace MatterHackers.MatterControl.SlicerConfiguration { @@ -195,8 +197,23 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private static SettingsLayer LoadMatterHackersBaseLayer() { - // TODO: Build if missing? string baseConfigPath = Path.Combine(profilesPath, "config.json"); + if(!File.Exists(baseConfigPath)) + { + string configIniPath = StaticData.Instance.MapPath(Path.Combine("PrinterSettings", "config.ini")); + + SettingsLayer baseLayer; + + using (var sourceStream = StaticData.Instance.OpenSteam(configIniPath)) + using (var reader = new StreamReader(sourceStream)) + { + baseLayer = SettingsLayer.LoadFromIni(reader); + } + File.WriteAllText(baseConfigPath, JsonConvert.SerializeObject(baseLayer)); + + return baseLayer; + } + return JsonConvert.DeserializeObject(File.ReadAllText(baseConfigPath)); } diff --git a/SlicerConfiguration/Settings/SettingsProfile.cs b/SlicerConfiguration/Settings/SettingsProfile.cs index 7a3e3e1cd..1091953e4 100644 --- a/SlicerConfiguration/Settings/SettingsProfile.cs +++ b/SlicerConfiguration/Settings/SettingsProfile.cs @@ -1149,6 +1149,44 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return foundValue; } + + public static SettingsLayer LoadFromIni(TextReader reader) + { + var layer = new SettingsLayer(); + + string line; + while ((line = reader.ReadLine()) != null) + { + var segments = line.Split('='); + if (!line.StartsWith("#") && !string.IsNullOrEmpty(line)) + { + string key = segments[0].Trim(); + layer[key] = segments[1].Trim(); + } + } + + return layer; + } + + public static SettingsLayer LoadFromIni(string filePath) + { + var settings = from line in File.ReadAllLines(filePath) + let segments = line.Split('=') + where !line.StartsWith("#") && !string.IsNullOrEmpty(line) + select new + { + Key = segments[0].Trim(), + Value = segments[1].Trim() + }; + + var layer = new SettingsLayer(); + foreach (var setting in settings) + { + layer[setting.Key] = setting.Value; + } + + return layer; + } } public class ProfileData diff --git a/SlicerConfiguration/SettingsControlSelectors.cs b/SlicerConfiguration/SettingsControlSelectors.cs index 7f78fd9ac..26605f875 100644 --- a/SlicerConfiguration/SettingsControlSelectors.cs +++ b/SlicerConfiguration/SettingsControlSelectors.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.Agg.Image; +using MatterHackers.Agg.ImageProcessing; using MatterHackers.Agg.PlatformAbstract; using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; @@ -51,7 +52,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private string filterTag; private string filterLabel; - public AnchoredDropDownList DropDownList; + public StyledDropDownList DropDownList; private TupleList> DropDownMenuItems = new TupleList>(); private int extruderIndex; //For multiple materials @@ -221,9 +222,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration #endif } - private AnchoredDropDownList CreateDropdown() + private StyledDropDownList CreateDropdown() { - AnchoredDropDownList dropDownList = new AnchoredDropDownList("- default -", maxHeight: 300); + var dropDownList = new StyledDropDownList("- default -", maxHeight: 300) + { + UseLeftIcons = true, + HAnchor = HAnchor.ParentLeftRight, + MenuItemsPadding = new BorderDouble(10, 4, 10, 6), + }; + dropDownList.Margin = new BorderDouble(0, 3); dropDownList.MinimumSize = new Vector2(dropDownList.LocalBounds.Width, dropDownList.LocalBounds.Height); @@ -237,7 +244,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration menuItem.Selected += onItemSelect; } - // put in a small bottom region + MenuItem addNewPreset = dropDownList.AddItem("Add New Setting...", "new", InvertLightness.DoInvertLightness(StaticData.Instance.LoadIcon("icon_circle_plus.png"))); + addNewPreset.Selected += onNewItemSelect; + + if (false) { FlowLayoutWidget container = new FlowLayoutWidget(); container.HAnchor = HAnchor.ParentLeftRight; diff --git a/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs b/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs index af50f6b0d..29b2d0095 100644 --- a/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs +++ b/SlicerConfiguration/SlicerMapping/EngineMapingBase.cs @@ -53,6 +53,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration "has_heated_bed", "has_power_control", "has_sd_card_reader", + "MatterControl.BaudRate", "manual_probe_paper_width", "pause_gcode", "print_leveling_method", diff --git a/StaticData/PrinterSettings/config.ini b/StaticData/PrinterSettings/config.ini index d40a535ea..df93063de 100644 --- a/StaticData/PrinterSettings/config.ini +++ b/StaticData/PrinterSettings/config.ini @@ -74,6 +74,7 @@ infill_type = TRIANGLES layer_gcode = ; LAYER:[layer_num] layer_height = 0.4 layer_to_pause = +MatterControl.BaudRate = 250000 max_fan_speed = 100 min_extrusion_before_retract = .1 min_fan_speed = 35 diff --git a/StaticData/SliceSettings/Layouts.txt b/StaticData/SliceSettings/Layouts.txt index c0b2dc24a..a4bfd5c05 100644 --- a/StaticData/SliceSettings/Layouts.txt +++ b/StaticData/SliceSettings/Layouts.txt @@ -272,7 +272,9 @@ Advanced extruder_count heat_extruder_before_homing extruders_share_temperature + z_homes_to_max Firmware + MatterControl.BaudRate z_can_be_negative gcode_flavor use_relative_e_distances @@ -293,7 +295,6 @@ Advanced Speed resume_first_layer_speed Homing - z_homes_to_max resume_position_before_z_home Custom G-Code Start G-Code diff --git a/StaticData/SliceSettings/Properties.json b/StaticData/SliceSettings/Properties.json index 693a6d65f..2c61b6f92 100644 --- a/StaticData/SliceSettings/Properties.json +++ b/StaticData/SliceSettings/Properties.json @@ -1216,6 +1216,13 @@ "DataEditType": "CHECK_BOX", "ExtraSettings": "" }, + { + "SlicerConfigName": "MatterControl.BaudRate", + "PresentationName": "Baud Rate", + "HelpText": "The serial port communication speed of the printers firmware.", + "DataEditType": "INT", + "ExtraSettings": "" + }, { "SlicerConfigName": "vibration_limit", "PresentationName": "Vibration Limit", diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 686f8389f..798aad7d8 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 686f8389fd1a84dd8ab98bc6cbe1625b91389ed2 +Subproject commit 798aad7d8f2d9817979383bad80b2fbc368ae234