Make sure when we create json it is valid and does not have selections in it

This commit is contained in:
Lars Brubaker 2022-02-04 14:51:41 -08:00
parent 11ff49bb7e
commit f83bdbeb7d
20 changed files with 768 additions and 646 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2018, Lars Brubaker, John Lewin
Copyright (c) 2022, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -203,12 +203,12 @@ namespace MatterHackers.MatterControl
}
}
public InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd)
public InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd, bool addUndoCheckPoint = true)
{
return this.AddToPlate(itemsToAdd, (this.Printer != null) ? this.Printer.Bed.BedCenter : Vector2.Zero, true);
return this.AddToPlate(itemsToAdd, (this.Printer != null) ? this.Printer.Bed.BedCenter : Vector2.Zero, true, addUndoCheckPoint);
}
public InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd, Vector2 initialPosition, bool moveToOpenPosition)
public InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd, Vector2 initialPosition, bool moveToOpenPosition, bool addUndoCheckPoint = true)
{
if (this.Printer != null
&& this.Printer.ViewState.ViewMode != PartViewMode.Model)
@ -234,13 +234,14 @@ namespace MatterHackers.MatterControl
{
PlatingHelper.MoveToOpenPositionRelativeGroup(item, itemsToAvoid);
}
}));
},
addUndoCheckPoint: addUndoCheckPoint));
});
return insertionGroup;
}
public async void AddToPlate(string[] filesToLoadIncludingZips)
public async void AddToPlate(string[] filesToLoadIncludingZips, bool addUndoCheckPoint = true)
{
if (filesToLoadIncludingZips?.Any() == true)
{
@ -296,7 +297,7 @@ namespace MatterHackers.MatterControl
});
var itemCache = new Dictionary<string, IObject3D>();
this.AddToPlate(filePaths.Select(f => new FileSystemFileItem(f)));
this.AddToPlate(filePaths.Select(f => new FileSystemFileItem(f)), addUndoCheckPoint);
}
}

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2019, Lars Brubaker, John Lewin
Copyright (c) 2022, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -62,13 +62,13 @@ namespace MatterHackers.MatterControl
event EventHandler SceneLoaded;
InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd);
InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd, bool addUndoCheckPoint = true);
InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd, Vector2 initialPosition, bool moveToOpenPosition);
InsertionGroupObject3D AddToPlate(IEnumerable<ILibraryItem> itemsToAdd, Vector2 initialPosition, bool moveToOpenPosition, bool addUndoCheckPoint = true);
List<BoolOption> GetBaseViewOptions();
void AddToPlate(string[] filesToLoadIncludingZips);
void AddToPlate(string[] filesToLoadIncludingZips, bool addUndoCheckPoint = true);
void ClearPlate();

View file

@ -256,7 +256,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
// *******************************************************************************************************************************
// SHA1 value is based on UTF8 encoded file contents
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(object3D.ToJson())))
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(object3D.ToJson().Result)))
{
return HashGenerator.ComputeSHA1(memoryStream);
}

View file

@ -89,7 +89,10 @@ namespace MatterHackers.MatterControl.Library
if (fileItem.FilePath.Contains(ApplicationDataStorage.Instance.ApplicationLibraryDataPath))
{
// save using the normal uncompressed mcx file
base.Save(item, content);
// Serialize the scene to disk using a modified Json.net pipeline with custom ContractResolvers and JsonConverters
File.WriteAllText(fileItem.FilePath, content.ToJson().Result);
this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem));
}
else
{
@ -103,6 +106,27 @@ namespace MatterHackers.MatterControl.Library
Status = "Saving Asset".Localize()
};
var directory = Path.GetDirectoryName(fileItem.FilePath);
var filename = Path.GetFileNameWithoutExtension(fileItem.FilePath);
var backupName = Path.Combine(directory, Path.ChangeExtension(filename + "_bak", ".mcx"));
try
{
if (File.Exists(backupName))
{
File.Delete(backupName);
}
// rename any existing file
if (File.Exists(fileItem.FilePath))
{
File.Move(fileItem.FilePath, backupName);
}
}
catch
{
}
// make sure we have all the mesh items in the cache for saving to the archive
await content.PersistAssets((percentComplete, text) =>
{
@ -110,16 +134,6 @@ namespace MatterHackers.MatterControl.Library
reporter.Report(status);
}, true);
var backupName = "";
// rename any existing file
if (File.Exists(fileItem.FilePath))
{
var directory = Path.GetDirectoryName(fileItem.FilePath);
var filename = Path.GetFileNameWithoutExtension(fileItem.FilePath);
backupName = Path.Combine(directory, Path.ChangeExtension(filename + "_bak", ".mcx"));
File.Move(fileItem.FilePath, backupName);
}
var persistableItems = content.GetPersistable(true);
var persistCount = persistableItems.Count();
var savedCount = 0;
@ -147,9 +161,13 @@ namespace MatterHackers.MatterControl.Library
reporter.Report(status);
}
using (var writer = new StreamWriter(zip.CreateEntry("scene.mcx").Open()))
var sceneEntry = zip.CreateEntry("scene.mcx");
using (var sceneStream = sceneEntry.Open())
{
writer.Write(content.ToJson());
using (var writer = new StreamWriter(sceneStream))
{
writer.Write(await content.ToJson());
}
}
}
}
@ -158,10 +176,14 @@ namespace MatterHackers.MatterControl.Library
this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem));
// remove the existing file after a successfull save
if (!string.IsNullOrEmpty(backupName))
try
{
File.Delete(backupName);
if (File.Exists(backupName))
{
File.Delete(backupName);
}
}
catch { }
});
}
}

