2014-01-29 19:09:30 -08:00
|
|
|
|
/*
|
2019-02-22 08:17:02 -08:00
|
|
|
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
2014-01-29 19:09:30 -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-01-29 19:09:30 -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-01-29 19:09:30 -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-01-29 19:09:30 -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-01-29 19:09:30 -08:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-05-24 19:11:51 -07:00
|
|
|
|
using System;
|
2018-05-15 08:42:56 -07:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-12 23:08:12 -07:00
|
|
|
|
using System.Linq;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2014-07-01 18:32:39 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2014-02-04 13:30:42 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2018-05-15 08:42:56 -07:00
|
|
|
|
using MatterHackers.MatterControl.ConfigurationPage;
|
2017-10-31 17:27:37 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2018-03-14 15:49:00 -07:00
|
|
|
|
public class GCodePanel : FlowLayoutWidget
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2019-02-01 16:12:12 -08:00
|
|
|
|
private ISceneContext sceneContext;
|
2017-10-19 09:01:07 -07:00
|
|
|
|
private ThemeConfig theme;
|
2018-02-09 19:23:19 -08:00
|
|
|
|
private PrinterConfig printer;
|
|
|
|
|
|
private SectionWidget speedsWidget;
|
2018-03-17 09:11:08 -07:00
|
|
|
|
private GuiWidget loadedGCodeSection;
|
2017-06-24 08:32:09 -07:00
|
|
|
|
|
2019-02-01 16:12:12 -08:00
|
|
|
|
public GCodePanel(PrinterConfig printer, ISceneContext sceneContext, ThemeConfig theme)
|
2018-02-16 18:47:07 -08:00
|
|
|
|
: base (FlowDirection.TopToBottom)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-09-15 16:49:21 -07:00
|
|
|
|
this.sceneContext = sceneContext;
|
2017-10-19 09:01:07 -07:00
|
|
|
|
this.theme = theme;
|
2018-02-09 19:23:19 -08:00
|
|
|
|
this.printer = printer;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-04-12 23:08:12 -07:00
|
|
|
|
SectionWidget sectionWidget;
|
|
|
|
|
|
|
2018-03-17 09:11:08 -07:00
|
|
|
|
this.AddChild(
|
2018-04-12 23:08:12 -07:00
|
|
|
|
sectionWidget = new SectionWidget(
|
2018-03-17 09:11:08 -07:00
|
|
|
|
"Options".Localize(),
|
|
|
|
|
|
new GCodeOptionsPanel(sceneContext, printer, theme),
|
2018-09-10 12:02:20 -07:00
|
|
|
|
theme)
|
2018-03-17 09:11:08 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-04-05 16:02:54 -07:00
|
|
|
|
VAnchor = VAnchor.Fit,
|
2018-04-12 23:08:12 -07:00
|
|
|
|
Padding = 0
|
2018-03-17 09:11:08 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
2018-04-12 23:08:12 -07:00
|
|
|
|
sectionWidget.ContentPanel.Descendants<SettingsRow>().First().Border = 0;
|
|
|
|
|
|
|
2018-05-15 11:36:43 -07:00
|
|
|
|
var scrollable = new ScrollableWidget(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "editorPanel",
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
scrollable.ScrollArea.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
|
|
|
|
|
|
scrollable.AddChild(loadedGCodeSection = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.AddChild(scrollable);
|
2018-03-17 09:11:08 -07:00
|
|
|
|
|
|
|
|
|
|
this.RefreshGCodeDetails(printer);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-05-15 08:42:56 -07:00
|
|
|
|
this.EnsureSectionWidgetStyling(this.Children<SectionWidget>());
|
|
|
|
|
|
|
2018-07-15 10:07:30 -07:00
|
|
|
|
var firstSection = this.Children<SectionWidget>().First();
|
|
|
|
|
|
firstSection.BorderColor = Color.Transparent; // Disable top border on first item to produce a more flat, dark top edge
|
|
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Register listeners
|
|
|
|
|
|
printer.Bed.LoadedGCodeChanged += Bed_LoadedGCodeChanged;
|
|
|
|
|
|
printer.Bed.RendererOptions.PropertyChanged += RendererOptions_PropertyChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-17 09:11:08 -07:00
|
|
|
|
private void RefreshGCodeDetails(PrinterConfig printer)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-03-17 09:11:08 -07:00
|
|
|
|
loadedGCodeSection.CloseAllChildren();
|
2017-06-02 06:45:04 -07:00
|
|
|
|
|
2017-09-15 16:49:21 -07:00
|
|
|
|
if (sceneContext.LoadedGCode?.LineCount > 0)
|
2017-06-30 15:05:07 -07:00
|
|
|
|
{
|
2018-05-08 15:19:06 -07:00
|
|
|
|
bool renderSpeeds = printer.Bed.RendererOptions.GCodeLineColorStyle == "Speeds";
|
|
|
|
|
|
loadedGCodeSection.AddChild(
|
|
|
|
|
|
speedsWidget = new SectionWidget(
|
|
|
|
|
|
"Speeds".Localize(),
|
2018-11-11 13:52:31 -08:00
|
|
|
|
new SpeedsLegend(sceneContext.LoadedGCode, theme, printer)
|
2018-05-08 15:19:06 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
Visible = renderSpeeds,
|
|
|
|
|
|
Padding = new BorderDouble(15, 4)
|
|
|
|
|
|
},
|
|
|
|
|
|
theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
speedsWidget.Visible = renderSpeeds;
|
|
|
|
|
|
|
2018-05-15 07:58:54 -07:00
|
|
|
|
// Single instance shared across widgets
|
2018-03-17 09:11:08 -07:00
|
|
|
|
loadedGCodeSection.AddChild(
|
2017-10-22 19:42:41 -07:00
|
|
|
|
new SectionWidget(
|
|
|
|
|
|
"Details".Localize(),
|
2018-10-29 16:38:31 -07:00
|
|
|
|
new GCodeDetailsView(printer.Bed.LoadedGCode, printer, theme)
|
2017-10-22 19:42:41 -07:00
|
|
|
|
{
|
2018-02-16 18:47:07 -08:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-02-09 22:51:18 -08:00
|
|
|
|
Margin = new BorderDouble(bottom: 3),
|
|
|
|
|
|
Padding = new BorderDouble(15, 4)
|
2018-01-10 15:00:59 -08:00
|
|
|
|
},
|
2018-02-16 18:47:07 -08:00
|
|
|
|
theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
});
|
2017-10-22 19:42:41 -07:00
|
|
|
|
|
2018-03-17 09:11:08 -07:00
|
|
|
|
loadedGCodeSection.AddChild(
|
2018-05-08 15:19:06 -07:00
|
|
|
|
new SectionWidget(
|
|
|
|
|
|
"Layer".Localize(),
|
2018-10-29 16:38:31 -07:00
|
|
|
|
new GCodeLayerDetailsView(printer.Bed.LoadedGCode, sceneContext, theme)
|
2017-10-22 19:42:41 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-05-08 15:19:06 -07:00
|
|
|
|
Margin = new BorderDouble(bottom: 3),
|
2018-02-09 22:51:18 -08:00
|
|
|
|
Padding = new BorderDouble(15, 4)
|
2018-01-10 15:00:59 -08:00
|
|
|
|
},
|
2018-02-16 18:47:07 -08:00
|
|
|
|
theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
});
|
2017-06-30 15:05:07 -07:00
|
|
|
|
}
|
2017-12-24 10:36:49 -08:00
|
|
|
|
|
2018-02-16 18:47:07 -08:00
|
|
|
|
// Enforce panel padding in sidebar
|
2018-05-15 08:42:56 -07:00
|
|
|
|
this.EnsureSectionWidgetStyling(loadedGCodeSection.Children<SectionWidget>());
|
2018-02-16 18:47:07 -08:00
|
|
|
|
|
2017-12-24 10:36:49 -08:00
|
|
|
|
this.Invalidate();
|
2017-06-30 15:05:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-15 08:42:56 -07:00
|
|
|
|
private void EnsureSectionWidgetStyling(IEnumerable<SectionWidget> sectionWidgets)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var sectionWidget in sectionWidgets)
|
|
|
|
|
|
{
|
|
|
|
|
|
var contentPanel = sectionWidget.ContentPanel;
|
|
|
|
|
|
var firstItem = contentPanel.Children<SettingsItem>().FirstOrDefault();
|
|
|
|
|
|
if (firstItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
firstItem.Border = firstItem.Border.Clone(top: 1);
|
|
|
|
|
|
contentPanel.Padding = new BorderDouble(10, 0, 10, 0);
|
|
|
|
|
|
contentPanel.Margin = contentPanel.Margin.Clone(bottom: 4);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
contentPanel.Padding = new BorderDouble(10, 10, 10, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var lastItem = contentPanel.Children<SettingsItem>().LastOrDefault();
|
|
|
|
|
|
if (lastItem != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastItem.Border = lastItem.Border.Clone(bottom: 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-17 09:10:07 -07:00
|
|
|
|
private void Bed_LoadedGCodeChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(() => this.RefreshGCodeDetails(printer));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-04 10:11:57 -07:00
|
|
|
|
private void RendererOptions_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
2018-02-09 19:23:19 -08:00
|
|
|
|
{
|
2018-04-04 10:11:57 -07:00
|
|
|
|
if (speedsWidget != null
|
|
|
|
|
|
&& e.PropertyName == "GCodeLineColorStyle")
|
2018-02-09 19:23:19 -08:00
|
|
|
|
{
|
2018-04-04 10:11:57 -07:00
|
|
|
|
speedsWidget.Visible = printer.Bed.RendererOptions.GCodeLineColorStyle == "Speeds";
|
2018-02-09 19:23:19 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:44:11 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Unregister listeners
|
2018-04-04 10:11:57 -07:00
|
|
|
|
printer.Bed.RendererOptions.PropertyChanged -= RendererOptions_PropertyChanged;
|
2018-03-17 09:10:07 -07:00
|
|
|
|
printer.Bed.LoadedGCodeChanged -= Bed_LoadedGCodeChanged;
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-27 12:05:14 -07:00
|
|
|
|
}
|