From f2e8a9d4ec923944edb28372a411b4354501ecfb Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 22 Jan 2019 09:15:30 -0800 Subject: [PATCH] Add error panel --- .../View3D/PrinterBar/PrintPopupMenu.cs | 79 ++++++++++++++++-- StaticData/Icons/noun_1306.png | Bin 0 -> 989 bytes 2 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 StaticData/Icons/noun_1306.png diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs index 1ba98b35a..68183879a 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs @@ -32,6 +32,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using MatterHackers.Agg; +using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; @@ -74,13 +75,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow allUiFields.Clear(); - var column = new FlowLayoutWidget(FlowDirection.TopToBottom) + var printPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) { Padding = theme.DefaultContainerPadding, BackgroundColor = menuTheme.BackgroundColor }; - column.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.TextColor) + printPanel.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.TextColor) { HAnchor = HAnchor.Left }); @@ -94,7 +95,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow MinimumSize = new Vector2(400, 65), Margin = new BorderDouble(top: 10), }; - column.AddChild(optionsPanel); + printPanel.AddChild(optionsPanel); foreach (var key in new[] { SettingsKey.layer_height, SettingsKey.fill_density, SettingsKey.create_raft }) { @@ -125,7 +126,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow VAnchor = VAnchor.Fit, Margin = 0 }; - column.AddChild(sectionWidget); + printPanel.AddChild(sectionWidget); foreach (var key in new[] { SettingsKey.spiral_vase, SettingsKey.layer_to_pause }) { @@ -160,8 +161,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow HAnchor = HAnchor.Stretch }; + // Perform validation before popup var errors = printer.ValidateSettings(); + // Enable print option when no validation Errors exists var printEnabled = !errors.Any(err => err.ErrorLevel == ValidationErrorLevel.Error); var startPrintButton = new TextButton("Start Print".Localize(), menuTheme) @@ -196,15 +199,72 @@ namespace MatterHackers.MatterControl.PartPreviewWindow setupRow.AddChild(new HorizontalSpacer()); setupRow.AddChild(startPrintButton); - column.AddChild(setupRow); + printPanel.AddChild(setupRow); - var printerNeedsToRunSetup = ApplicationController.PrinterNeedsToRunSetup(printer); - - if (!printerNeedsToRunSetup) + if (printEnabled) { theme.ApplyPrimaryActionStyle(startPrintButton); } + if (errors.Any()) + { + var errorsPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + HAnchor = HAnchor.Absolute, + VAnchor = VAnchor.Fit | VAnchor.Top, + BackgroundColor = theme.ResolveColor(menuTheme.BackgroundColor, theme.PrimaryAccentColor.WithAlpha(30)), + Width = 350 + }; + errorsPanel.Load += (s, e) => + { + errorsPanel.Parent.BackgroundColor = Color.Transparent; + }; + + errorsPanel.AddChild(new TextWidget("Warnings and Errors".Localize(), textColor: menuTheme.TextColor) + { + HAnchor = HAnchor.Left + }); + + var fixIcon = AggContext.StaticData.LoadIcon("noun_1306.png", 16, 16, theme.InvertIcons); + + foreach(var error in errors) + { + var row = new SettingsRow(error.Error, null, theme); + + if (error.FixAction is NamedAction action) + { + var button = new IconButton(fixIcon, theme) + { + ToolTipText = action.Title + }; + button.Click += (s, e) => + { + action.Action.Invoke(); + }; + + row.AddChild(button); + } + + errorsPanel.AddChild(row); + } + + // Conditional layout for right or bottom errors panel alignment + //var layoutStyle = FlowDirection.TopToBottom; + var layoutStyle = FlowDirection.LeftToRight; + + // Instead of the typical case where the print panel is returned, wrap and append validation errors panel + var errorsContainer = new FlowLayoutWidget(layoutStyle) + { + HAnchor = HAnchor.Fit, + VAnchor = VAnchor.Fit + }; + errorsContainer.AddChild(printPanel); + errorsContainer.AddChild(errorsPanel); + + return errorsContainer; + } + + /* // put in setup if needed if (printerNeedsToRunSetup && printerIsConnected) { @@ -234,8 +294,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }; column.AddChild(finishSetupButton); } + */ - return column; + return printPanel; }; this.AddChild(new TextButton("Print".Localize(), theme) diff --git a/StaticData/Icons/noun_1306.png b/StaticData/Icons/noun_1306.png new file mode 100644 index 0000000000000000000000000000000000000000..aafc465c496722d6fccc9f1ed69d06d07cd9d484 GIT binary patch literal 989 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7r87e!N+NuHtdjF{^%7I^ zlT!66atjzhz{b9!ATc>RwL~E)H9a%WR_Xoj{Yna%DYi=CroINg16w1-Ypui3%0DIeEoa6}C!XbFK1lpi<;HsXMd|v6mX?*7iAWdWaj57fXqxx$}cUkRZ`LiS)vaT z3373>Rs>jpDC9$+c7}IF(+q@Xs*eeVowF7v}tqye%o$*_?=G0)G5=ptv)p2T*}%T z873yy=JKERKUmnt#>5hG)=Yi5yNK4U=X+hc@0RV{s&)Kt_Ezs*Ya7)SY*x$+3#;&{ zNYc&TwMY5R64k4!4~-xCdFyG^Jb(33Y5%S{8lSeGo+c#Cl;2#S@v-~y{s`}=%*0B| z+?Q8Yh3)G9J!!$bnKP$t4Nc=VGj!_|N}7|{)^Xu*!w-(wFPC(!wVt$d{|sK^u}xf3Y}q?OTRd<`4g@T647gVG{Q&dEcu++>`v5T{n2}R^-*Q1s~b6 z#JX&?=N5lrIMr5j)%49<=k_Dl_5U%vewDt?{_`3W1_lPs0*}aI1_r((Aj~*bn@^g7 zf#H^?i(`mI@6t>Ay$&Uc9Q)X>c2Qm{Sit=Wmv8sj^7-#M?VtCpSsCQFw^4daK|}hN4-=B=I=J^J zA2weX=;yn$yU^fd!FHve^KTvVPMPp9