2017-08-16 17:13:16 -07:00
|
|
|
|
/*
|
2018-04-19 18:16:14 -07:00
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
2017-08-16 17:13:16 -07:00
|
|
|
|
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;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.Image;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2018-10-10 14:58:03 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
2018-11-24 08:02:03 -08:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
using MatterHackers.MeshVisualizer;
|
|
|
|
|
|
using MatterHackers.PolygonMesh;
|
2021-11-26 12:49:42 -08:00
|
|
|
|
using MatterHackers.PolygonMesh.Processors;
|
2018-04-19 18:16:14 -07:00
|
|
|
|
using MatterHackers.RenderOpenGl;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2018-04-19 14:37:54 -07:00
|
|
|
|
public static class BedMeshGenerator
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
|
|
|
|
|
private static ImageBuffer watermarkImage = null;
|
|
|
|
|
|
|
2018-04-19 14:37:54 -07:00
|
|
|
|
public static ImageBuffer CreatePrintBedImage(PrinterConfig printer)
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageBuffer bedImage;
|
|
|
|
|
|
|
|
|
|
|
|
switch (printer.Bed.BedShape)
|
|
|
|
|
|
{
|
|
|
|
|
|
case BedShape.Rectangular:
|
|
|
|
|
|
bedImage = CreateRectangularBedGridImage(printer);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BedShape.Circular:
|
|
|
|
|
|
bedImage = CreateCircularBedGridImage(printer);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return bedImage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-13 02:13:20 -07:00
|
|
|
|
public static (Mesh bed, Mesh volume) CreatePrintBedAndVolume(PrinterConfig printer)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2020-12-17 07:11:59 -08:00
|
|
|
|
Mesh printerBed;
|
2017-09-20 15:30:35 -07:00
|
|
|
|
Mesh buildVolume = null;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
|
2020-12-17 07:11:59 -08:00
|
|
|
|
var displayVolumeToBuild = Vector3.ComponentMax(printer.Bed.ViewerVolume, new Vector3(1, 1, 1));
|
2017-08-16 17:13:16 -07:00
|
|
|
|
|
2019-04-13 02:13:20 -07:00
|
|
|
|
// Temporarily assign a placeholder image as the mesh texture. This will be replaced with a themed image by the view
|
|
|
|
|
|
var placeHolderImage = new ImageBuffer(5, 5);
|
|
|
|
|
|
var graphics = placeHolderImage.NewGraphics2D();
|
|
|
|
|
|
graphics.Clear(Color.Gray.WithAlpha(40));
|
2017-08-16 17:13:16 -07:00
|
|
|
|
|
2017-09-20 15:30:35 -07:00
|
|
|
|
switch (printer.Bed.BedShape)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
|
|
|
|
|
case BedShape.Rectangular:
|
2017-10-31 12:51:16 -07:00
|
|
|
|
if (displayVolumeToBuild.Z > 0)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
|
|
|
|
|
buildVolume = PlatonicSolids.CreateCube(displayVolumeToBuild);
|
2019-01-11 16:49:34 -08:00
|
|
|
|
for(int i=0; i< buildVolume.Vertices.Count; i++)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2019-01-11 16:49:34 -08:00
|
|
|
|
buildVolume.Vertices[i] = buildVolume.Vertices[i] + new Vector3Float(0, 0, displayVolumeToBuild.Z / 2);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
2019-04-13 02:13:20 -07:00
|
|
|
|
|
2018-04-02 17:43:48 -07:00
|
|
|
|
var bspTree = FaceBspTree.Create(buildVolume);
|
|
|
|
|
|
buildVolume.FaceBspTree = bspTree;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
printerBed = PlatonicSolids.CreateCube(displayVolumeToBuild.X, displayVolumeToBuild.Y, 1.8);
|
2019-04-13 02:13:20 -07:00
|
|
|
|
printerBed.PlaceTextureOnFaces(0, placeHolderImage);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BedShape.Circular:
|
|
|
|
|
|
{
|
2017-10-31 12:51:16 -07:00
|
|
|
|
if (displayVolumeToBuild.Z > 0)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2017-10-31 12:51:16 -07:00
|
|
|
|
buildVolume = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolumeToBuild.X / 2, displayVolumeToBuild.Y / 2), displayVolumeToBuild.Z);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
printerBed = VertexSourceToMesh.Extrude(new Ellipse(new Vector2(), displayVolumeToBuild.X / 2, displayVolumeToBuild.Y / 2), 1.8);
|
2019-04-13 02:13:20 -07:00
|
|
|
|
printerBed.PlaceTextureOnFaces(0, placeHolderImage);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 16:49:34 -08:00
|
|
|
|
var zTop = printerBed.GetAxisAlignedBoundingBox().MaxXYZ.Z;
|
|
|
|
|
|
for (int i = 0; i < printerBed.Vertices.Count; i++)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2019-01-11 16:49:34 -08:00
|
|
|
|
printerBed.Vertices[i] = printerBed.Vertices[i] - new Vector3Float(-printer.Bed.BedCenter, zTop + .02);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buildVolume != null)
|
|
|
|
|
|
{
|
2019-01-11 16:49:34 -08:00
|
|
|
|
for (int i = 0; i < buildVolume.Vertices.Count; i++)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2019-01-11 16:49:34 -08:00
|
|
|
|
buildVolume.Vertices[i] = buildVolume.Vertices[i] - new Vector3Float(-printer.Bed.BedCenter, zTop + .02);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-04-02 17:43:17 -07:00
|
|
|
|
|
2019-04-13 02:13:20 -07:00
|
|
|
|
return (printerBed, buildVolume);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-19 14:37:54 -07:00
|
|
|
|
private static ImageBuffer CreateCircularBedGridImage(PrinterConfig printer)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2020-12-17 07:11:59 -08:00
|
|
|
|
var displayVolumeToBuild = Vector3.ComponentMax(printer.Bed.ViewerVolume, new Vector3(1, 1, 1));
|
2017-12-02 12:54:42 -08:00
|
|
|
|
double sizeForMarking = Math.Max(displayVolumeToBuild.X, displayVolumeToBuild.Y);
|
|
|
|
|
|
double cmPerLine = 10;
|
|
|
|
|
|
int skip = 1;
|
|
|
|
|
|
if (sizeForMarking > 1000)
|
|
|
|
|
|
{
|
|
|
|
|
|
cmPerLine = 100;
|
|
|
|
|
|
skip = 10;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (sizeForMarking > 300)
|
|
|
|
|
|
{
|
|
|
|
|
|
cmPerLine = 50;
|
|
|
|
|
|
skip = 5;
|
|
|
|
|
|
}
|
2017-08-16 17:13:16 -07:00
|
|
|
|
|
2019-04-13 01:54:01 -07:00
|
|
|
|
var theme = AppContext.Theme;
|
2019-04-13 14:49:13 -07:00
|
|
|
|
var bedMarkingsColor = theme.PrinterBedTextColor;
|
2019-04-13 01:54:01 -07:00
|
|
|
|
|
2017-08-16 17:13:16 -07:00
|
|
|
|
var bedplateImage = new ImageBuffer(1024, 1024);
|
|
|
|
|
|
Graphics2D graphics2D = bedplateImage.NewGraphics2D();
|
2019-04-13 01:54:01 -07:00
|
|
|
|
graphics2D.Clear(theme.BedColor);
|
2017-12-02 12:54:42 -08:00
|
|
|
|
|
|
|
|
|
|
var originPixels = new Vector2();
|
|
|
|
|
|
{
|
|
|
|
|
|
double lineSpacePixels = bedplateImage.Width / (displayVolumeToBuild.X / cmPerLine);
|
|
|
|
|
|
|
|
|
|
|
|
double xPositionLines = (-(printer.Bed.ViewerVolume.X / 2.0) + printer.Bed.BedCenter.X) / cmPerLine;
|
|
|
|
|
|
int xPositionCmInt = (int)Math.Round(xPositionLines);
|
|
|
|
|
|
double fraction = xPositionLines - xPositionCmInt;
|
|
|
|
|
|
for (double linePos = lineSpacePixels * (1 - fraction); linePos < bedplateImage.Width; linePos += lineSpacePixels)
|
|
|
|
|
|
{
|
|
|
|
|
|
xPositionCmInt++;
|
|
|
|
|
|
if (xPositionCmInt == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
originPixels.X = linePos;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
double lineDist = bedplateImage.Height / (displayVolumeToBuild.Y / cmPerLine);
|
|
|
|
|
|
|
|
|
|
|
|
double yPositionCm = (-(printer.Bed.ViewerVolume.Y / 2.0) + printer.Bed.BedCenter.Y) / cmPerLine;
|
|
|
|
|
|
int yPositionCmInt = (int)Math.Round(yPositionCm);
|
|
|
|
|
|
double fraction = yPositionCm - yPositionCmInt;
|
|
|
|
|
|
for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Height; linePos += lineDist)
|
|
|
|
|
|
{
|
|
|
|
|
|
yPositionCmInt++;
|
|
|
|
|
|
int linePosInt = (int)linePos;
|
|
|
|
|
|
if (yPositionCmInt == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
originPixels.Y = linePos;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-17 07:11:59 -08:00
|
|
|
|
var bedCircle = new Ellipse(bedplateImage.Width/2, bedplateImage.Height/2, bedplateImage.Width/2, bedplateImage.Height/2);
|
2019-04-13 01:54:01 -07:00
|
|
|
|
graphics2D.Render(bedCircle, theme.BedColor);
|
2018-04-19 14:37:54 -07:00
|
|
|
|
//graphics2D.Clear(bedBaseColor);
|
|
|
|
|
|
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2017-12-02 12:54:42 -08:00
|
|
|
|
double lineSpacePixels = bedplateImage.Width / (displayVolumeToBuild.X / cmPerLine);
|
|
|
|
|
|
|
|
|
|
|
|
double xPositionLines = (-(printer.Bed.ViewerVolume.X / 2.0) + printer.Bed.BedCenter.X) / cmPerLine;
|
|
|
|
|
|
int xPositionCmInt = (int)Math.Round(xPositionLines);
|
|
|
|
|
|
double fraction = xPositionLines - xPositionCmInt;
|
|
|
|
|
|
int pointSize = 20;
|
|
|
|
|
|
graphics2D.DrawString((xPositionCmInt * skip).ToString(), 4, originPixels.Y + 4, pointSize, color: bedMarkingsColor);
|
|
|
|
|
|
for (double linePos = lineSpacePixels * (1 - fraction); linePos < bedplateImage.Width; linePos += lineSpacePixels)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2017-12-02 12:54:42 -08:00
|
|
|
|
xPositionCmInt++;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
int linePosInt = (int)linePos;
|
2017-12-02 12:54:42 -08:00
|
|
|
|
int lineWidth = 1;
|
|
|
|
|
|
if (xPositionCmInt == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lineWidth = 2;
|
|
|
|
|
|
graphics2D.Line(linePosInt, 0, linePosInt, bedplateImage.Height, bedMarkingsColor, lineWidth);
|
|
|
|
|
|
}
|
|
|
|
|
|
graphics2D.DrawString((xPositionCmInt * skip).ToString(), linePos + 4, originPixels.Y + 4, pointSize, color: bedMarkingsColor);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
|
2020-12-17 07:11:59 -08:00
|
|
|
|
var circle = new Ellipse(originPixels, linePos - originPixels.X);
|
|
|
|
|
|
var outline = new Stroke(circle);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
graphics2D.Render(outline, bedMarkingsColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-02 12:54:42 -08:00
|
|
|
|
{
|
|
|
|
|
|
double lineDist = bedplateImage.Height / (displayVolumeToBuild.Y / cmPerLine);
|
|
|
|
|
|
|
|
|
|
|
|
double yPositionCm = (-(printer.Bed.ViewerVolume.Y / 2.0) + printer.Bed.BedCenter.Y) / cmPerLine;
|
|
|
|
|
|
int yPositionCmInt = (int)Math.Round(yPositionCm);
|
|
|
|
|
|
double fraction = yPositionCm - yPositionCmInt;
|
|
|
|
|
|
int pointSize = 20;
|
|
|
|
|
|
for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Height; linePos += lineDist)
|
|
|
|
|
|
{
|
|
|
|
|
|
yPositionCmInt++;
|
|
|
|
|
|
int linePosInt = (int)linePos;
|
|
|
|
|
|
int lineWidth = 1;
|
|
|
|
|
|
if (yPositionCmInt == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lineWidth = 2;
|
|
|
|
|
|
originPixels.Y = linePos;
|
|
|
|
|
|
graphics2D.Line(0, linePosInt, bedplateImage.Height, linePosInt, bedMarkingsColor, lineWidth);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
graphics2D.DrawString((yPositionCmInt * skip).ToString(), originPixels.X + 4, linePos + 4, pointSize, color: bedMarkingsColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-04-19 14:37:54 -07:00
|
|
|
|
|
|
|
|
|
|
ApplyOemBedImage(bedplateImage, printer);
|
|
|
|
|
|
|
2017-08-16 17:13:16 -07:00
|
|
|
|
return bedplateImage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-19 14:37:54 -07:00
|
|
|
|
private static ImageBuffer CreateRectangularBedGridImage(PrinterConfig printer)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2020-12-17 07:11:59 -08:00
|
|
|
|
var displayVolumeToBuild = Vector3.ComponentMax(printer.Bed.ViewerVolume, new Vector3(1, 1, 1));
|
2017-12-02 12:54:42 -08:00
|
|
|
|
double sizeForMarking = Math.Max(displayVolumeToBuild.X, displayVolumeToBuild.Y);
|
|
|
|
|
|
double divisor = 10;
|
|
|
|
|
|
int skip = 1;
|
|
|
|
|
|
if (sizeForMarking > 1000)
|
|
|
|
|
|
{
|
|
|
|
|
|
divisor = 100;
|
|
|
|
|
|
skip = 10;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (sizeForMarking > 300)
|
|
|
|
|
|
{
|
|
|
|
|
|
divisor = 50;
|
|
|
|
|
|
skip = 5;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-13 01:54:01 -07:00
|
|
|
|
var theme = AppContext.Theme;
|
2019-04-13 14:49:13 -07:00
|
|
|
|
var bedMarkingsColor = theme.PrinterBedTextColor;
|
2019-04-13 01:54:01 -07:00
|
|
|
|
|
2017-08-16 17:13:16 -07:00
|
|
|
|
var bedplateImage = new ImageBuffer(1024, 1024);
|
|
|
|
|
|
Graphics2D graphics2D = bedplateImage.NewGraphics2D();
|
2019-04-13 01:54:01 -07:00
|
|
|
|
graphics2D.Clear(theme.BedColor);
|
|
|
|
|
|
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
2017-10-31 12:51:16 -07:00
|
|
|
|
double lineDist = bedplateImage.Width / (displayVolumeToBuild.X / divisor);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
double xPositionCm = (-(printer.Bed.ViewerVolume.X / 2.0) + printer.Bed.BedCenter.X) / divisor;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
int xPositionCmInt = (int)Math.Round(xPositionCm);
|
|
|
|
|
|
double fraction = xPositionCm - xPositionCmInt;
|
|
|
|
|
|
int pointSize = 20;
|
|
|
|
|
|
graphics2D.DrawString((xPositionCmInt * skip).ToString(), 4, 4, pointSize, color: bedMarkingsColor);
|
|
|
|
|
|
for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Width; linePos += lineDist)
|
|
|
|
|
|
{
|
|
|
|
|
|
xPositionCmInt++;
|
|
|
|
|
|
int linePosInt = (int)linePos;
|
|
|
|
|
|
int lineWidth = 1;
|
|
|
|
|
|
if (xPositionCmInt == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lineWidth = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
graphics2D.Line(linePosInt, 0, linePosInt, bedplateImage.Height, bedMarkingsColor, lineWidth);
|
|
|
|
|
|
graphics2D.DrawString((xPositionCmInt * skip).ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
2017-10-31 12:51:16 -07:00
|
|
|
|
double lineDist = bedplateImage.Height / (displayVolumeToBuild.Y / divisor);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
double yPositionCm = (-(printer.Bed.ViewerVolume.Y / 2.0) + printer.Bed.BedCenter.Y) / divisor;
|
2017-08-16 17:13:16 -07:00
|
|
|
|
int yPositionCmInt = (int)Math.Round(yPositionCm);
|
|
|
|
|
|
double fraction = yPositionCm - yPositionCmInt;
|
|
|
|
|
|
int pointSize = 20;
|
|
|
|
|
|
for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Height; linePos += lineDist)
|
|
|
|
|
|
{
|
|
|
|
|
|
yPositionCmInt++;
|
|
|
|
|
|
int linePosInt = (int)linePos;
|
|
|
|
|
|
int lineWidth = 1;
|
|
|
|
|
|
if (yPositionCmInt == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lineWidth = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
graphics2D.Line(0, linePosInt, bedplateImage.Height, linePosInt, bedMarkingsColor, lineWidth);
|
|
|
|
|
|
|
|
|
|
|
|
graphics2D.DrawString((yPositionCmInt * skip).ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-19 14:37:54 -07:00
|
|
|
|
ApplyOemBedImage(bedplateImage, printer);
|
|
|
|
|
|
|
2017-08-16 17:13:16 -07:00
|
|
|
|
return bedplateImage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-19 14:37:54 -07:00
|
|
|
|
private static void ApplyOemBedImage(ImageBuffer bedImage, PrinterConfig printer)
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Add an oem/watermark image to the bedplate grid
|
|
|
|
|
|
string imagePathAndFile = Path.Combine("OEMSettings", "bedimage.png");
|
2020-11-25 07:39:36 -08:00
|
|
|
|
if (StaticData.Instance.FileExists(imagePathAndFile))
|
2017-08-16 17:13:16 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (watermarkImage == null)
|
|
|
|
|
|
{
|
2020-11-25 07:39:36 -08:00
|
|
|
|
watermarkImage = StaticData.Instance.LoadImage(imagePathAndFile);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-22 17:23:49 -08:00
|
|
|
|
var xYRatio = printer.Bed.ViewerVolume.X / Math.Max(1, printer.Bed.ViewerVolume.Y);
|
|
|
|
|
|
var scaledWidth = Math.Max(1, watermarkImage.Width);
|
|
|
|
|
|
var scaledHeight = Math.Max(1, watermarkImage.Height * xYRatio);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
Graphics2D bedGraphics = bedImage.NewGraphics2D();
|
|
|
|
|
|
bedGraphics.Render(
|
2018-04-02 17:43:17 -07:00
|
|
|
|
watermarkImage,
|
2017-08-16 17:13:16 -07:00
|
|
|
|
new Vector2(
|
2018-04-02 17:43:17 -07:00
|
|
|
|
(bedImage.Width - scaledWidth) / 2,
|
2019-02-22 17:23:49 -08:00
|
|
|
|
Math.Max(0, (bedImage.Height - scaledHeight) / 2)),
|
2018-04-02 17:43:17 -07:00
|
|
|
|
scaledWidth, scaledHeight);
|
2017-08-16 17:13:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|