View file

@ -87,7 +87,7 @@ namespace MatterHackers.MatterControl.Library
var filename = ApplicationController.Instance.SanitizeFileName($"{name} - {now}.mcx");
string mcxPath = Path.Combine(this.FullPath, filename);
File.WriteAllText(mcxPath, new Object3D().ToJson());
File.WriteAllText(mcxPath, new Object3D().ToJson().Result);
return new FileSystemFileItem(mcxPath);
}

View file

@ -34,6 +34,7 @@ using System.Linq;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrintQueue;
@ -71,6 +72,18 @@ namespace MatterHackers.MatterControl.Library
this.ReloadContent();
}
public override void Save(ILibraryItem item, IObject3D content)
{
if (item is FileSystemFileItem fileItem)
{
// save using the normal uncompressed mcx file
// Serialize the scene to disk using a modified Json.net pipeline with custom ContractResolvers and JsonConverters
File.WriteAllText(fileItem.FilePath, content.ToJson().Result);
this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem));
}
}
public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)
{
#if DEBUG

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrintQueue;
@ -189,6 +190,18 @@ namespace MatterHackers.MatterControl.Library
this.ReloadContent();
}
public override void Save(ILibraryItem item, IObject3D content)
{
if (item is FileSystemFileItem fileItem)
{
// save using the normal uncompressed mcx file
// Serialize the scene to disk using a modified Json.net pipeline with custom ContractResolvers and JsonConverters
File.WriteAllText(fileItem.FilePath, content.ToJson().Result);
this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem));
}
}
public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)
{
#if DEBUG

View file

@ -49,16 +49,7 @@ namespace MatterHackers.MatterControl.Library
public abstract void Remove(IEnumerable<ILibraryItem> items);
public virtual void Save(ILibraryItem item, IObject3D content)
{
if (item is FileSystemFileItem fileItem)
{
// Serialize the scene to disk using a modified Json.net pipeline with custom ContractResolvers and JsonConverters
File.WriteAllText(fileItem.FilePath, content.ToJson());
this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem));
}
}
public abstract void Save(ILibraryItem item, IObject3D content);
public virtual void Move(IEnumerable<ILibraryItem> items, ILibraryWritableContainer sourceContainer)
{

View file

@ -62,7 +62,8 @@ namespace MatterHackers.MatterControl.Library
InteractiveScene scene,
Vector2 newItemOffset,
Action<IObject3D, IEnumerable<IObject3D>> layoutParts,
bool trackSourceFiles = false)
bool trackSourceFiles = false,
bool addUndoCheckPoint = true)
{
if (items == null)
{
@ -143,7 +144,7 @@ namespace MatterHackers.MatterControl.Library
}
this.Children.Remove(placeholderItem);
this.Collapse();
this.Collapse(addUndoCheckPoint);
this.Invalidate(InvalidateType.Children);
});
@ -152,7 +153,7 @@ namespace MatterHackers.MatterControl.Library
/// <summary>
/// Collapse the InsertionGroup into the scene
/// </summary>
public void Collapse()
private void Collapse(bool addUndoCheckPoint)
{
// Drag operation has finished, we need to perform the collapse
var loadedItems = this.Children;
@ -193,7 +194,14 @@ namespace MatterHackers.MatterControl.Library
}
}
view3DWidget.Scene.UndoBuffer.AddAndDo(new InsertCommand(view3DWidget.Scene, loadedItems));
if (addUndoCheckPoint)
{
view3DWidget.Scene.UndoBuffer.AddAndDo(new InsertCommand(view3DWidget.Scene, loadedItems));
}
else
{
new InsertCommand(view3DWidget.Scene, loadedItems).Do();
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
Copyright (c) 2022, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -67,13 +67,22 @@ namespace MatterHackers.MatterControl
};
itemNameWidget.ActualTextEditWidget.EnterPressed += (s, e) =>
{
if (librarySelectorWidget.ActiveContainer is ILibraryWritableContainer)
if (this.acceptButton.Enabled)
{
acceptButton.InvokeClick();
// And disable it so there are not multiple fires. No need to re-enable, the dialog is going to close.
this.AcceptButton.Enabled = false;
if (librarySelectorWidget.ActiveContainer is ILibraryWritableContainer)
{
acceptButton.InvokeClick();
// And disable it so there are not multiple fires. No need to re-enable, the dialog is going to close.
this.AcceptButton.Enabled = false;
}
}
};
itemNameWidget.ActualTextEditWidget.TextChanged += (s, e) =>
{
acceptButton.Enabled = libraryNavContext.ActiveContainer is ILibraryWritableContainer
&& !string.IsNullOrWhiteSpace(itemNameWidget.ActualTextEditWidget.Text);
};
contentRow.AddChild(itemNameWidget);
var icon = StaticData.Instance.LoadIcon("fa-folder-new_16.png", 16, 16).SetToColor(ApplicationController.Instance.MenuTheme.TextColor);

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2018, Lars Brubaker, John Lewin
Copyright (c) 2022, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -38,6 +38,7 @@ using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.ImageProcessing;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.Library;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
@ -463,8 +464,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
"Continue Printing".Localize());
}
else if (this.TabContent is DesignTabPage partTab
&& partTab?.Workspace?.SceneContext?.Scene is InteractiveScene sceneContext
&& sceneContext.HasUnsavedChanges)
&& partTab?.Workspace?.SceneContext?.Scene is InteractiveScene scene
&& scene.HasUnsavedChanges)
{
StyledMessageBox.ShowYNCMessageBox(
(response) =>
@ -474,12 +475,30 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
case StyledMessageBox.ResponseType.YES:
UiThread.RunOnIdle(async () =>
{
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, partTab.Workspace.SceneContext.SaveChanges);
var sceneContext = partTab.Workspace.SceneContext;
if (sceneContext.EditContext.ContentStore == null)
{
// If we are about to close a tab that has never been saved it will need a name before it can actually save
// Open up the save as dialog rather than continue with saving and closing
DialogWindow.Show(
new SaveAsPage(
(container, newName) =>
{
sceneContext.SaveAs(container, newName);
// If we succeed at saveing the file go ahead and finish closing this tab
this.CloseClicked?.Invoke(this, null);
// Must be called after CloseClicked otherwise listeners are cleared before event is invoked
this.parentTabControl.CloseTab(this);
}));
}
else
{
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, partTab.Workspace.SceneContext.SaveChanges);
this.CloseClicked?.Invoke(this, null);
// Must be called after CloseClicked otherwise listeners are cleared before event is invoked
this.parentTabControl.CloseTab(this);
this.CloseClicked?.Invoke(this, null);
// Must be called after CloseClicked otherwise listeners are cleared before event is invoked
this.parentTabControl.CloseTab(this);
}
});
break;

File diff suppressed because it is too large Load diff

View file

@ -841,7 +841,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return theme.CreateSplitButton(new SplitButtonParams()
{
ButtonText = "Save".Localize(),
ButtonName = "Save Button",
ButtonName = "Save",
Icon = StaticData.Instance.LoadIcon("save_grey_16x.png", 16, 16).SetToColor(theme.TextColor),
ButtonAction = (menuButton) =>
{

View file

@ -37,6 +37,7 @@ using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SettingsManagement;
@ -353,16 +354,25 @@ namespace MatterHackers.MatterControl
{
if (workspace.Printer == null)
{
// if we have a filename
// save
// else
// switch to the tab we are about to save
// ask the user to give us a filname
// if no filename
// abort the exit procedure
await ApplicationController.Instance.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges);
// check for error or abort
hadSaveError |= workspace.SceneContext.HadSaveError;
var sceneContext = workspace.SceneContext;
if (sceneContext.EditContext.ContentStore == null)
{
hadSaveError = true;
// If we are about to close a tab that has never been saved it will need a name before it can actually save
// Open up the save as dialog rather than continue with saving and closing
DialogWindow.Show(
new SaveAsPage(
(container, newName) =>
{
sceneContext.SaveAs(container, newName);
}));
}
else
{
await ApplicationController.Instance.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges);
// check for error or abort
hadSaveError |= workspace.SceneContext.HadSaveError;
}
}
}

@ -1 +1 @@
Subproject commit 255aa2aa1a9a157fb44e0aa9a62438173de67905
Subproject commit 90fb1dffadc95d8f361fac9a5bb8db9e6c11f3fb

View file

@ -1,4 +1,33 @@
using System.IO;
/*
Copyright (c) 2022, 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 System.IO;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg.UI;
@ -56,7 +85,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
testRunner.Require(() => scene.Children.Count == 1, "Should have 1 part (the phil)");
var tempFilaname = "Temp Test Save.mcx";
var tempFullPath = Path.Combine(ApplicationDataStorage.Instance.MyDocumentsDirectory, tempFilaname);
var tempFullPath = Path.Combine(ApplicationDataStorage.Instance.DownloadsDirectory, tempFilaname);
// delete the temp file if it exists in the Downloads folder
void DeleteTempFile()
@ -70,10 +99,13 @@ namespace MatterHackers.MatterControl.Tests.Automation
DeleteTempFile();
// Make sure the tab is named 'New Design'
Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design"));
testRunner.Require(() => systemWindow.GetVisibleWigetWithText("New Design") != null, "Must have New Design");
// add a new part to the bed
testRunner.AddItemToBed();
// Click the save button
testRunner.ClickByName("Save Button")
testRunner.ClickByName("Save")
// Cancle the save as
.ClickByName("Cancel Wizard Button");
@ -99,7 +131,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design"));
// Click the save button
testRunner.ClickByName("Save Button")
testRunner.ClickByName("Save")
// Save a temp file to the downloads folder
.DoubleClickByName("Computer Row Item Collection")
.DoubleClickByName("Downloads Row Item Collection")
@ -119,7 +151,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
// Click the 'Cancel'
.ClickByName("Cancel Button")
// Click the 'Save' button
.ClickByName("Save Button")
.ClickByName("Save")
// Click the close button (now we have no edit it should cancel without request)
.ClickByName("Close Tab Button");

View file

@ -210,7 +210,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
// Assert - one part added and queue count increases by one
Assert.AreEqual(expectedCount, QueueData.Instance.ItemCount, "Queue count should increase by 1 when adding 1 item");
Assert.IsTrue(testRunner.WaitForName("Row Item Rook"), "Named widget should exist after add(Rook)");
Assert.IsTrue(testRunner.WaitForName("Row Item Rook.amf"), "Named widget should exist after add(Rook)");
return Task.CompletedTask;
});

View file

@ -85,7 +85,6 @@ namespace MatterControl.Tests.MatterControl
var assetManager = new MockAssetManager();
AssetObject3D.AssetManager = assetManager;
// Store
await AssetObject3D.AssetManager.StoreAsset(object3D, false, CancellationToken.None, null);

View file

@ -230,6 +230,11 @@ namespace MatterHackers.MatterControl.Tests.Automation
return testRunner.ClickByName(partNameToSelect);
}
public static AutomationRunner ClickDiscardChanges(this AutomationRunner testRunner)
{
return testRunner.ClickByName("No Button");
}
public static AutomationRunner WaitForFirstDraw(this AutomationRunner testRunner)
{
testRunner.GetWidgetByName("PartPreviewContent", out SystemWindow systemWindow, 10);
@ -626,45 +631,40 @@ namespace MatterHackers.MatterControl.Tests.Automation
{
testRunner.EnsureContentMenuOpen();
switch (libraryRowItemName)
if (!testRunner.NameExists(libraryRowItemName, .2))
{
case "SD Card Row Item Collection":
if (ApplicationController.Instance.DragDropData.View3DWidget?.Printer is PrinterConfig printer)
{
testRunner.DoubleClickByName($"{printer.PrinterName} Row Item Collection");
// go back to the home section
testRunner.ClickByName("Bread Crumb Button Home")
.Delay();
testRunner.Delay();
switch (libraryRowItemName)
{
case "SD Card Row Item Collection":
if (ApplicationController.Instance.DragDropData.View3DWidget?.Printer is PrinterConfig printer)
{
testRunner.DoubleClickByName($"{printer.PrinterName} Row Item Collection")
.Delay();
}
testRunner.ClickByName(libraryRowItemName);
}
break;
break;
case "Calibration Parts Row Item Collection":
case "Primitives Row Item Collection":
if (!testRunner.NameExists("Design Apps Row Item Collection"))
{
testRunner.ClickByName("Bread Crumb Button Home")
.Delay();
}
// If visible, navigate into Libraries container before opening target
if (testRunner.NameExists("Design Apps Row Item Collection"))
{
case "Calibration Parts Row Item Collection":
case "Primitives Row Item Collection":
// If visible, navigate into Libraries container before opening target
testRunner.DoubleClickByName("Design Apps Row Item Collection")
.Delay();
}
break;
break;
case "Cloud Library Row Item Collection":
case "Print Queue Row Item Collection":
case "Local Library Row Item Collection":
if (!testRunner.NameExists(libraryRowItemName))
{
testRunner.ClickByName("Bread Crumb Button Home")
case "Downloads Row Item Collection":
testRunner.DoubleClickByName("Computer Row Item Collection")
.Delay();
}
break;
break;
case "Cloud Library Row Item Collection":
case "Print Queue Row Item Collection":
case "Local Library Row Item Collection":
break;
}
}
testRunner.DoubleClickByName(libraryRowItemName);
@ -675,7 +675,8 @@ namespace MatterHackers.MatterControl.Tests.Automation
{
if (!testRunner.WaitForName("FolderBreadCrumbWidget", secondsToWait: 0.2))
{
testRunner.ClickByName("Add Content Menu");
testRunner.ClickByName("Add Content Menu")
.Delay();
}
return testRunner;
@ -923,7 +924,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
testMethod,
maxTimeToRun,
defaultTestImages,
closeWindow: () =>
closeWindow: (testRunner) =>
{
foreach (var printer in ApplicationController.Instance.ActivePrinters)
{
@ -934,6 +935,12 @@ namespace MatterHackers.MatterControl.Tests.Automation
}
rootSystemWindow.Close();
testRunner.Delay();
if (testRunner.NameExists("No Button"))
{
testRunner.ClickDiscardChanges();
}
});
}

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2016, John Lewin
Copyright (c) 2022, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -48,6 +48,15 @@ namespace MatterHackers.PolygonMesh.UnitTests
[TestFixture, Category("Agg.PolygonMesh"), RunInApplicationDomain]
public class SceneTests
{
[SetUp]
public void SetupUserSettings()
{
StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "MatterControl", "StaticData");
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
UserSettings.Instance.set(UserSettingsKey.PublicProfilesSha, "0"); //Clears DB so we will download the latest list
}
[Test]
public void SaveSimpleScene()
{
@ -242,11 +251,6 @@ namespace MatterHackers.PolygonMesh.UnitTests
[Test]
public async Task ResavedSceneRemainsConsistent()
{
#if !__ANDROID__
// Set the static data to point to the directory of MatterControl
StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData");
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
#endif
AssetObject3D.AssetManager = new AssetManager();
var sceneContext = new BedConfig(null);
@ -262,14 +266,9 @@ namespace MatterHackers.PolygonMesh.UnitTests
// Set directory for asset resolution
Object3D.AssetsPath = Path.Combine(tempPath, "Assets");
Directory.Delete(Object3D.AssetsPath, true);
Directory.CreateDirectory(Object3D.AssetsPath);
// Empty temp folder
foreach (string tempFile in Directory.GetFiles(tempPath).ToList())
{
File.Delete(tempFile);
}
scene.Save(filePath);
Assert.AreEqual(1, Directory.GetFiles(tempPath).Length, "Only .mcx file should exists");
Assert.AreEqual(1, Directory.GetFiles(Path.Combine(tempPath, "Assets")).Length, "Only 1 asset should exist");
@ -290,8 +289,8 @@ namespace MatterHackers.PolygonMesh.UnitTests
});
// Serialize and compare the two trees
string onDiskData = loadedItem.ToJson();
string inMemoryData = scene.ToJson();
string onDiskData = loadedItem.ToJson().Result;
string inMemoryData = scene.ToJson().Result;
//File.WriteAllText(@"c:\temp\file-a.txt", onDiskData);
//File.WriteAllText(@"c:\temp\file-b.txt", inMemoryData);
@ -301,7 +300,7 @@ namespace MatterHackers.PolygonMesh.UnitTests
// Save the scene a second time, validate that things remain the same
scene.Save(filePath);
onDiskData = loadedItem.ToJson();
onDiskData = loadedItem.ToJson().Result;
Assert.IsTrue(inMemoryData == onDiskData);