Improving hole button

This commit is contained in:
Lars Brubaker 2022-04-29 14:18:55 -07:00
parent 0d78497331
commit 4a48f2e3e8
9 changed files with 137 additions and 32 deletions

View file

@ -276,12 +276,18 @@ namespace MatterHackers.MatterControl
|| (view3D.Printer != null && view3D.Printer.ViewState.ViewMode == PartViewMode.Model))
{
var scene = view3D.sceneContext.Scene;
if (scene.SelectedItem != null
&& scene.SelectedItem is SelectionGroupObject3D
&& scene.SelectedItem.Children.Count > 1)
if (scene.SelectedItem != null)
{
var group = new GroupHolesAppliedObject3D();
group.WrapSelectedItemAndSelect(scene);
if (keyEvent.Shift)
{
scene.UngroupSelection();
}
else if (scene.SelectedItem is SelectionGroupObject3D
&& scene.SelectedItem.Children.Count > 1)
{
var group = new GroupHolesAppliedObject3D();
group.WrapSelectedItemAndSelect(scene);
}
}
}

View file

@ -1519,6 +1519,7 @@ namespace MatterHackers.MatterControl
return false;
},
Icon = (theme) => StaticData.Instance.LoadIcon("ungroup.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
UiHint = "Shift + G".Localize(),
};
}
}

View file

