Files
UVtools/UVtools.Core/FileFormats/MakerbaseFile.cs
T
Tiago Conceição 0ba61780b7 v2.4.0
* (Upgrade) EmguCV/OpenCV to v4.5.1
* (Upgrade) AvaloniaUI to 1.0
* (Improvement) GUI re-touched
* (Improvement) Make pixel editor tab to disappear when pixel editor is disabled
* (Improvement) Simplify the output filename from PrusaSlicer profiles
* (Improvement) All operations require a slicer file at constructor rather than on execute, this allow exposure the open file to the operation before run it
* (Improvement) Calibrations: Auto set "Mirror Output" if open file have MirrorDisplay set
* (Change) Tool - Redraw model/supports icon
* (Change) photon and cbddlp to use version 3 by default
* (Add) Tool - Dynamic layer height: Analyze and optimize the model with dynamic layer heights, larger angles will slice at lower layer height
        while more straight angles will slice larger layer height. (#131)
* (Add) Calibration - Exposure time finder: Generates test models with various strategies and increments to verify the best exposure time for a given layer height
* (Add) File load checks, trigger error when a file have critical errors and attempt to fix non-critical errors
  * Layers must have an valid image, otherwise trigger an error
  * Layers must have a incremental or equal position Z than it previous, otherwise trigger an error
  * If layer 0 starts at 0mm it will auto fix all layers, it will add Layer Height to the current z at every layer
* (Add) Tool - Edit print parameters: Allow set parameters to each x layers and skip n layers inside the given range.
        This allow the use of optimizations in a layer pattern, for example, to set 3s for a layer but 2.5s for the next.
* (Add) Layer height property to "Layer Data" table: Shows layer height for the slice
* (Fix) When automations applied and file is saved, it will not warn user about file overwrite for the first time save
* (Fix) Tool - Redraw model/supports: Disable apply button when no file selected
* (Fix) Tool - Infill: Lack of equality member to test if same infill profile already exists
* (Fix) Auto converted files from SL1 where clipping filename at first dot (.), now it only strips known extensions
* (Fix) SL1 encoded files wasn't generating the right information and lead to printer crash
* (Fix) PrusaSlicer printer "Anycubic Photon S" LiftSpeed was missing and contains a typo (#135)
* (Fix) PrusaSlicer profile manager wasnt marking missing profiles to be installed (#135)
* (Fix) PrusaSlicer folder search on linux to also look at %HOME%/.config/PrusaSlicer (#135, #136)
* (Fix) Operations were revised and some bug fixed, most about can't cancel the progress
* (Fix) Some typos on tooltips
* (Fix) Prevent PhotonS from enconding, it will trigger error now as this format is read-only
* **(Fix) Ctrl + Shift + Z to redo the last operation:**
  * The layer range is reseted instead of pull the used values
  * Tool - Arithmetic always disabled
  * Action - Layer import didn't generate info and always disabled
2021-02-06 22:09:55 +00:00

235 lines
7.6 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
// https://github.com/cbiffle/catibo/blob/master/doc/cbddlp-ctb.adoc
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using BinarySerialization;
using UVtools.Core.Operations;
namespace UVtools.Core.FileFormats
{
public class MakerbaseFile : FileFormat
{
#region Constants
private const uint MAGIC_CBDDLP = 0x12FD0019;
private const uint MAGIC_CBT = 0x12FD0086;
private const ushort REPEATRGB15MASK = 0x20;
private const byte RLE8EncodingLimit = 0x7d; // 125;
private const ushort RLE16EncodingLimit = 0xFFF;
#endregion
#region Sub Classes
#region Header
public class Header
{
public const string TagValue = "MKSDLP";
//[FieldOrder(0)] public uint Offset1 { get; set; }
/// <summary>
/// Gets the file tag = MKSDLP
/// </summary>
[FieldOrder(0)] [FieldOffset(4)] [FieldLength(6)] public string Tag { get; set; } = TagValue;
[FieldOrder(1)] [FieldOffset(1)] public ushort MaxSize { get; set; }
[FieldOrder(2)] public ushort ResolutionX { get; set; }
[FieldOrder(3)] public ushort ResolutionY { get; set; }
}
#endregion
#endregion
#region Properties
public Header HeaderSettings { get; protected internal set; } = new Header();
private int temp = 0;
public override FileFormatType FileType => FileFormatType.Binary;
public override FileExtension[] FileExtensions { get; } = {
new FileExtension("mdlp", "Makerbase MDLP Files"),
new FileExtension("gr1", "GR1 Workshop GR1 Files"),
};
public override PrintParameterModifier[] PrintParameterModifiers { get; } =
{
PrintParameterModifier.BottomLayerCount,
PrintParameterModifier.BottomExposureSeconds,
PrintParameterModifier.ExposureSeconds,
PrintParameterModifier.BottomLightOffDelay,
PrintParameterModifier.LightOffDelay,
PrintParameterModifier.BottomLiftHeight,
PrintParameterModifier.BottomLiftSpeed,
PrintParameterModifier.LiftHeight,
PrintParameterModifier.LiftSpeed,
PrintParameterModifier.RetractSpeed,
PrintParameterModifier.BottomLightPWM,
PrintParameterModifier.LightPWM,
};
public override byte ThumbnailsCount { get; } = 0;
public override Size[] ThumbnailsOriginalSize { get; } = {new Size(400, 300), new Size(200, 125)};
public override uint ResolutionX
{
get => 0;
set => temp = 0;
}
public override uint ResolutionY
{
get => 0;
set => temp = 0;
}
public override float DisplayWidth { get; set; }
public override float DisplayHeight { get; set; }
public override bool MirrorDisplay { get; set; }
public override byte AntiAliasing
{
get => 1;
set { }
}
public override float LayerHeight
{
get => 0;
set => temp = 0;
}
public override uint LayerCount
{
set
{
temp = 0;
/*HeaderSettings.LayerCount = LayerCount;
HeaderSettings.OverallHeightMilimeter = TotalHeight;*/
}
}
public override ushort BottomLayerCount => 0;
public override float BottomExposureTime => 0;
public override float ExposureTime => 0;
public override float LiftHeight => 0;
public override float LiftSpeed => 0;
public override float RetractSpeed => 0;
public override float PrintTime => 0;
public override float MaterialMilliliters => 0;
public override float MaterialCost => 0;
public override string MaterialName => "Unknown";
public override string MachineName => null;
public override object[] Configs => new[] { (object)HeaderSettings };
#endregion
#region Constructors
public MakerbaseFile()
{
}
#endregion
#region Methods
protected override void EncodeInternally(string fileFullPath, OperationProgress progress)
{
uint currentOffset = (uint)Helpers.Serializer.SizeOf(HeaderSettings);
using (var outputFile = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write))
{
outputFile.Seek((int) currentOffset, SeekOrigin.Begin);
}
Debug.WriteLine("Encode Results:");
Debug.WriteLine(HeaderSettings);
Debug.WriteLine("-End-");
}
protected override void DecodeInternally(string fileFullPath, OperationProgress progress)
{
using (var inputFile = new FileStream(fileFullPath, FileMode.Open, FileAccess.Read))
{
//HeaderSettings = Helpers.ByteToType<CbddlpFile.Header>(InputFile);
//HeaderSettings = Helpers.Serializer.Deserialize<Header>(InputFile.ReadBytes(Helpers.Serializer.SizeOf(typeof(Header))));
HeaderSettings = Helpers.Deserialize<Header>(inputFile);
if (HeaderSettings.Tag != Header.TagValue)
{
throw new FileLoadException("Not a valid Makerfile file!", fileFullPath);
}
}
}
public override void SaveAs(string filePath = null, OperationProgress progress = null)
{
if (RequireFullEncode)
{
if (!string.IsNullOrEmpty(filePath))
{
FileFullPath = filePath;
}
Encode(FileFullPath, progress);
return;
}
if (!string.IsNullOrEmpty(filePath))
{
File.Copy(FileFullPath, filePath, true);
FileFullPath = filePath;
}
/*using (var outputFile = new FileStream(FileFullPath, FileMode.Open, FileAccess.Write))
{
outputFile.Seek(0, SeekOrigin.Begin);
Helpers.SerializeWriteFileStream(outputFile, HeaderSettings);
if (HeaderSettings.Version >= 2 && HeaderSettings.PrintParametersOffsetAddress > 0)
{
outputFile.Seek(HeaderSettings.PrintParametersOffsetAddress, SeekOrigin.Begin);
Helpers.SerializeWriteFileStream(outputFile, PrintParametersSettings);
Helpers.SerializeWriteFileStream(outputFile, SlicerInfoSettings);
}
uint layerOffset = HeaderSettings.LayersDefinitionOffsetAddress;
for (byte aaIndex = 0; aaIndex < HeaderSettings.AntiAliasLevel; aaIndex++)
{
for (uint layerIndex = 0; layerIndex < HeaderSettings.LayerCount; layerIndex++)
{
outputFile.Seek(layerOffset, SeekOrigin.Begin);
layerOffset += Helpers.SerializeWriteFileStream(outputFile, LayersDefinitions[aaIndex, layerIndex]);
}
}
}*/
//Decode(FileFullPath, progress);
}
#endregion
}
}