mattercontrol/MatterControlLib/PartPreviewWindow/GenerateSupportPanel.cs

149 lines
5.2 KiB
C#
Raw Normal View History

/*
2019-01-02 18:30:21 -08:00
Copyright (c) 2019, Lars Brubaker, John Lewin
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;
using System.Threading.Tasks;
using MatterHackers.Agg;
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;
using MatterHackers.PolygonMesh;
using MatterHackers.RayTracer;
using MatterHackers.VectorMath;
2018-12-31 09:12:49 -08:00
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2019-01-02 18:30:21 -08:00
public class GenerateSupportPanel : FlowLayoutWidget
{
private SupportGenerator supportGenerator;
2018-12-31 12:12:05 -08:00
private ThemeConfig theme;
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)
{
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;
// put in support pillar size
2018-12-31 12:12:05 -08:00
// support pillar resolution
var pillarSizeField = new DoubleField(theme);
pillarSizeField.Initialize(0);
pillarSizeField.DoubleValue = supportGenerator.PillarSize;
2018-12-31 12:12:05 -08:00
pillarSizeField.ValueChanged += (s, e) =>
{
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);
overHangField.DoubleValue = supportGenerator.MaxOverHangAngle;
2018-12-31 12:12:05 -08:00
overHangField.ValueChanged += (s, e) =>
{
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-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();
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);
}
public override void OnKeyDown(KeyEventArgs keyEvent)
2018-12-31 12:12:05 -08:00
{
if (!keyEvent.Handled)
2019-01-04 18:07:12 -08:00
{
switch (keyEvent.KeyCode)
{
case Keys.Enter:
Rebuild();
keyEvent.Handled = true;
break;
}
}
2018-12-31 12:12:05 -08:00
base.OnKeyDown(keyEvent);
2018-12-31 12:12:05 -08:00
}
2019-01-03 16:05:02 -08:00
private Task Rebuild()
{
return ApplicationController.Instance.Tasks.Execute(
"Create Support".Localize(),
null, supportGenerator.Create
);
2019-01-12 15:16:27 -08:00
}
}
}