3mf loading improvements (soon)
Text wrapping
This commit is contained in:
parent
5b8ccb4334
commit
097b53649a
7 changed files with 120 additions and 73 deletions
|
|
@ -65,7 +65,8 @@ namespace MatterHackers.MatterControl
|
||||||
public static readonly string ExceptionDuringSliceSettingsValidation = nameof(ExceptionDuringSliceSettingsValidation);
|
public static readonly string ExceptionDuringSliceSettingsValidation = nameof(ExceptionDuringSliceSettingsValidation);
|
||||||
public static readonly string IncompatibleBedSurfaceAndMaterial = nameof(IncompatibleBedSurfaceAndMaterial);
|
public static readonly string IncompatibleBedSurfaceAndMaterial = nameof(IncompatibleBedSurfaceAndMaterial);
|
||||||
public static readonly string ItemCannotBeExported = nameof(ItemCannotBeExported);
|
public static readonly string ItemCannotBeExported = nameof(ItemCannotBeExported);
|
||||||
public static readonly string ItemToAMFExportInvalid = nameof(ItemToAMFExportInvalid);
|
public static readonly string ItemToAMFExportInvalid = nameof(ItemToAMFExportInvalid);
|
||||||
|
public static readonly string ItemTo3MFExportInvalid = nameof(ItemTo3MFExportInvalid);
|
||||||
public static readonly string ItemToSTLExportInvalid = nameof(ItemToSTLExportInvalid);
|
public static readonly string ItemToSTLExportInvalid = nameof(ItemToSTLExportInvalid);
|
||||||
public static readonly string MaterialNotSelected = nameof(MaterialNotSelected);
|
public static readonly string MaterialNotSelected = nameof(MaterialNotSelected);
|
||||||
public static readonly string BedTemperatureError = nameof(BedTemperatureError);
|
public static readonly string BedTemperatureError = nameof(BedTemperatureError);
|
||||||
|
|
|
||||||
|
|
@ -27,56 +27,12 @@ of the authors and should not be interpreted as representing official policies,
|
||||||
either expressed or implied, of the FreeBSD Project.
|
either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.IO.Compression;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using global::MatterControl.Printing;
|
|
||||||
using Markdig.Agg;
|
|
||||||
using Markdig.Renderers.Agg;
|
|
||||||
using MatterHackers.Agg;
|
|
||||||
using MatterHackers.Agg.Font;
|
|
||||||
using MatterHackers.Agg.Image;
|
|
||||||
using MatterHackers.Agg.Platform;
|
|
||||||
using MatterHackers.Agg.UI;
|
|
||||||
using MatterHackers.Agg.VertexSource;
|
|
||||||
using MatterHackers.DataConverters3D;
|
|
||||||
using MatterHackers.DataConverters3D.UndoCommands;
|
|
||||||
using MatterHackers.Localizations;
|
|
||||||
using MatterHackers.MatterControl.CustomWidgets;
|
|
||||||
using MatterHackers.MatterControl.DataStorage;
|
|
||||||
using MatterHackers.MatterControl.DesignTools;
|
|
||||||
using MatterHackers.MatterControl.DesignTools.Operations;
|
|
||||||
using MatterHackers.MatterControl.Extensibility;
|
|
||||||
using MatterHackers.MatterControl.Library;
|
using MatterHackers.MatterControl.Library;
|
||||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
|
||||||
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
|
|
||||||
using MatterHackers.MatterControl.Plugins;
|
|
||||||
using MatterHackers.MatterControl.PrinterCommunication;
|
|
||||||
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
|
|
||||||
using MatterHackers.MatterControl.PrintQueue;
|
|
||||||
using MatterHackers.MatterControl.SettingsManagement;
|
|
||||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
||||||
using MatterHackers.MatterControl.Tour;
|
|
||||||
using MatterHackers.PolygonMesh;
|
|
||||||
using MatterHackers.PolygonMesh.Processors;
|
|
||||||
using MatterHackers.VectorMath;
|
|
||||||
using MatterHackers.VectorMath.TrackBall;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("MatterControl.Tests")]
|
[assembly: InternalsVisibleTo("MatterControl.Tests")]
|
||||||
[assembly: InternalsVisibleTo("MatterControl.AutomationTests")]
|
[assembly: InternalsVisibleTo("MatterControl.AutomationTests")]
|
||||||
|
|
@ -84,20 +40,19 @@ using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace MatterHackers.MatterControl
|
namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
|
public class ContentStoreConverter : JsonConverter<IContentStore>
|
||||||
|
{
|
||||||
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
public class ContentStoreConverter : JsonConverter<IContentStore>
|
public override IContentStore ReadJson(JsonReader reader, Type objectType, IContentStore existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
public override bool CanWrite => false;
|
var token = JToken.Load(reader);
|
||||||
|
|
||||||
public override IContentStore ReadJson(JsonReader reader, Type objectType, IContentStore existingValue, bool hasExistingValue, JsonSerializer serializer)
|
return null;
|
||||||
{
|
}
|
||||||
var token = JToken.Load(reader);
|
|
||||||
|
|
||||||
return null;
|
public override void WriteJson(JsonWriter writer, IContentStore value, JsonSerializer serializer)
|
||||||
}
|
{
|
||||||
|
}
|
||||||
public override void WriteJson(JsonWriter writer, IContentStore value, JsonSerializer serializer)
|
}
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -191,12 +191,12 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
bool valuesChanged = false;
|
bool valuesChanged = false;
|
||||||
var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
|
var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
|
||||||
var wrappingWidth = WrappingWidth.Value(this);
|
var wrappingWidth_mm = WrappingWidth.Value(this);
|
||||||
var wrappingIndent = WrappingIndent.ClampIfNotCalculated(this, 0, 100, ref valuesChanged);
|
var wrappingIndent = WrappingIndent.ClampIfNotCalculated(this, 0, 100, ref valuesChanged);
|
||||||
|
|
||||||
if (wrappingWidth < 10)
|
if (wrappingWidth_mm < 10)
|
||||||
{
|
{
|
||||||
wrappingWidth = 0;
|
wrappingWidth_mm = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var textToWrite = MultiLine
|
var textToWrite = MultiLine
|
||||||
|
|
@ -205,10 +205,16 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
|
|
||||||
var pointSize = PointSize.Value(this);
|
var pointSize = PointSize.Value(this);
|
||||||
|
|
||||||
if (WrapLines && wrappingWidth > 0)
|
var mmPerInch = 25.4;
|
||||||
|
var mmPerPoint = mmPerInch / StyledTypeFace.PointsPerInch;
|
||||||
|
var pixelsPerPoint = StyledTypeFace.PixelsPerInch / StyledTypeFace.PointsPerInch;
|
||||||
|
|
||||||
|
if (WrapLines && wrappingWidth_mm > 0)
|
||||||
{
|
{
|
||||||
var wrapper = new EnglishTextWrapping(pointSize);
|
var wrapper = new EnglishTextWrapping(pointSize);
|
||||||
textToWrite = wrapper.InsertCRs(textToWrite, wrappingWidth, MultiLine ? wrappingIndent : 0);
|
var wrappingPoints = wrappingWidth_mm / mmPerPoint;
|
||||||
|
var wrappingPixels = wrappingPoints * pixelsPerPoint;
|
||||||
|
textToWrite = wrapper.InsertCRs(textToWrite, wrappingPixels, MultiLine ? wrappingIndent : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(textToWrite))
|
if (string.IsNullOrWhiteSpace(textToWrite))
|
||||||
|
|
@ -224,7 +230,6 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
list.Clear();
|
list.Clear();
|
||||||
|
|
||||||
var offset = Vector2.Zero;
|
var offset = Vector2.Zero;
|
||||||
double pointsToMm = 0.352778;
|
|
||||||
var lineNumber = 1;
|
var lineNumber = 1;
|
||||||
var leterNumber = 1;
|
var leterNumber = 1;
|
||||||
var lineObject = new Object3D()
|
var lineObject = new Object3D()
|
||||||
|
|
@ -240,14 +245,14 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
{
|
{
|
||||||
ResolutionScale = 10
|
ResolutionScale = 10
|
||||||
};
|
};
|
||||||
var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
|
var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(mmPerPoint));
|
||||||
|
|
||||||
if (letter == '\n')
|
if (letter == '\n')
|
||||||
{
|
{
|
||||||
leterNumber = 0;
|
leterNumber = 0;
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
offset.X = 0;
|
offset.X = 0;
|
||||||
offset.Y -= style.EmSizeInPoints * pointsToMm * 1.4;
|
offset.Y -= style.EmSizeInPoints * mmPerPoint * 1.4;
|
||||||
lineObject = new Object3D()
|
lineObject = new Object3D()
|
||||||
{
|
{
|
||||||
Matrix = Matrix4X4.CreateTranslation(0, offset.Y, 0),
|
Matrix = Matrix4X4.CreateTranslation(0, offset.Y, 0),
|
||||||
|
|
@ -261,11 +266,11 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
switch (letter)
|
switch (letter)
|
||||||
{
|
{
|
||||||
case ' ':
|
case ' ':
|
||||||
offset.X += letterPrinter.GetSize(" ").X * pointsToMm;
|
offset.X += letterPrinter.GetSize(" ").X * mmPerPoint;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\t':
|
case '\t':
|
||||||
offset.X += letterPrinter.GetSize(" ").X * pointsToMm;
|
offset.X += letterPrinter.GetSize(" ").X * mmPerPoint;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -281,7 +286,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
new VertexSourceApplyTransform(
|
new VertexSourceApplyTransform(
|
||||||
new VertexStorage(scaledLetterPrinter), Affine.NewTranslation(offset.X, offset.Y)));
|
new VertexStorage(scaledLetterPrinter), Affine.NewTranslation(offset.X, offset.Y)));
|
||||||
}
|
}
|
||||||
offset.X += letterPrinter.GetSize(letter.ToString()).X * pointsToMm;
|
offset.X += letterPrinter.GetSize(letter.ToString()).X * mmPerPoint;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
83
MatterControlLib/Library/Export/TheeMFExport.cs
Normal file
83
MatterControlLib/Library/Export/TheeMFExport.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2023, Lars Brubaker, 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.Image;
|
||||||
|
using MatterHackers.Agg.Platform;
|
||||||
|
using MatterHackers.Localizations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MatterHackers.MatterControl.Library.Export
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
// This is not working yet. So it is only enabled in debug mode
|
||||||
|
public class TheeMFExport : IExportPlugin
|
||||||
|
{
|
||||||
|
public string ButtonText => "3MF File".Localize();
|
||||||
|
public string DisabledReason => "";
|
||||||
|
public bool Enabled => true;
|
||||||
|
public string ExtensionFilter => "Save as 3MF|*.3mf";
|
||||||
|
public string FileExtension => ".3mf";
|
||||||
|
public ImageBuffer Icon { get; } = StaticData.Instance.LoadIcon(Path.Combine("filetypes", "3mf.png"));
|
||||||
|
public int Priority => 3;
|
||||||
|
|
||||||
|
public bool ExportPossible(ILibraryAsset libraryItem) => true;
|
||||||
|
|
||||||
|
public async Task<List<ValidationError>> Generate(IEnumerable<ILibraryItem> libraryItems, string outputPath, Action<double, string> progress, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var firstItem = libraryItems.OfType<ILibraryAsset>().FirstOrDefault();
|
||||||
|
if (firstItem is ILibraryAsset libraryItem)
|
||||||
|
{
|
||||||
|
bool exportSuccessful = await MeshExport.ExportMesh(libraryItem, outputPath, true, progress);
|
||||||
|
if (exportSuccessful)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new List<ValidationError>()
|
||||||
|
{
|
||||||
|
new ValidationError(ValidationErrors.ItemTo3MFExportInvalid)
|
||||||
|
{
|
||||||
|
Error = "Item cannot be exported as 3MF".Localize(),
|
||||||
|
Details = firstItem?.ToString() ?? ""
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize(PrinterConfig printer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
BIN
StaticData/Icons/filetypes/3mf.png
Normal file
BIN
StaticData/Icons/filetypes/3mf.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 556 B |
|
|
@ -115,6 +115,9 @@ Translated:3D
|
||||||
English:3D Layer View
|
English:3D Layer View
|
||||||
Translated:3D Layer View
|
Translated:3D Layer View
|
||||||
|
|
||||||
|
English:3MF File
|
||||||
|
Translated:3MF File
|
||||||
|
|
||||||
English:3x3 Mesh
|
English:3x3 Mesh
|
||||||
Translated:3x3 Mesh
|
Translated:3x3 Mesh
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit f7bda6246e751c44143ddb557f4742f5274015bb
|
Subproject commit 1e59388827f24709eae3e19cf0d94f3a63a4a03b
|
||||||
Loading…
Add table
Add a link
Reference in a new issue