98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api.DataType;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Aurora.Api;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using VisionCalibrator;
|
|
using VisionDirector;
|
|
using Aurora.Api.Devices;
|
|
using System.Threading.Tasks;
|
|
using Aurora.View;
|
|
|
|
namespace MilUI {
|
|
public class MovePositionMode : DisplayMode {
|
|
private readonly object _lockObj = new object();
|
|
private Logger _logger = new Logger(typeof(MovePositionMode).Name);
|
|
private FovInfo _fovInfo;
|
|
private ImageSize _imageSize;
|
|
private ImagePoint _imageCenter;
|
|
private Calibrator _calibrator;
|
|
private MotionDirector _teachingDirector;
|
|
|
|
private bool _isMoving = false;
|
|
|
|
public MovePositionMode(FovInfo fovInfo, ImageSize imageSize) {
|
|
_fovInfo = fovInfo;
|
|
_imageSize = imageSize;
|
|
_imageCenter = new ImagePoint(imageSize.Width * 0.5, imageSize.Height * 0.5);
|
|
_calibrator = CalibratorManager.GetCalibrator(_fovInfo);
|
|
_teachingDirector = TeachingDirectorManager.Instance.GetDirector(fovInfo.ToSubSysInfo());
|
|
}
|
|
|
|
public override void MouseLeftDown(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void MouseMove(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void MouseRightDown(MIL_ID EventID) {
|
|
lock (_lockObj) {
|
|
if (IsMoving()) {
|
|
MessageUtil.ShowErrorToast("Motor is Moving");
|
|
return;
|
|
}
|
|
SetIsMoving(true);
|
|
}
|
|
|
|
var measureImagePoint = GetMousePoint(EventID);
|
|
|
|
if (IsLocatedInImageArea(_imageSize, measureImagePoint)) {
|
|
var referenceStaticPoint = _calibrator.TransformToCalibratedSpace(_imageCenter, _imageSize);
|
|
var measureStaticPoint = _calibrator.TransformToCalibratedSpace(measureImagePoint, _imageSize);
|
|
var moveStaticOffset = referenceStaticPoint - measureStaticPoint;
|
|
var moveMotionOffset = _teachingDirector.ApplyDirection(moveStaticOffset);
|
|
_logger.I($"{measureImagePoint}, {moveStaticOffset}, {moveMotionOffset}");
|
|
RelMove(moveMotionOffset);
|
|
}
|
|
else {
|
|
SetIsMoving(false);
|
|
}
|
|
}
|
|
|
|
private bool IsMoving() {
|
|
lock (_lockObj) {
|
|
return _isMoving;
|
|
}
|
|
}
|
|
|
|
private void SetIsMoving(bool isMovsing) {
|
|
lock (_lockObj) {
|
|
_isMoving = isMovsing;
|
|
}
|
|
}
|
|
|
|
private async void RelMove(DoublePoint moveOffset) {
|
|
await Task.Run(() => {
|
|
EquipAdapter.Instance.TeachingMotionManager.RelMove(_fovInfo, new Position() { X = moveOffset.X, Y = moveOffset.Y });
|
|
SetIsMoving(false);
|
|
});
|
|
}
|
|
|
|
private bool IsLocatedInImageArea(ImageSize imageSize, ImagePoint p) {
|
|
return (0 <= p.X) && (0 <= p.Y) &&
|
|
(p.X < imageSize.Width) && (p.Y < imageSize.Height);
|
|
}
|
|
|
|
public override void GraphicSelectionModified(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void Clear() {
|
|
}
|
|
}
|
|
}
|