2018-12-28 16:00:21 -08:00
|
|
|
|
/*
|
2019-01-02 18:30:21 -08:00
|
|
|
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
2018-12-28 16:00:21 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2019-01-02 18:30:21 -08:00
|
|
|
|
using System.Collections.Generic;
|
2019-01-23 13:38:47 -08:00
|
|
|
|
using System.Reflection;
|
2019-01-04 15:53:01 -08:00
|
|
|
|
using System.Threading.Tasks;
|
2019-01-02 17:50:34 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2018-12-28 16:00:21 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
2018-12-31 12:12:05 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
using MatterHackers.MatterControl.DesignTools;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2018-12-28 16:00:21 -08:00
|
|
|
|
using MatterHackers.PolygonMesh;
|
2019-01-02 17:50:34 -08:00
|
|
|
|
using MatterHackers.RayTracer;
|
2018-12-28 16:00:21 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
2018-12-31 09:12:49 -08:00
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
2018-12-28 16:00:21 -08:00
|
|
|
|
{
|
2019-01-02 18:30:21 -08:00
|
|
|
|
public class GenerateSupportPanel : FlowLayoutWidget
|
2018-12-28 16:00:21 -08:00
|
|
|
|
{
|
2019-01-18 15:47:11 -08:00
|
|
|
|
private SupportGenerator supportGenerator;
|
2018-12-31 12:12:05 -08:00
|
|
|
|
private ThemeConfig theme;
|
2018-12-28 16:00:21 -08:00
|
|
|
|
|
2019-01-02 18:30:21 -08:00
|
|
|
|
public GenerateSupportPanel(ThemeConfig theme, InteractiveScene scene)
|
2018-12-31 12:12:05 -08:00
|
|
|
|
: base(FlowDirection.TopToBottom)
|
2018-12-28 16:00:21 -08:00
|
|
|
|
{
|
2019-01-18 15:47:11 -08:00
|
|
|
|
supportGenerator = new SupportGenerator(scene);
|
|
|
|
|
|
|
2018-12-31 09:12:49 -08:00
|
|
|
|
this.theme = theme;
|
2018-12-31 12:12:05 -08:00
|
|
|
|
|
2019-01-02 18:24:46 -08:00
|
|
|
|
this.VAnchor = VAnchor.Fit;
|
|
|
|
|
|
this.HAnchor = HAnchor.Absolute;
|
|
|
|
|
|
this.Width = 300;
|
|
|
|
|
|
this.BackgroundColor = theme.BackgroundColor;
|
|
|
|
|
|
this.Padding = theme.DefaultContainerPadding;
|
|
|
|
|
|
|
2019-01-23 16:08:27 -08:00
|
|
|
|
// Add an editor field for the SupportGenerator.SupportType
|
|
|
|
|
|
PropertyInfo propertyInfo = typeof(SupportGenerator).GetProperty(nameof(SupportGenerator.SupportType));
|
2018-12-31 12:12:05 -08:00
|
|
|
|
|
2019-01-23 16:08:27 -08:00
|
|
|
|
var editor = PublicPropertyEditor.CreatePropertyEditor(
|
|
|
|
|
|
new EditableProperty(propertyInfo, supportGenerator),
|
|
|
|
|
|
null,
|
|
|
|
|
|
new PPEContext(),
|
|
|
|
|
|
theme);
|
|
|
|
|
|
if (editor != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.AddChild(editor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// put in support pillar size
|
2018-12-31 12:12:05 -08:00
|
|
|
|
var pillarSizeField = new DoubleField(theme);
|
|
|
|
|
|
pillarSizeField.Initialize(0);
|
2019-01-18 15:47:11 -08:00
|
|
|
|
pillarSizeField.DoubleValue = supportGenerator.PillarSize;
|
2018-12-31 12:12:05 -08:00
|
|
|
|
pillarSizeField.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2019-01-18 15:47:11 -08:00
|
|
|
|
supportGenerator.PillarSize = pillarSizeField.DoubleValue;
|
|
|
|
|
|
// in case it was corrected set it back again
|
|
|
|
|
|
if (pillarSizeField.DoubleValue != supportGenerator.PillarSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
pillarSizeField.DoubleValue = supportGenerator.PillarSize;
|
|
|
|
|
|
}
|
2018-12-31 12:12:05 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var pillarRow = PublicPropertyEditor.CreateSettingsRow("Pillar Size".Localize(), "The width and depth of the support pillars".Localize());
|
|
|
|
|
|
pillarRow.AddChild(pillarSizeField.Content);
|
|
|
|
|
|
this.AddChild(pillarRow);
|
|
|
|
|
|
|
|
|
|
|
|
// put in the angle setting
|
|
|
|
|
|
var overHangField = new DoubleField(theme);
|
|
|
|
|
|
overHangField.Initialize(0);
|
2019-01-18 15:47:11 -08:00
|
|
|
|
overHangField.DoubleValue = supportGenerator.MaxOverHangAngle;
|
2018-12-31 12:12:05 -08:00
|
|
|
|
overHangField.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2019-01-18 15:47:11 -08:00
|
|
|
|
supportGenerator.MaxOverHangAngle = overHangField.DoubleValue;
|
|
|
|
|
|
// in case it was corrected set it back again
|
|
|
|
|
|
if (overHangField.DoubleValue != supportGenerator.MaxOverHangAngle)
|
|
|
|
|
|
{
|
|
|
|
|
|
overHangField.DoubleValue = supportGenerator.MaxOverHangAngle;
|
|
|
|
|
|
}
|
2018-12-31 12:12:05 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var overHangRow = PublicPropertyEditor.CreateSettingsRow("Overhang Angle".Localize(), "The angle to generate support for".Localize());
|
|
|
|
|
|
overHangRow.AddChild(overHangField.Content);
|
|
|
|
|
|
this.AddChild(overHangRow);
|
|
|
|
|
|
|
2019-01-23 13:38:47 -08:00
|
|
|
|
// Button Row
|
2019-01-02 18:24:46 -08:00
|
|
|
|
var buttonRow = new FlowLayoutWidget()
|
2018-12-31 12:12:05 -08:00
|
|
|
|
{
|
2019-01-02 18:24:46 -08:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-12-31 12:12:05 -08:00
|
|
|
|
VAnchor = VAnchor.Fit,
|
2019-01-02 18:24:46 -08:00
|
|
|
|
Margin = new BorderDouble(top: 5)
|
2018-12-31 12:12:05 -08:00
|
|
|
|
};
|
2019-01-02 18:24:46 -08:00
|
|
|
|
this.AddChild(buttonRow);
|
|
|
|
|
|
|
|
|
|
|
|
buttonRow.AddChild(new HorizontalSpacer());
|
2018-12-31 12:12:05 -08:00
|
|
|
|
|
|
|
|
|
|
// add 'Remove Auto Supports' button
|
2019-01-02 18:24:46 -08:00
|
|
|
|
var removeButton = theme.CreateDialogButton("Remove".Localize());
|
|
|
|
|
|
removeButton.ToolTipText = "Remove all auto generated supports".Localize();
|
2019-01-18 15:47:11 -08:00
|
|
|
|
removeButton.Click += (s, e) => supportGenerator.RemoveExisting();
|
2019-01-02 18:24:46 -08:00
|
|
|
|
buttonRow.AddChild(removeButton);
|
|
|
|
|
|
|
|
|
|
|
|
// add 'Generate Supports' button
|
|
|
|
|
|
var generateButton = theme.CreateDialogButton("Generate".Localize());
|
|
|
|
|
|
generateButton.ToolTipText = "Find and create supports where needed".Localize();
|
|
|
|
|
|
generateButton.Click += (s, e) => Rebuild();
|
|
|
|
|
|
buttonRow.AddChild(generateButton);
|
|
|
|
|
|
theme.ApplyPrimaryActionStyle(generateButton);
|
2018-12-28 16:00:21 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-22 11:35:47 -08:00
|
|
|
|
public override void OnKeyDown(KeyEventArgs keyEvent)
|
2018-12-31 12:12:05 -08:00
|
|
|
|
{
|
2019-01-22 11:35:47 -08:00
|
|
|
|
if (!keyEvent.Handled)
|
2019-01-04 18:07:12 -08:00
|
|
|
|
{
|
2019-01-22 11:35:47 -08:00
|
|
|
|
switch (keyEvent.KeyCode)
|
2018-12-28 16:00:21 -08:00
|
|
|
|
{
|
2019-01-22 11:35:47 -08:00
|
|
|
|
case Keys.Enter:
|
|
|
|
|
|
Rebuild();
|
|
|
|
|
|
keyEvent.Handled = true;
|
|
|
|
|
|
break;
|
2019-01-18 15:47:11 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-31 12:12:05 -08:00
|
|
|
|
|
2019-01-22 11:35:47 -08:00
|
|
|
|
base.OnKeyDown(keyEvent);
|
2018-12-31 12:12:05 -08:00
|
|
|
|
}
|
2019-01-03 16:05:02 -08:00
|
|
|
|
|
2019-01-22 11:35:47 -08:00
|
|
|
|
private Task Rebuild()
|
2019-01-02 17:50:34 -08:00
|
|
|
|
{
|
2019-01-22 11:35:47 -08:00
|
|
|
|
return ApplicationController.Instance.Tasks.Execute(
|
|
|
|
|
|
"Create Support".Localize(),
|
|
|
|
|
|
null, supportGenerator.Create
|
|
|
|
|
|
);
|
2019-01-12 15:16:27 -08:00
|
|
|
|
}
|
2019-01-02 17:50:34 -08:00
|
|
|
|
}
|
2018-12-28 16:00:21 -08:00
|
|
|
|
}
|