Improving Set Temperature usability

Added Set Temperature test
This commit is contained in:
Lars Brubaker 2020-11-17 12:11:42 -08:00
parent 583dc7f27c
commit 4784508d77
8 changed files with 95 additions and 12 deletions

View file

@ -31,6 +31,9 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using MatterControl.Printing;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
@ -39,7 +42,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class SetTemperatureObject3D : Object3D, IObject3DControlsProvider, IGCodeTransformer
public class SetTemperatureObject3D : Object3D, IObject3DControlsProvider, IGCodeTransformer, IEditorDraw
{
private bool hasBeenReached;
private double accumulatedLayerHeight;
@ -47,8 +50,11 @@ namespace MatterHackers.MatterControl.DesignTools
public SetTemperatureObject3D()
{
Name = "Set Temperature".Localize();
Color = new Color(.11, .98, .26, .2);
Mesh = PlatonicSolids.CreateCube(40, 40, 0.2);
Color = Color.White.WithAlpha(.2);
Mesh = new RoundedRect(-20, -20, 20, 20, 3)
{
ResolutionScale = 10
}.Extrude(.2);
}
public static async Task<SetTemperatureObject3D> Create()
@ -99,10 +105,16 @@ namespace MatterHackers.MatterControl.DesignTools
Invalidate(InvalidateType.DisplayValues);
}
UpdateTexture();
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
return Task.CompletedTask;
}
private double WorldZ => default(Vector3).Transform(this.WorldMatrix()).Z;
private (double temp, double worldZ) displayInfo = (double.MinValue, double.MinValue);
public IEnumerable<string> ProcessCGcode(string lineToWrite, PrinterConfig printer)
{
if (!hasBeenReached
@ -112,9 +124,7 @@ namespace MatterHackers.MatterControl.DesignTools
if (GCodeFile.GetFirstNumberAfter("; LAYER_HEIGHT", lineToWrite, ref layerHeight, out _, stopCheckingString: ":"))
{
accumulatedLayerHeight += layerHeight;
var worldPosition = default(Vector3);
worldPosition = worldPosition.Transform(this.WorldMatrix());
if (accumulatedLayerHeight > worldPosition.Z)
if (accumulatedLayerHeight > WorldZ)
{
hasBeenReached = true;
yield return $"M104 S{Temperature} ; Change Layer Temperature";
@ -128,5 +138,41 @@ namespace MatterHackers.MatterControl.DesignTools
hasBeenReached = false;
accumulatedLayerHeight = 0;
}
public void DrawEditor(Object3DControlsLayer object3DControlLayer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
if (displayInfo.temp == double.MinValue
|| displayInfo.temp != Temperature
|| displayInfo.worldZ != WorldZ)
{
UpdateTexture();
}
}
private void UpdateTexture()
{
Mesh.FaceTextures.Clear();
displayInfo.temp = Temperature;
displayInfo.worldZ = WorldZ;
var theme = AppContext.Theme;
var texture = new ImageBuffer(128, 128, 32);
var graphics2D = texture.NewGraphics2D();
graphics2D.Clear(theme.BackgroundColor);
graphics2D.DrawString($"Height: {displayInfo.worldZ:0.##}",
texture.Width / 2,
texture.Height / 5 * 3,
15,
Agg.Font.Justification.Center,
Agg.Font.Baseline.BoundsCenter,
theme.TextColor);
graphics2D.DrawString($"Temp: {displayInfo.temp:0.##}",
texture.Width / 2,
texture.Height / 5 * 2,
15,
Agg.Font.Justification.Center,
Agg.Font.Baseline.BoundsCenter,
theme.TextColor);
Mesh.PlaceTextureOnFaces(0, texture);
}
}
}

View file

@ -54,6 +54,7 @@ namespace MatterHackers.MatterControl.DesignTools
public TemperatureTowerObject3D()
{
Name = "Temperature Tower".Localize();
Color = Color.White;
if (shape == null)
{
@ -172,7 +173,6 @@ namespace MatterHackers.MatterControl.DesignTools
PointSize = 10,
NameToWrite = $"{temp:0.##}",
Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4) * Matrix4X4.CreateTranslation(0, -4.3, .8),
Color = Color.Transparent
};
text.Rebuild().Wait();
var textBounds = text.GetAxisAlignedBoundingBox();

View file

@ -326,6 +326,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
object3D.Invalidated += RefreshField;
field.Content.Descendants<InternalTextEditWidget>().First().Name = property.DisplayName + " Edit";
field.Content.Closed += (s, e) => object3D.Invalidated -= RefreshField;
rowContainer = CreateSettingsRow(property, field, theme);

View file

@ -78,7 +78,6 @@ namespace MatterHackers.MatterControl.Library
() => "Text".Localize(),
async () => await TextObject3D.Create())
{ DateCreated = new System.DateTime(index++) },
new GeneratorItem(
() => "Cylinder".Localize(),
async () => await CylinderObject3D.Create())

View file

@ -752,11 +752,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (!item.RebuildLocked)
{
item.Mesh.FaceTextures.TryGetValue(0, out FaceTextureData faceTexture);
bool viewOnlyTexture = faceTexture?.image == Object3DControlsLayer.viewOnlyTexture;
bool faceIsTextured = faceTexture?.image != null;
// if not persistable and has view only texture, remove the view only texture if it has it
if (item.WorldPersistable()
&& viewOnlyTexture)
&& faceIsTextured)
{
// make sure it does not have the view only texture
using (item.RebuildLock())
@ -765,7 +765,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
else if (!item.WorldPersistable()
&& !viewOnlyTexture
&& !faceIsTextured
&& !item.RebuildLocked)
{
// add a view only texture if it does not have one

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Before After
Before After

@ -1 +1 @@
Subproject commit c18ecbe08a331cfd860edc7e635cbb82e044fe5b
Subproject commit 6206906c77413f6c5c3b11bc1ffffd8a9e13d619

View file

@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.GuiAutomation;
using MatterHackers.MatterControl.PrinterCommunication;
@ -380,6 +381,42 @@ namespace MatterHackers.MatterControl.Tests.Automation
}, maxTimeToRun: 180);
}
[Test, Category("Emulator")]
public async Task TemperatureTowerWorks()
{
await MatterControlUtilities.RunTest((testRunner) =>
{
using (var emulator = testRunner.LaunchAndConnectToPrinterEmulator())
{
Assert.AreEqual(1, ApplicationController.Instance.ActivePrinters.Count(), "One printer should exist after add");
var printer = testRunner.FirstPrinter();
bool foundTemp = false;
printer.Connection.LineSent += (s, e) =>
{
if (e.StartsWith("M104 S222.2"))
{
foundTemp = true;
}
};
// print a part
testRunner.AddItemToBedplate()
.AddItemToBedplate(partName: "Row Item Set Temperature")
.DragDropByName("MoveInZControl", "MoveInZControl", offsetDrag: new Point2D(0, 0), offsetDrop: new Point2D(0, 10))
.ClickByName("Temperature Edit")
.Type("222.2")
.StartPrint(printer)
.WaitFor(() => printer.Connection.CommunicationState == CommunicationStates.Connected);
Assert.IsTrue(foundTemp);
}
return Task.CompletedTask;
}, maxTimeToRun: 180);
}
[Test, Category("Emulator")]
public async Task RecoveryT1NoProbe()
{