public GCodeLayerDetailsView(GCodeDetails gcodeDetails, BedConfig sceneContext, ThemeConfig theme) : base(FlowDirection.TopToBottom) { this.theme = theme; GuiWidget layerIndex = AddSetting("Number".Localize(), ""); GuiWidget layerTime = AddSetting("Time".Localize(), ""); GuiWidget layerTimeToHere = AddSetting("Time From Start".Localize(), ""); GuiWidget layerTimeFromHere = AddSetting("Time to End".Localize(), ""); GuiWidget layerHeight = AddSetting("Height".Localize(), ""); GuiWidget layerWidth = AddSetting("Layer Top".Localize(), ""); GuiWidget layerFanSpeeds = AddSetting("Fan Speed".Localize(), ""); void UpdateLayerDisplay(object sender, EventArgs e) { layerIndex.Text = $"{sceneContext.ActiveLayerIndex + 1}"; layerTime.Text = gcodeDetails.LayerTime(sceneContext.ActiveLayerIndex); layerTimeToHere.Text = gcodeDetails.LayerTimeToHere(sceneContext.ActiveLayerIndex); layerTimeFromHere.Text = gcodeDetails.LayerTimeFromeHere(sceneContext.ActiveLayerIndex); layerHeight.Text = $"{gcodeDetails.GetLayerHeight(sceneContext.ActiveLayerIndex):0.###}"; layerWidth.Text = $"{gcodeDetails.GetLayerTop(sceneContext.ActiveLayerIndex):0.###}"; var fanSpeed = gcodeDetails.GetLayerFanSpeeds(sceneContext.ActiveLayerIndex); layerFanSpeeds.Text = string.IsNullOrWhiteSpace(fanSpeed) ? "Unchanged" : fanSpeed; } sceneContext.ActiveLayerChanged += UpdateLayerDisplay; // and do the initial setting UpdateLayerDisplay(this, null); }
public GCodeDetailsView(GCodeDetails gcodeDetails, ThemeConfig theme) : base(FlowDirection.TopToBottom) { this.gcodeDetails = gcodeDetails; this.theme = theme; // put in the print time AddSetting("Print Time".Localize(), gcodeDetails.EstimatedPrintTime); // show the filament used AddSetting("Filament Length".Localize(), gcodeDetails.FilamentUsed); AddSetting("Filament Volume".Localize(), gcodeDetails.FilamentVolume); // Cost info is only displayed when available - conditionalCostPanel is invisible when cost <= 0 TextWidget costTextWidget = AddSetting("Estimated Cost".Localize(), gcodeDetails.EstimatedCost); TextWidget massTextWidget = AddSetting("Estimated Mass".Localize(), gcodeDetails.EstimatedMass); var conditionalCostContainer = costTextWidget.Parent; conditionalCostContainer.Visible = gcodeDetails.TotalCost > 0; PrinterSettings.SettingChanged.RegisterEvent((s, e) => { if (e is StringEventArgs stringEvent) { if (stringEvent.Data == SettingsKey.filament_cost || stringEvent.Data == SettingsKey.filament_diameter || stringEvent.Data == SettingsKey.filament_density) { massTextWidget.Text = gcodeDetails.EstimatedMass; conditionalCostContainer.Visible = gcodeDetails.TotalCost > 0; if (gcodeDetails.TotalCost > 0) { costTextWidget.Text = gcodeDetails.EstimatedCost; } } } }, ref unregisterEvents); }
private void RefreshGCodeDetails(PrinterConfig printer) { loadedGCodeSection.CloseAllChildren(); if (sceneContext.LoadedGCode?.LineCount > 0) { bool renderSpeeds = printer.Bed.RendererOptions.GCodeLineColorStyle == "Speeds"; loadedGCodeSection.AddChild( speedsWidget = new SectionWidget( "Speeds".Localize(), new SpeedsLegend(sceneContext.LoadedGCode, theme) { HAnchor = HAnchor.Stretch, Visible = renderSpeeds, Padding = new BorderDouble(15, 4) }, theme) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit }); speedsWidget.Visible = renderSpeeds; // Single instance shared across widgets var gcodeDetails = new GCodeDetails(printer, printer.Bed.LoadedGCode); loadedGCodeSection.AddChild( new SectionWidget( "Details".Localize(), new GCodeDetailsView(gcodeDetails, theme) { HAnchor = HAnchor.Stretch, Margin = new BorderDouble(bottom: 3), Padding = new BorderDouble(15, 4) }, theme) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit }); loadedGCodeSection.AddChild( new SectionWidget( "Layer".Localize(), new GCodeLayerDetailsView(gcodeDetails, sceneContext, theme) { HAnchor = HAnchor.Stretch, Margin = new BorderDouble(bottom: 3), Padding = new BorderDouble(15, 4) }, theme) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit }); } // Enforce panel padding in sidebar this.EnsureSectionWidgetStyling(loadedGCodeSection.Children <SectionWidget>()); this.Invalidate(); }