@ -422,7 +422,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
else if (propertyValue is Color color)
{
var field = new ColorField(theme, object3D.Color, null);
var field = new ColorField(theme, object3D.Color, null, false);
field.Initialize(0);
field.ValueChanged += (s, e) =>
{

View file

@ -33,7 +33,6 @@ using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.ImageProcessing;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
@ -51,7 +50,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public bool IsOpen => popupContent?.ContainsFocus == true;
public ItemColorButton(ThemeConfig theme, Color selectedColor, Action<Action<Color>> getPickedColor)
private static int TransparentAmount => 120;
public ItemColorButton(ThemeConfig theme, Color selectedColor, Action<Action<Color>> getPickedColor, bool transparentCheckbox)
{
this.ToolTipText = "Color".Localize();
var scaledButtonSize = 24 * GuiWidget.DeviceScale;
@ -82,7 +83,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.DynamicPopupContent = () =>
{
popupContent = NewColorSelector(theme, colorButton.BackgroundColor, menuTheme, (color) => colorButton.BackgroundColor = color, getPickedColor);
popupContent = NewColorSelector(theme, colorButton.BackgroundColor, menuTheme, (color) => colorButton.BackgroundColor = color, getPickedColor, transparentCheckbox);
return popupContent;
};
@ -103,8 +104,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Color selectedColor,
ThemeConfig menuTheme,
Action<Color> update,
Action<Action<Color>> getPickedColor)
Action<Action<Color>> getPickedColor,
bool transparentCheckbox)
{
CheckBox transparent = null;
var content = new FlowLayoutWidget(FlowDirection.LeftToRight)
{
Padding = new BorderDouble(5),
@ -124,6 +128,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
picker.SelectedColorChanged += (s, newColor) =>
{
htmlField.SetValue(picker.SelectedColor.Html.Substring(1, 6), false);
if (transparent?.Checked == true)
{
picker.SelectedColor = picker.SelectedColor.WithAlpha(TransparentAmount);
}
else
{
picker.SelectedColor = picker.SelectedColor.WithAlpha(255);
}
update?.Invoke(picker.SelectedColor);
};
@ -154,7 +166,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
else // valid color set
{
picker.SelectedColor = color;
if (transparent?.Checked == true)
{
picker.SelectedColor = color.WithAlpha(TransparentAmount);
}
else
{
picker.SelectedColor = color.WithAlpha(255);
}
}
};
@ -193,6 +212,35 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
picker.SelectedColorChanged += (s, newColor) => colorSwatch.BackgroundColor = picker.SelectedColor;
if (transparentCheckbox)
{
transparent = new CheckBox("Transparent".Localize())
{
TextColor = theme.TextColor,
Margin = new BorderDouble(15, 0, 0, 3),
HAnchor = HAnchor.Fit | HAnchor.Left,
VAnchor = VAnchor.Absolute,
ToolTipText = "Set the rendering for the object to be transparent".Localize(),
Checked = selectedColor.Alpha0To255 < 255,
};
rightContent.AddChild(transparent);
transparent.CheckedStateChanged += (s, e) =>
{
if (transparent.Checked)
{
picker.SelectedColor = picker.SelectedColor.WithAlpha(TransparentAmount);
}
else
{
picker.SelectedColor = picker.SelectedColor.WithAlpha(255);
}
update?.Invoke(picker.SelectedColor);
};
}
var resetButton = rightContent.AddChild(new TextIconButton("Clear".Localize(), StaticData.Instance.LoadIcon("transparent_grid.png", 16, 16), theme)
{
Margin = new BorderDouble(0, 0, 0, 3),
@ -222,7 +270,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
getPickedColor((color) =>
{
update?.Invoke(color);
picker.SelectedColor = color;
if (transparent?.Checked == true)
{
picker.SelectedColor = color.WithAlpha(TransparentAmount);
}
else
{
picker.SelectedColor = color;
}
});
};

View file

@ -69,7 +69,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var scaledButtonSize = 24 * GuiWidget.DeviceScale;
GuiWidget colorButton;
buttonView.AddChild(colorButton = new ItemColorButton(theme, MaterialRendering.Color(printer, extruderIndex, theme.BorderColor), null)
buttonView.AddChild(colorButton = new ItemColorButton(theme, MaterialRendering.Color(printer, extruderIndex, theme.BorderColor), null, false)
{
Width = scaledButtonSize,
Height = scaledButtonSize,

View file

@ -289,7 +289,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (!(selectedItem.GetType().GetCustomAttributes(typeof(HideMeterialAndColor), true).FirstOrDefault() is HideMeterialAndColor))
{
// put in a color edit field
var colorField = new ColorField(theme, selectedItem.Color, GetNextSelectionColor);
var colorField = new ColorField(theme, selectedItem.Color, GetNextSelectionColor, true);
colorField.Initialize(0);
colorField.ValueChanged += (s, e) =>
{
@ -299,7 +299,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
};
colorField.Content.MouseDown += (s, e) =>
var colorButton = colorField.Content.Descendants<ColorButton>().FirstOrDefault();
colorButton.Parent.MouseDown += (s, e) =>
{
// make sure the render mode is set to shaded or outline
if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Shaded
@ -308,32 +309,57 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// make sure the render mode is set to outline
sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Outlines;
}
var currentOutputType = selectedItem.WorldOutputType();
if (currentOutputType != PrintOutputTypes.Solid || currentOutputType != PrintOutputTypes.Default)
{
undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color));
}
};
editorPanel.AddChild(new SettingsRow("Color".Localize(), null, colorField.Content, theme)
var colorRow = new SettingsRow("Result".Localize(), null, colorField.Content, theme)
{
// Special top border style for first item in editor
Border = new BorderDouble(0, 1)
});
};
editorPanel.AddChild(colorRow);
// put in a hole edit field
var holeField = new ToggleboxField(theme);
holeField.Initialize(0);
holeField.Checked = selectedItem.WorldOutputType() == PrintOutputTypes.Hole;
holeField.ValueChanged += (s, e) =>
// put in a hole button
var scaledButtonSize = 24 * GuiWidget.DeviceScale;
var holeButton = new ColorButton(Color.DarkGray)
{
if (selectedItem.OutputType == PrintOutputTypes.Hole)
{
undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color));
}
else
Margin = new BorderDouble(5, 0, 11, 0),
Width = scaledButtonSize,
Height = scaledButtonSize,
BackgroundRadius = scaledButtonSize / 2,
BackgroundOutlineWidth = 1,
VAnchor = VAnchor.Center,
DisabledColor = theme.MinimalShade,
BorderColor = theme.TextColor,
ToolTipText = "Convert to Hole".Localize(),
};
var buttonRow = colorButton.Parents<FlowLayoutWidget>().FirstOrDefault();
buttonRow.AddChild(new TextWidget("Solid".Localize(), pointSize: theme.FontSize10, textColor: theme.TextColor)
{
VAnchor = VAnchor.Center,
Margin = new BorderDouble(3, 0),
}, 0);
buttonRow.AddChild(holeButton, 0);
buttonRow.AddChild(new TextWidget("Hole".Localize(), pointSize: theme.FontSize10, textColor: theme.TextColor)
{
VAnchor = VAnchor.Center,
Margin = new BorderDouble(3, 0),
}, 0);
holeButton.Click += (s, e) =>
{
if (selectedItem.WorldOutputType() != PrintOutputTypes.Hole)
{
undoBuffer.AddAndDo(new MakeHole(selectedItem));
}
};
editorPanel.AddChild(new SettingsRow("Hole".Localize(), null, holeField.Content, theme));
// put in a material edit field
var materialField = new MaterialIndexField(sceneContext.Printer, theme, selectedItem.MaterialIndex);
materialField.Initialize(0);

View file

@ -704,7 +704,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
break;
case SliceSettingData.DataEditTypes.COLOR:
uiField = new ColorField(theme, Color.Transparent, null);
uiField = new ColorField(theme, Color.Transparent, null, false);
break;
case SliceSettingData.DataEditTypes.POSITIVE_DOUBLE:

View file

@ -37,12 +37,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public class ColorField : UIField
{
private ItemColorButton colorWidget;
private bool transparentCheckbox;
private Action<Action<Color>> getPickedColor;
private ThemeConfig theme;
private Color initialColor;
public ColorField(ThemeConfig theme, Color initialColor, Action<Action<Color>> getPickedColor)
public ColorField(ThemeConfig theme, Color initialColor, Action<Action<Color>> getPickedColor, bool transparentCheckbox)
{
this.transparentCheckbox = transparentCheckbox;
this.getPickedColor = getPickedColor;
this.theme = theme;
this.initialColor = initialColor;
@ -58,7 +60,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
var container = new FlowLayoutWidget();
colorWidget = new ItemColorButton(theme, initialColor, getPickedColor);
colorWidget = new ItemColorButton(theme, initialColor, getPickedColor, transparentCheckbox);
colorWidget.ColorChanged += (s, e) =>
{
this.SetValue(Color.Html, true);

View file

@ -1018,6 +1018,9 @@ Translated:Controls the speed of printer moves
English:Convert to Fuzzy Region
Translated:Convert to Fuzzy Region
English:Convert to Hole
Translated:Convert to Hole
English:Convert to Support
Translated:Convert to Support
@ -4081,6 +4084,9 @@ Translated:Restore Settings...
English:Restoring
Translated:Restoring
English:Result
Translated:Result
English:Resume
Translated:Resume
@ -4420,6 +4426,9 @@ Translated:Set Temperature
English:Set the information below to configure your printer. After completing this step, you can customize additional settings under the 'Settings' and 'Printer' options for this printer.
Translated:Set the information below to configure your printer. After completing this step, you can customize additional settings under the 'Settings' and 'Printer' options for this printer.
English:Set the rendering for the object to be transparent
Translated:Set the rendering for the object to be transparent
English:Sets MatterControl to attempt to connect to a printer over the network. (You must disconnect and reconnect for this to take effect)
Translated:Sets MatterControl to attempt to connect to a printer over the network. (You must disconnect and reconnect for this to take effect)
@ -4492,6 +4501,9 @@ Translated:Share with someone
English:Shared with Me
Translated:Shared with Me
English:Shift + G
Translated:Shift + G
English:Shop
Translated:Shop
@ -4660,6 +4672,9 @@ Translated:Snapping Turned Off
English:Software License Agreement
Translated:Software License Agreement
English:Solid
Translated:Solid
English:Solid Infill
Translated:Solid Infill