mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-12 19:42:32 +02:00
5cfd62d36e
* (Add) Tools can now run inside a ROI (#49) * (Add) Layer preview: Hold-Shift + Left-drag to select an ROI (Region of interest) on image, that region will be used instead of whole image when running some tools * (Add) Layer preview: Hold-Shift + Hold-Alt + Left-drag to select and auto adjust the ROI to the contained objects, that region will be used instead of whole image when running some tools * (Add) Layer preview: Hold-Shift + Right-click on a object to select its bounding area, that region will be used instead of whole image when running some tools * (Add) Layer preview: ESC key to clear ROI * (Add) Layer preview: Overlay text with hints for current action * (Add) Tool - Move: Now possible to do a copy move instead of a cut move * (Add) Arrow wait cursor to progress loadings * (Change) Layer preview: Hold-Shift key to select issues and pick pixel position/brightness changed to Hold-Control key * (Change) Layer preview: Shift+click combination to zoom-in changed to Alt+click * (Fix) CTB v3: Bad file when re-encoding
138 lines
4.8 KiB
C#
138 lines
4.8 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.
|
|
*/
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using UVtools.Core.Objects;
|
|
|
|
namespace UVtools.Core.Operations
|
|
{
|
|
public class OperationMove : Operation
|
|
{
|
|
public override string Title => "Move";
|
|
public override string Description =>
|
|
"Change or copy the position of the model on the build plate.";
|
|
|
|
public override string ConfirmationText =>
|
|
(IsCutMove ? "move" : "copy") + $" model layers {LayerIndexStart} through {LayerIndexEnd} from " +
|
|
$"location {{X={ROI.X},Y={ROI.Y}}} to " +
|
|
$"location {{X={DstRoi.X},Y={DstRoi.Y}}}?";
|
|
|
|
public override string ProgressTitle =>
|
|
(IsCutMove ? "Moving" : "Copying") +$" model to {{X={DstRoi.X},Y={DstRoi.Y}}}";
|
|
|
|
public override string ProgressAction => (IsCutMove ? "Moved" : "Copied")+" layers";
|
|
|
|
public override StringTag Validate(params object[] parameters)
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
if (!ValidateBounds())
|
|
{
|
|
sb.AppendLine("Your parameters will put the model outside of build plate. Please adjust the location and margins.");
|
|
}
|
|
|
|
return new StringTag(sb.ToString());
|
|
}
|
|
|
|
private Rectangle _dstRoi = Rectangle.Empty;
|
|
public Rectangle DstRoi
|
|
{
|
|
get
|
|
{
|
|
if(!_dstRoi.IsEmpty) return _dstRoi;
|
|
CalculateDstRoi();
|
|
|
|
return _dstRoi;
|
|
}
|
|
}
|
|
|
|
public void CalculateDstRoi()
|
|
{
|
|
_dstRoi.Size = ROI.Size;
|
|
|
|
switch (Anchor)
|
|
{
|
|
case Enumerations.Anchor.TopLeft:
|
|
_dstRoi.Location = new Point(0, 0);
|
|
break;
|
|
case Enumerations.Anchor.TopCenter:
|
|
_dstRoi.Location = new Point((int)(ImageWidth / 2 - ROI.Width / 2), 0);
|
|
break;
|
|
case Enumerations.Anchor.TopRight:
|
|
_dstRoi.Location = new Point((int)(ImageWidth - ROI.Width), 0);
|
|
break;
|
|
case Enumerations.Anchor.MiddleLeft:
|
|
_dstRoi.Location = new Point(0, (int)(ImageHeight / 2 - ROI.Height / 2));
|
|
break;
|
|
case Enumerations.Anchor.MiddleCenter:
|
|
//case Anchor.None:
|
|
_dstRoi.Location = new Point((int)(ImageWidth / 2 - ROI.Width / 2), (int)(ImageHeight / 2 - ROI.Height / 2));
|
|
break;
|
|
case Enumerations.Anchor.MiddleRight:
|
|
_dstRoi.Location = new Point((int)(ImageWidth - ROI.Width), (int)(ImageHeight / 2 - ROI.Height / 2));
|
|
break;
|
|
case Enumerations.Anchor.BottomLeft:
|
|
_dstRoi.Location = new Point(0, (int)(ImageHeight - ROI.Height));
|
|
break;
|
|
case Enumerations.Anchor.BottomCenter:
|
|
_dstRoi.Location = new Point((int)(ImageWidth / 2 - ROI.Width / 2), (int)(ImageHeight - ROI.Height));
|
|
break;
|
|
case Enumerations.Anchor.BottomRight:
|
|
_dstRoi.Location = new Point((int)(ImageWidth - ROI.Width), (int)(ImageHeight - ROI.Height));
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
_dstRoi.X += MarginLeft;
|
|
_dstRoi.X -= MarginRight;
|
|
_dstRoi.Y += MarginTop;
|
|
_dstRoi.Y -= MarginBottom;
|
|
}
|
|
|
|
|
|
public uint ImageWidth { get; set; }
|
|
public uint ImageHeight { get; set; }
|
|
|
|
public Enumerations.Anchor Anchor { get; set; }
|
|
|
|
public int MarginLeft { get; set; } = 0;
|
|
public int MarginTop { get; set; } = 0;
|
|
public int MarginRight { get; set; } = 0;
|
|
public int MarginBottom { get; set; } = 0;
|
|
|
|
public bool IsCutMove { get; set; } = true;
|
|
|
|
public OperationMove()
|
|
{
|
|
}
|
|
|
|
public OperationMove(Rectangle srcRoi, uint imageWidth = 0, uint imageHeight = 0, Enumerations.Anchor anchor = Enumerations.Anchor.MiddleCenter)
|
|
{
|
|
ROI = srcRoi;
|
|
ImageWidth = imageWidth;
|
|
ImageHeight = imageHeight;
|
|
Anchor = anchor;
|
|
}
|
|
|
|
|
|
|
|
public bool ValidateBounds()
|
|
{
|
|
CalculateDstRoi();
|
|
if (DstRoi.X < 0) return false;
|
|
if (DstRoi.Y < 0) return false;
|
|
if (DstRoi.Right > ImageWidth) return false;
|
|
if (DstRoi.Bottom > ImageHeight) return false;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|