Collapse PartPreviewWidget into View3DWidget
This commit is contained in:
parent
a1fade3716
commit
1b781d5015
5 changed files with 127 additions and 192 deletions
|
|
@ -40,6 +40,8 @@ namespace MatterHackers.MatterControl
|
||||||
|
|
||||||
public class ThemeConfig
|
public class ThemeConfig
|
||||||
{
|
{
|
||||||
|
protected static readonly int DefaultScrollBarWidth = 120;
|
||||||
|
|
||||||
private static ImageBuffer restoreNormal;
|
private static ImageBuffer restoreNormal;
|
||||||
private static ImageBuffer restoreHover;
|
private static ImageBuffer restoreHover;
|
||||||
private static ImageBuffer restorePressed;
|
private static ImageBuffer restorePressed;
|
||||||
|
|
@ -365,5 +367,35 @@ namespace MatterHackers.MatterControl
|
||||||
Margin = new BorderDouble(0, 0, 5, 0)
|
Margin = new BorderDouble(0, 0, 5, 0)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SolidSlider InsertUiForSlider(GuiWidget wordOptionContainer, string header, double min = 0, double max = .5)
|
||||||
|
{
|
||||||
|
double scrollBarWidth = 10;
|
||||||
|
if (UserSettings.Instance.IsTouchScreen)
|
||||||
|
{
|
||||||
|
scrollBarWidth = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextWidget spacingText = new TextWidget(header, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
||||||
|
{
|
||||||
|
Margin = new BorderDouble(10, 3, 3, 5),
|
||||||
|
HAnchor = HAnchor.ParentLeft
|
||||||
|
};
|
||||||
|
wordOptionContainer.AddChild(spacingText);
|
||||||
|
|
||||||
|
SolidSlider namedSlider = new SolidSlider(new Vector2(), scrollBarWidth, 0, 1)
|
||||||
|
{
|
||||||
|
TotalWidthInPixels = DefaultScrollBarWidth,
|
||||||
|
Minimum = min,
|
||||||
|
Maximum = max,
|
||||||
|
Margin = new BorderDouble(3, 5, 3, 3),
|
||||||
|
HAnchor = HAnchor.ParentCenter,
|
||||||
|
};
|
||||||
|
namedSlider.View.BackgroundColor = new RGBA_Bytes();
|
||||||
|
|
||||||
|
wordOptionContainer.AddChild(namedSlider);
|
||||||
|
|
||||||
|
return namedSlider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +244,6 @@
|
||||||
<Compile Include="PartPreviewWindow\SelectedObjectPanel.cs" />
|
<Compile Include="PartPreviewWindow\SelectedObjectPanel.cs" />
|
||||||
<Compile Include="PartPreviewWindow\ViewControls3D.cs" />
|
<Compile Include="PartPreviewWindow\ViewControls3D.cs" />
|
||||||
<Compile Include="PartPreviewWindow\ViewControlsToggle.cs" />
|
<Compile Include="PartPreviewWindow\ViewControlsToggle.cs" />
|
||||||
<Compile Include="PartPreviewWindow\BaseClasses\PartPreview3DWidget.cs" />
|
|
||||||
<Compile Include="PartPreviewWindow\GCode2DWidget.cs" />
|
<Compile Include="PartPreviewWindow\GCode2DWidget.cs" />
|
||||||
<Compile Include="CustomWidgets\DisableableWidget.cs" />
|
<Compile Include="CustomWidgets\DisableableWidget.cs" />
|
||||||
<Compile Include="CustomWidgets\ExportPrintItemWindow.cs" />
|
<Compile Include="CustomWidgets\ExportPrintItemWindow.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,188 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 2014, Lars Brubaker
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using MatterHackers.Agg;
|
|
||||||
using MatterHackers.Agg.Image;
|
|
||||||
using MatterHackers.Agg.PlatformAbstract;
|
|
||||||
using MatterHackers.Agg.UI;
|
|
||||||
using MatterHackers.DataConverters3D;
|
|
||||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
||||||
using MatterHackers.MeshVisualizer;
|
|
||||||
using MatterHackers.PolygonMesh;
|
|
||||||
using MatterHackers.RayTracer;
|
|
||||||
using MatterHackers.VectorMath;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
||||||
{
|
|
||||||
public abstract class PartPreview3DWidget : GuiWidget
|
|
||||||
{
|
|
||||||
protected static readonly int DefaultScrollBarWidth = 120;
|
|
||||||
|
|
||||||
protected bool autoRotating = false;
|
|
||||||
protected bool allowAutoRotate = false;
|
|
||||||
|
|
||||||
public MeshViewerWidget meshViewerWidget;
|
|
||||||
|
|
||||||
private EventHandler unregisterEvents;
|
|
||||||
|
|
||||||
// Proxy to MeshViewerWidget
|
|
||||||
public InteractiveScene Scene => meshViewerWidget.Scene;
|
|
||||||
|
|
||||||
protected ViewControls3D viewControls3D { get; }
|
|
||||||
|
|
||||||
private bool needToRecreateBed = false;
|
|
||||||
|
|
||||||
public PartPreview3DWidget(ViewControls3D viewControls3D)
|
|
||||||
{
|
|
||||||
this.viewControls3D = viewControls3D;
|
|
||||||
|
|
||||||
ActiveSliceSettings.SettingChanged.RegisterEvent(CheckSettingChanged, ref unregisterEvents);
|
|
||||||
ApplicationController.Instance.AdvancedControlsPanelReloading.RegisterEvent(CheckSettingChanged, ref unregisterEvents);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MeshSelectInfo CurrentSelectInfo { get; private set; } = new MeshSelectInfo();
|
|
||||||
|
|
||||||
protected IObject3D FindHitObject3D(Vector2 screenPosition, ref IntersectInfo intersectionInfo)
|
|
||||||
{
|
|
||||||
Vector2 meshViewerWidgetScreenPosition = meshViewerWidget.TransformFromParentSpace(this, screenPosition);
|
|
||||||
Ray ray = meshViewerWidget.World.GetRayForLocalBounds(meshViewerWidgetScreenPosition);
|
|
||||||
|
|
||||||
intersectionInfo = Scene.TraceData().GetClosestIntersection(ray);
|
|
||||||
if (intersectionInfo != null)
|
|
||||||
{
|
|
||||||
foreach (Object3D object3D in Scene.Children)
|
|
||||||
{
|
|
||||||
if (object3D.TraceData().Contains(intersectionInfo.closestHitObject))
|
|
||||||
{
|
|
||||||
CurrentSelectInfo.PlaneDownHitPos = intersectionInfo.HitPosition;
|
|
||||||
CurrentSelectInfo.LastMoveDelta = new Vector3();
|
|
||||||
return object3D;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckSettingChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
StringEventArgs stringEvent = e as StringEventArgs;
|
|
||||||
if (stringEvent != null)
|
|
||||||
{
|
|
||||||
if (stringEvent.Data == SettingsKey.bed_size
|
|
||||||
|| stringEvent.Data == SettingsKey.print_center
|
|
||||||
|| stringEvent.Data == SettingsKey.build_height
|
|
||||||
|| stringEvent.Data == SettingsKey.bed_shape)
|
|
||||||
{
|
|
||||||
needToRecreateBed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RecreateBed()
|
|
||||||
{
|
|
||||||
double buildHeight = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.build_height);
|
|
||||||
|
|
||||||
UiThread.RunOnIdle((Action)(() =>
|
|
||||||
{
|
|
||||||
meshViewerWidget.CreatePrintBed(
|
|
||||||
new Vector3(ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.bed_size), buildHeight),
|
|
||||||
ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.print_center),
|
|
||||||
ActiveSliceSettings.Instance.GetValue<BedShape>(SettingsKey.bed_shape));
|
|
||||||
PutOemImageOnBed();
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnDraw(Graphics2D graphics2D)
|
|
||||||
{
|
|
||||||
if (needToRecreateBed)
|
|
||||||
{
|
|
||||||
needToRecreateBed = false;
|
|
||||||
RecreateBed();
|
|
||||||
}
|
|
||||||
base.OnDraw(graphics2D);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImageBuffer wattermarkImage = null;
|
|
||||||
protected void PutOemImageOnBed()
|
|
||||||
{
|
|
||||||
// this is to add an image to the bed
|
|
||||||
string imagePathAndFile = Path.Combine("OEMSettings", "bedimage.png");
|
|
||||||
if (StaticData.Instance.FileExists(imagePathAndFile))
|
|
||||||
{
|
|
||||||
if (wattermarkImage == null)
|
|
||||||
{
|
|
||||||
wattermarkImage = StaticData.Instance.LoadImage(imagePathAndFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageBuffer bedImage = MeshViewerWidget.BedImage;
|
|
||||||
Graphics2D bedGraphics = bedImage.NewGraphics2D();
|
|
||||||
bedGraphics.Render(wattermarkImage, new Vector2((bedImage.Width - wattermarkImage.Width) / 2, (bedImage.Height - wattermarkImage.Height) / 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnClosed(ClosedEventArgs e)
|
|
||||||
{
|
|
||||||
unregisterEvents?.Invoke(this, null);
|
|
||||||
base.OnClosed(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SolidSlider InsertUiForSlider(GuiWidget wordOptionContainer, string header, double min = 0, double max = .5)
|
|
||||||
{
|
|
||||||
double scrollBarWidth = 10;
|
|
||||||
if (UserSettings.Instance.IsTouchScreen)
|
|
||||||
{
|
|
||||||
scrollBarWidth = 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextWidget spacingText = new TextWidget(header, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
|
||||||
{
|
|
||||||
Margin = new BorderDouble(10, 3, 3, 5),
|
|
||||||
HAnchor = HAnchor.ParentLeft
|
|
||||||
};
|
|
||||||
wordOptionContainer.AddChild(spacingText);
|
|
||||||
|
|
||||||
SolidSlider namedSlider = new SolidSlider(new Vector2(), scrollBarWidth, 0, 1)
|
|
||||||
{
|
|
||||||
TotalWidthInPixels = DefaultScrollBarWidth,
|
|
||||||
Minimum = min,
|
|
||||||
Maximum = max,
|
|
||||||
Margin = new BorderDouble(3, 5, 3, 3),
|
|
||||||
HAnchor = HAnchor.ParentCenter,
|
|
||||||
};
|
|
||||||
namedSlider.View.BackgroundColor = new RGBA_Bytes();
|
|
||||||
|
|
||||||
wordOptionContainer.AddChild(namedSlider);
|
|
||||||
|
|
||||||
return namedSlider;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -168,7 +168,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class View3DWidget : PartPreview3DWidget
|
public class View3DWidget : GuiWidget
|
||||||
{
|
{
|
||||||
private bool DoBooleanTest = false;
|
private bool DoBooleanTest = false;
|
||||||
private bool deferEditorTillMouseUp = false;
|
private bool deferEditorTillMouseUp = false;
|
||||||
|
|
@ -235,13 +235,16 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
private ThemeConfig theme;
|
private ThemeConfig theme;
|
||||||
|
|
||||||
public View3DWidget(PrintItemWrapper printItemWrapper, Vector3 viewerVolume, Vector2 bedCenter, BedShape bedShape, WindowMode windowType, AutoRotate autoRotate, ViewControls3D viewControls3D, ThemeConfig theme, OpenMode openMode = OpenMode.Viewing)
|
public View3DWidget(PrintItemWrapper printItemWrapper, Vector3 viewerVolume, Vector2 bedCenter, BedShape bedShape, WindowMode windowType, AutoRotate autoRotate, ViewControls3D viewControls3D, ThemeConfig theme, OpenMode openMode = OpenMode.Viewing)
|
||||||
: base(viewControls3D)
|
|
||||||
{
|
{
|
||||||
|
this.viewControls3D = viewControls3D;
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
this.openMode = openMode;
|
this.openMode = openMode;
|
||||||
allowAutoRotate = (autoRotate == AutoRotate.Enabled);
|
allowAutoRotate = (autoRotate == AutoRotate.Enabled);
|
||||||
meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape);
|
meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape);
|
||||||
this.printItemWrapper = printItemWrapper;
|
this.printItemWrapper = printItemWrapper;
|
||||||
|
|
||||||
|
ActiveSliceSettings.SettingChanged.RegisterEvent(CheckSettingChanged, ref unregisterEvents);
|
||||||
|
ApplicationController.Instance.AdvancedControlsPanelReloading.RegisterEvent(CheckSettingChanged, ref unregisterEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
|
|
@ -984,6 +987,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
|
|
||||||
public override void OnDraw(Graphics2D graphics2D)
|
public override void OnDraw(Graphics2D graphics2D)
|
||||||
{
|
{
|
||||||
|
if (needToRecreateBed)
|
||||||
|
{
|
||||||
|
needToRecreateBed = false;
|
||||||
|
RecreateBed();
|
||||||
|
}
|
||||||
|
|
||||||
if (Scene.HasSelection)
|
if (Scene.HasSelection)
|
||||||
{
|
{
|
||||||
var selectedItem = Scene.SelectedItem;
|
var selectedItem = Scene.SelectedItem;
|
||||||
|
|
@ -2521,6 +2530,89 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected bool autoRotating = false;
|
||||||
|
protected bool allowAutoRotate = false;
|
||||||
|
|
||||||
|
public MeshViewerWidget meshViewerWidget;
|
||||||
|
|
||||||
|
// Proxy to MeshViewerWidget
|
||||||
|
public InteractiveScene Scene => meshViewerWidget.Scene;
|
||||||
|
|
||||||
|
protected ViewControls3D viewControls3D { get; }
|
||||||
|
|
||||||
|
private bool needToRecreateBed = false;
|
||||||
|
|
||||||
|
public MeshSelectInfo CurrentSelectInfo { get; private set; } = new MeshSelectInfo();
|
||||||
|
|
||||||
|
protected IObject3D FindHitObject3D(Vector2 screenPosition, ref IntersectInfo intersectionInfo)
|
||||||
|
{
|
||||||
|
Vector2 meshViewerWidgetScreenPosition = meshViewerWidget.TransformFromParentSpace(this, screenPosition);
|
||||||
|
Ray ray = meshViewerWidget.World.GetRayForLocalBounds(meshViewerWidgetScreenPosition);
|
||||||
|
|
||||||
|
intersectionInfo = Scene.TraceData().GetClosestIntersection(ray);
|
||||||
|
if (intersectionInfo != null)
|
||||||
|
{
|
||||||
|
foreach (Object3D object3D in Scene.Children)
|
||||||
|
{
|
||||||
|
if (object3D.TraceData().Contains(intersectionInfo.closestHitObject))
|
||||||
|
{
|
||||||
|
CurrentSelectInfo.PlaneDownHitPos = intersectionInfo.HitPosition;
|
||||||
|
CurrentSelectInfo.LastMoveDelta = new Vector3();
|
||||||
|
return object3D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckSettingChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
StringEventArgs stringEvent = e as StringEventArgs;
|
||||||
|
if (stringEvent != null)
|
||||||
|
{
|
||||||
|
if (stringEvent.Data == SettingsKey.bed_size
|
||||||
|
|| stringEvent.Data == SettingsKey.print_center
|
||||||
|
|| stringEvent.Data == SettingsKey.build_height
|
||||||
|
|| stringEvent.Data == SettingsKey.bed_shape)
|
||||||
|
{
|
||||||
|
needToRecreateBed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RecreateBed()
|
||||||
|
{
|
||||||
|
double buildHeight = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.build_height);
|
||||||
|
|
||||||
|
UiThread.RunOnIdle((Action)(() =>
|
||||||
|
{
|
||||||
|
meshViewerWidget.CreatePrintBed(
|
||||||
|
new Vector3(ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.bed_size), buildHeight),
|
||||||
|
ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.print_center),
|
||||||
|
ActiveSliceSettings.Instance.GetValue<BedShape>(SettingsKey.bed_shape));
|
||||||
|
PutOemImageOnBed();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImageBuffer wattermarkImage = null;
|
||||||
|
protected void PutOemImageOnBed()
|
||||||
|
{
|
||||||
|
// this is to add an image to the bed
|
||||||
|
string imagePathAndFile = Path.Combine("OEMSettings", "bedimage.png");
|
||||||
|
if (StaticData.Instance.FileExists(imagePathAndFile))
|
||||||
|
{
|
||||||
|
if (wattermarkImage == null)
|
||||||
|
{
|
||||||
|
wattermarkImage = StaticData.Instance.LoadImage(imagePathAndFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageBuffer bedImage = MeshViewerWidget.BedImage;
|
||||||
|
Graphics2D bedGraphics = bedImage.NewGraphics2D();
|
||||||
|
bedGraphics.Render(wattermarkImage, new Vector2((bedImage.Width - wattermarkImage.Width) / 2, (bedImage.Height - wattermarkImage.Height) / 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static MenuItem AddCheckbox(string text, string itemValue, bool itemChecked, BorderDouble padding, EventHandler eventHandler)
|
private static MenuItem AddCheckbox(string text, string itemValue, bool itemChecked, BorderDouble padding, EventHandler eventHandler)
|
||||||
{
|
{
|
||||||
var checkbox = new CheckBox(text)
|
var checkbox = new CheckBox(text)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ namespace MatterHackers.MatterControl.Plugins.TextCreator
|
||||||
textToAddWidget.ActualTextEditWidget.EnterPressed += (s, e) => RebuildText(textToAddWidget.Text);
|
textToAddWidget.ActualTextEditWidget.EnterPressed += (s, e) => RebuildText(textToAddWidget.Text);
|
||||||
tabContainer.AddChild(textToAddWidget);
|
tabContainer.AddChild(textToAddWidget);
|
||||||
|
|
||||||
spacingScrollBar = PartPreview3DWidget.InsertUiForSlider(tabContainer, "Spacing:".Localize(), .5, 1);
|
spacingScrollBar = theme.InsertUiForSlider(tabContainer, "Spacing:".Localize(), .5, 1);
|
||||||
spacingScrollBar.ValueChanged += (sender, e) =>
|
spacingScrollBar.ValueChanged += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (injectedItem != null)
|
if (injectedItem != null)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue