Design tools
This commit is contained in:
parent
69a77368b5
commit
907609b587
86 changed files with 4971 additions and 4664 deletions
|
|
@ -71,6 +71,7 @@
|
|||
<Compile Include="MatterControl\GCodeStreamTests.cs" />
|
||||
<Compile Include="MatterControl\TranslationsTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SceneTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
|
|
@ -80,10 +81,6 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BrailleBuilder\BrailleBuilder.csproj">
|
||||
<Project>{70FBB82C-558D-4B5F-BE75-A922D392E650}</Project>
|
||||
<Name>BrailleBuilder</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\MatterControl.csproj">
|
||||
<Project>{0B8D6F56-BD7F-4426-B858-D9292B084656}</Project>
|
||||
<Name>MatterControl</Name>
|
||||
|
|
@ -96,10 +93,18 @@
|
|||
<Project>{657DBC6D-C3EA-4398-A3FA-DDB73C14F71B}</Project>
|
||||
<Name>Agg</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Submodules\agg-sharp\DataConverters3D\DataConverters3D.csproj">
|
||||
<Project>{04667764-dc7b-4b95-aef6-b4e6c87a54e9}</Project>
|
||||
<Name>DataConverters3D</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Submodules\agg-sharp\examples\GCodeVisualizer\GCodeVisualizer.csproj">
|
||||
<Project>{F67AE800-B0C7-42A8-836F-597B4E74591C}</Project>
|
||||
<Name>GCodeVisualizer</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Submodules\agg-sharp\examples\MeshViewer\MeshViewer.csproj">
|
||||
<Project>{a737bc76-165b-46c6-82b7-8871c7c92942}</Project>
|
||||
<Name>MeshViewer</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Submodules\agg-sharp\GuiAutomation\GuiAutomation.csproj">
|
||||
<Project>{E9102310-0029-4D8F-B1E9-88FBA6147D45}</Project>
|
||||
<Name>GuiAutomation</Name>
|
||||
|
|
@ -132,6 +137,10 @@
|
|||
<Project>{D3E41B4E-BFBB-44CA-94C8-95C00F754FDD}</Project>
|
||||
<Name>VectorMath</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\TextCreator\TextCreator.csproj">
|
||||
<Project>{F49EC1DD-D645-4709-8667-B57318AF67B0}</Project>
|
||||
<Name>TextCreator</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
@ -143,6 +143,18 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
CloseSignInAndPrinterSelect,
|
||||
};
|
||||
|
||||
public static void Select3DPart(this AutomationRunner testRunner, string partNameToSelect)
|
||||
{
|
||||
if(testRunner.NameExists("3D View Edit"))
|
||||
{
|
||||
testRunner.ClickByName("3D View Edit");
|
||||
}
|
||||
testRunner.DragDropByName("centerPartPreviewAndControls", "centerPartPreviewAndControls", offsetDrop: new Agg.Point2D(10, 15), mouseButtons: MouseButtons.Right);
|
||||
|
||||
testRunner.Delay(1);
|
||||
testRunner.ClickByName(partNameToSelect);
|
||||
}
|
||||
|
||||
public static void CloseSignInAndPrinterSelect(this AutomationRunner testRunner, PrepAction preAction = PrepAction.CloseSignInAndPrinterSelect)
|
||||
{
|
||||
// Non-MCCentral builds won't have the plugin. Reduce the wait time for these cases
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ using MatterHackers.Agg;
|
|||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.GuiAutomation;
|
||||
using MatterHackers.MatterControl.Tests.Automation;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -45,43 +46,41 @@ namespace MatterHackers.MatterControl
|
|||
StatisticsTracker testTracker = new StatisticsTracker("SwitchBetweenTabs");
|
||||
bool clickFirstItem = true;
|
||||
bool done = false;
|
||||
bool firstDraw = true;
|
||||
AutomationRunner clickPreview;
|
||||
Stopwatch timeSinceLastClick = Stopwatch.StartNew();
|
||||
Stopwatch totalDrawTime = Stopwatch.StartNew();
|
||||
int drawCount = 0;
|
||||
|
||||
EventHandler<DrawEventArgs> beforeDraw = (sender, e) =>
|
||||
EventHandler formLoad = (s, e) =>
|
||||
{
|
||||
if (firstDraw)
|
||||
clickPreview = new AutomationRunner();
|
||||
Task.Run(() =>
|
||||
{
|
||||
clickPreview = new AutomationRunner();
|
||||
Task.Run(() =>
|
||||
while (!done)
|
||||
{
|
||||
while (!done)
|
||||
if (clickPreview != null && timeSinceLastClick.Elapsed.TotalSeconds > switchTimeSeconds)
|
||||
{
|
||||
if (clickPreview != null && timeSinceLastClick.Elapsed.TotalSeconds > switchTimeSeconds)
|
||||
if (clickFirstItem)
|
||||
{
|
||||
if (clickFirstItem)
|
||||
{
|
||||
clickPreview.ClickByName(firstWidgetName);
|
||||
}
|
||||
else
|
||||
{
|
||||
clickPreview.ClickByName(secondWidgetName);
|
||||
}
|
||||
clickFirstItem = !clickFirstItem;
|
||||
timeSinceLastClick.Restart();
|
||||
clickPreview.ClickByName(firstWidgetName);
|
||||
}
|
||||
else
|
||||
{
|
||||
clickPreview.ClickByName(secondWidgetName);
|
||||
}
|
||||
clickFirstItem = !clickFirstItem;
|
||||
timeSinceLastClick.Restart();
|
||||
}
|
||||
});
|
||||
firstDraw = false;
|
||||
}
|
||||
|
||||
totalDrawTime.Restart();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
container.BeforeDraw += beforeDraw;
|
||||
container.Load += formLoad;
|
||||
|
||||
container.BeforeDraw += (sender, e) =>
|
||||
{
|
||||
totalDrawTime.Restart();
|
||||
};
|
||||
|
||||
EventHandler<DrawEventArgs> afterDraw = null;
|
||||
afterDraw = (sender, e) =>
|
||||
|
|
@ -93,7 +92,7 @@ namespace MatterHackers.MatterControl
|
|||
if (testTracker.Count == 100)
|
||||
{
|
||||
Trace.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(testTracker));
|
||||
container.BeforeDraw -= beforeDraw;
|
||||
container.Load -= formLoad;
|
||||
container.BeforeDraw -= afterDraw;
|
||||
done = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ namespace MatterControl.Tests
|
|||
MatterHackers.Agg.ImageProcessing.dll
|
||||
MatterHackers.MarchingSquares.dll
|
||||
GuiAutomation.dll
|
||||
BrailBuilder.dll
|
||||
TextCreator.dll";
|
||||
|
||||
foreach (string assemblyName in knownAssemblies.Split('\n').Select(s => s.Trim()))
|
||||
|
|
|
|||
175
Tests/MatterControl.Tests/SceneTests.cs
Normal file
175
Tests/MatterControl.Tests/SceneTests.cs
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using MatterHackers.PolygonMesh.Csg;
|
||||
using MatterHackers.VectorMath;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.MatterControl.Tests.Automation;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.PolygonMesh.UnitTests
|
||||
{
|
||||
[TestFixture, Category("Agg.PolygonMesh")]
|
||||
public class SceneTests
|
||||
{
|
||||
static string matterControlPath = Path.GetFullPath(Path.Combine("..", "..", "..", "..", "..", "MatterControl"));
|
||||
|
||||
[Test]
|
||||
public void SaveSimpleScene()
|
||||
{
|
||||
var scene = new InteractiveScene();
|
||||
scene.Children.Add(new Object3D
|
||||
{
|
||||
ItemType = Object3DTypes.Model
|
||||
});
|
||||
|
||||
string tempPath = GetSceneTempPath();
|
||||
string filePath = Path.Combine(tempPath, "some.mcx");
|
||||
|
||||
scene.Save(filePath, tempPath);
|
||||
|
||||
Assert.IsTrue(File.Exists(filePath));
|
||||
|
||||
IObject3D loadedItem = Object3D.Load(filePath);
|
||||
Assert.IsTrue(loadedItem.Children.Count == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatesAndLinksAmfsForUnsavedMeshes()
|
||||
{
|
||||
var scene = new InteractiveScene();
|
||||
scene.Children.Add(new Object3D
|
||||
{
|
||||
ItemType = Object3DTypes.Model,
|
||||
Mesh = PlatonicSolids.CreateCube(20, 20, 20)
|
||||
});
|
||||
|
||||
string tempPath = GetSceneTempPath();
|
||||
string filePath = Path.Combine(tempPath, "some.mcx");
|
||||
|
||||
scene.Save(filePath, tempPath);
|
||||
|
||||
Assert.IsTrue(File.Exists(filePath));
|
||||
|
||||
IObject3D loadedItem = Object3D.Load(filePath);
|
||||
Assert.IsTrue(loadedItem.Children.Count == 1);
|
||||
|
||||
IObject3D meshItem = loadedItem.Children.First();
|
||||
|
||||
Assert.IsTrue(!string.IsNullOrEmpty(meshItem.MeshPath));
|
||||
Assert.IsTrue(File.Exists(meshItem.MeshPath));
|
||||
Assert.IsNotNull(meshItem.Mesh);
|
||||
Assert.IsTrue(meshItem.Mesh.Faces.Count > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ResavedSceneRemainsConsistent()
|
||||
{
|
||||
#if !__ANDROID__
|
||||
string staticDataPathOverride = Path.Combine(matterControlPath, "StaticData");
|
||||
|
||||
// Set the static data to point to the directory of MatterControl
|
||||
StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
|
||||
|
||||
ActiveSliceSettings.Instance?.SetValue(SettingsKey.center_part_on_bed, "0");
|
||||
#endif
|
||||
var view3DWidget = new View3DWidget(
|
||||
null,
|
||||
new Vector3(200, 200, 100),
|
||||
new Vector2(100, 100),
|
||||
MeshVisualizer.BedShape.Rectangular,
|
||||
View3DWidget.WindowMode.Embeded,
|
||||
View3DWidget.AutoRotate.Disabled,
|
||||
View3DWidget.OpenMode.Editing);
|
||||
|
||||
var scene = view3DWidget.Scene;
|
||||
scene.Children.Add(new Object3D
|
||||
{
|
||||
ItemType = Object3DTypes.Model,
|
||||
Mesh = PlatonicSolids.CreateCube(20, 20, 20)
|
||||
});
|
||||
|
||||
string tempPath = GetSceneTempPath();
|
||||
string filePath = Path.Combine(tempPath, "some.mcx");
|
||||
|
||||
// Empty temp folder
|
||||
foreach(string tempFile in Directory.GetFiles(tempPath).ToList())
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
|
||||
scene.Save(filePath, tempPath);
|
||||
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");
|
||||
|
||||
var originalFiles = Directory.GetFiles(tempPath).ToArray(); ;
|
||||
|
||||
IObject3D loadedItem = Object3D.Load(filePath);
|
||||
Assert.IsTrue(loadedItem.Children.Count == 1);
|
||||
|
||||
await view3DWidget.ClearBedAndLoadPrintItemWrapper(
|
||||
new MatterControl.PrintQueue.PrintItemWrapper(
|
||||
new MatterControl.DataStorage.PrintItem("test", filePath)), true);
|
||||
|
||||
string onDiskData = JsonConvert.SerializeObject(loadedItem, Formatting.Indented);
|
||||
string inMemoryData = JsonConvert.SerializeObject(view3DWidget.Scene, Formatting.Indented);
|
||||
|
||||
Assert.IsTrue(inMemoryData == onDiskData);
|
||||
|
||||
// Save the scene a second time, validate that things remain the same
|
||||
view3DWidget.Scene.Save(filePath, tempPath);
|
||||
onDiskData = JsonConvert.SerializeObject(loadedItem, Formatting.Indented);
|
||||
|
||||
Assert.IsTrue(inMemoryData == onDiskData);
|
||||
|
||||
// Verify that no additional files get created on second save
|
||||
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");
|
||||
}
|
||||
|
||||
public static string GetSceneTempPath()
|
||||
{
|
||||
string tempPath = Path.GetFullPath(Path.Combine(matterControlPath, "Tests", "temp", "scenetests"));
|
||||
Directory.CreateDirectory(tempPath);
|
||||
return tempPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue