403 lines
17 KiB
C#
403 lines
17 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.DataType;
|
|
using MilCommon;
|
|
using VisionCommon;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using MilPattern;
|
|
using VisionAligner;
|
|
using VisionInspector;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
|
|
namespace MilUI {
|
|
public static class DisplayDrawer {
|
|
private static Logger _logger = new Logger("DisplayDrawer");
|
|
private const double DEFAULT_IMAGE_WIDTH = 2500.0;
|
|
private const double DEFAULT_IMAGE_HEIGHT = 2500.0;
|
|
|
|
public static void DrawStrReadResult(
|
|
MIL_ID displayId, MIL_ID resultContextId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MilGraphics milGraphics, ROI roi) {
|
|
|
|
double ulPosX = 0;
|
|
double ulPosY = 0;
|
|
MIL.MstrGetResult(resultContextId, MIL.M_DEFAULT, MIL.M_STRING_BOX_UL_X, ref ulPosX);
|
|
MIL.MstrGetResult(resultContextId, MIL.M_DEFAULT, MIL.M_STRING_BOX_UL_Y, ref ulPosY);
|
|
|
|
var offsetX = roi.Left + ulPosX - 1; // 픽셀 오프셋이 있어야 그래픽이 정확히 들어 맞는다.. 그래픽 오차가 큰 이유를 모르겠음..
|
|
var offsetY = roi.Top + ulPosY - 3;
|
|
MIL_ID label = MIL.M_NULL;
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
|
|
// M_DRAW_STRING_CONTOUR
|
|
MIL.MgraColor(graphicContext, MIL.M_COLOR_BLUE);
|
|
MIL.MstrDraw(graphicContext, resultContextId, graphicListId, MIL.M_DRAW_STRING_CONTOUR, MIL.M_ALL, MIL.M_DEFAULT);
|
|
|
|
MIL.MgraInquireList(graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref label);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_X, -offsetX);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_Y, -offsetY);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
|
|
// M_DRAW_STRING
|
|
MIL.MgraColor(graphicContext, MIL.M_COLOR_GREEN);
|
|
MIL.MstrDraw(graphicContext, resultContextId, graphicListId, MIL.M_DRAW_STRING, MIL.M_ALL, MIL.M_DEFAULT);
|
|
//MIL.MstrDraw(graphicContext, resultContextId, graphicListId, MIL.M_DRAW_STRING + MIL.M_DRAW_STRING_BOX, MIL.M_ALL, MIL.M_DEFAULT);
|
|
|
|
MIL.MgraInquireList(graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref label);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_X, -offsetX);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_Y, -offsetY);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void DrawOcrReadResult(
|
|
MIL_ID displayId, MIL_ID resultContextId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MilGraphics milGraphics, ROI roi) {
|
|
|
|
double ulPosX = 0;
|
|
double ulPosY = 0;
|
|
MIL.MstrGetResult(resultContextId, MIL.M_DEFAULT, MIL.M_STRING_BOX_UL_X, ref ulPosX);
|
|
MIL.MstrGetResult(resultContextId, MIL.M_DEFAULT, MIL.M_STRING_BOX_UL_Y, ref ulPosY);
|
|
|
|
var offsetX = roi.Left + ulPosX;
|
|
var offsetY = roi.Top + ulPosY;
|
|
MIL_ID label = MIL.M_NULL;
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
|
|
// M_DRAW_STRING_CHAR_BOX
|
|
MIL.MgraColor(graphicContext, MIL.M_COLOR_GREEN);
|
|
MIL.MocrDraw(graphicContext, resultContextId, graphicListId, MIL.M_DRAW_STRING_CHAR_BOX, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_DEFAULT);
|
|
|
|
MIL.MgraInquireList(graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref label);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_X, -offsetX);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_Y, -offsetY);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
|
|
// M_DRAW_STRING_CHAR_POSITION
|
|
MIL.MgraColor(graphicContext, MIL.M_COLOR_BLUE);
|
|
MIL.MocrDraw(graphicContext, resultContextId, graphicListId, MIL.M_DRAW_STRING_CHAR_POSITION, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_DEFAULT);
|
|
|
|
MIL.MgraInquireList(graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref label);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_X, -offsetX);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_Y, -offsetY);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void AddPatternEdge(
|
|
MIL_ID displayId, MIL_ID resultContextId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MilGraphics milGraphics, ROI roi) {
|
|
|
|
var offsetX = roi.Left;
|
|
var offsetY = roi.Top;
|
|
MIL_ID label = MIL.M_NULL;
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
|
|
MIL_INT color = MIL.M_COLOR_DARK_GREEN;
|
|
MIL.MgraColor(graphicContext, color);
|
|
|
|
MIL.MmodDraw(graphicContext, resultContextId, graphicListId, MIL.M_DRAW_EDGES, MIL.M_DEFAULT, MIL.M_DEFAULT);
|
|
|
|
MIL.MgraInquireList(graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref label);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_X, -offsetX);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(label), MIL.M_DEFAULT, MIL.M_DRAW_OFFSET_Y, -offsetY);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void AddCross(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics,
|
|
Cross cross) {
|
|
AddCrossesInternal(displayId, graphicContext, graphicListId, color, milGraphics, new List<Cross>() { cross });
|
|
}
|
|
|
|
public static void AddCrosses(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics,
|
|
List<Cross> crosses) {
|
|
AddCrossesInternal(displayId, graphicContext, graphicListId, color, milGraphics, crosses);
|
|
}
|
|
|
|
private static void AddCrossesInternal(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics,
|
|
List<Cross> crosses) {
|
|
|
|
if (crosses == null) {
|
|
return;
|
|
}
|
|
var lines = new List<Line<ImagePoint>>();
|
|
for (int i = 0; i < crosses.Count; i++) {
|
|
var cross = crosses[i];
|
|
if (cross == null) {
|
|
continue;
|
|
}
|
|
lines.Add(cross.VerticalLine);
|
|
lines.Add(cross.HorizontalLine);
|
|
}
|
|
|
|
AddLines(displayId, graphicContext, graphicListId, color, milGraphics, lines);
|
|
}
|
|
|
|
public static void AddLine(
|
|
MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics,
|
|
Line<ImagePoint> line, bool isEditable) {
|
|
|
|
MIL_ID graphicLabel = MIL.M_NULL;
|
|
MIL.MgraColor(graphicContext, color);
|
|
MIL.MgraLine(graphicContext, graphicListId, line.StartPoint.X, line.StartPoint.Y, line.EndPoint.X, line.EndPoint.Y);
|
|
MIL.MgraInquireList(graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref graphicLabel);
|
|
SetEditable(graphicListId, graphicLabel, isEditable);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
}
|
|
|
|
public static void AddLines(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics,
|
|
List<Line<ImagePoint>> lines) {
|
|
|
|
double[] pStartX = lines.Select(p => p.StartPoint.X).ToArray();
|
|
double[] pStartY = lines.Select(p => p.StartPoint.Y).ToArray();
|
|
double[] pEndX = lines.Select(p => p.EndPoint.X).ToArray();
|
|
double[] pEndY = lines.Select(p => p.EndPoint.Y).ToArray();
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
|
|
MIL.MgraColor(graphicContext, color);
|
|
MIL.MgraLines(graphicContext, graphicListId, lines.Count, pStartX, pStartY, pEndX, pEndY, MIL.M_LINE_LIST);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void AddVectors(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics,
|
|
List<Line<ImagePoint>> lines,
|
|
bool drawTail) {
|
|
|
|
// Head
|
|
double[] pStartX = lines.Select(line => line.StartPoint.X).ToArray();
|
|
double[] pStartY = lines.Select(line => line.StartPoint.Y).ToArray();
|
|
double[] pEndX = lines.Select(line => (line.EndPoint - line.StartPoint).X).ToArray();
|
|
double[] pEndY = lines.Select(line => (line.EndPoint - line.StartPoint).Y).ToArray();
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
|
|
MIL.MgraColor(graphicContext, color);
|
|
MIL.MgraVectors(
|
|
graphicContext, graphicListId, lines.Count, pStartX, pStartY, pEndX, pEndY,
|
|
MIL.M_AUTO, MIL.M_DEFAULT, MIL.M_PROPORTIONAL_ARROWHEADS);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
|
|
// Tail
|
|
if (drawTail) {
|
|
pStartX = lines.Select(line => line.EndPoint.X).ToArray();
|
|
pStartY = lines.Select(line => line.EndPoint.Y).ToArray();
|
|
pEndX = lines.Select(line => (line.StartPoint - line.EndPoint).X).ToArray();
|
|
pEndY = lines.Select(line => (line.StartPoint - line.EndPoint).Y).ToArray();
|
|
|
|
MIL.MgraColor(graphicContext, color);
|
|
MIL.MgraVectors(
|
|
graphicContext, graphicListId, lines.Count, pStartX, pStartY, pEndX, pEndY,
|
|
MIL.M_AUTO, MIL.M_DEFAULT, MIL.M_PROPORTIONAL_ARROWHEADS);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
}
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void AddRoi(
|
|
MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics, ROI findRoi, bool isEditable) {
|
|
MIL_ID graphicLabel = MIL.M_NULL;
|
|
|
|
MIL.MgraColor(graphicContext, color);
|
|
MIL.MgraRectAngle(
|
|
graphicContext,
|
|
graphicListId,
|
|
findRoi.CenterX,
|
|
findRoi.CenterY,
|
|
findRoi.Width,
|
|
findRoi.Height,
|
|
findRoi.Angle.Degree,
|
|
MIL.M_CENTER_AND_DIMENSION);
|
|
|
|
MIL.MgraInquireList(graphicListId, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_LAST_LABEL, ref graphicLabel);
|
|
SetEditable(graphicListId, graphicLabel, isEditable);
|
|
milGraphics.Add();
|
|
}
|
|
|
|
public static void AddPatternResultDots(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics, List<ImagePoint> dots) {
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
MIL.MgraColor(graphicContext, color);
|
|
foreach (var dot in dots) {
|
|
MIL.MgraDot(graphicContext, graphicListId, dot.X, dot.Y);
|
|
milGraphics.Add();
|
|
}
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void AddTextList(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics, ImageSize imageSize,
|
|
ImagePoint p, List<string> msgs) {
|
|
int lineInterval = (int)(85 * (imageSize.Height / DEFAULT_IMAGE_HEIGHT));
|
|
AddTextList(
|
|
displayId, graphicContext, graphicListId,
|
|
color, milGraphics, imageSize,
|
|
p, msgs, lineInterval);
|
|
}
|
|
|
|
public static void AddTextList(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics, ImageSize imageSize,
|
|
ImagePoint p, List<string> msgs, int lineInterval) {
|
|
int offsetY = 0;
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
foreach (var msg in msgs) {
|
|
AddText(
|
|
graphicContext, graphicListId,
|
|
color, milGraphics, imageSize,
|
|
new ImagePoint(p.X, p.Y + offsetY), msg);
|
|
offsetY += lineInterval;
|
|
}
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void AddColorTextList(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MilGraphics milGraphics, ImageSize imageSize,
|
|
ImagePoint p, List<ColorText> colorTextList) {
|
|
int lineInterval = (int)(60 * (imageSize.Height / DEFAULT_IMAGE_HEIGHT));
|
|
AddColorTextList(
|
|
displayId, graphicContext, graphicListId,
|
|
milGraphics, imageSize,
|
|
p, colorTextList, lineInterval);
|
|
}
|
|
|
|
public static void AddColorTextList(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MilGraphics milGraphics, ImageSize imageSize,
|
|
ImagePoint p, List<ColorText> colorTextList, int lineInterval) {
|
|
int offsetY = 0;
|
|
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_DISABLE);
|
|
foreach (var colorText in colorTextList) {
|
|
AddText(
|
|
graphicContext, graphicListId,
|
|
ColorConverter.ConvertColor(colorText.Color),
|
|
milGraphics, imageSize,
|
|
new ImagePoint(p.X, p.Y + offsetY), colorText.Text);
|
|
offsetY += lineInterval;
|
|
}
|
|
MIL.MdispControl(displayId, MIL.M_UPDATE_GRAPHIC_LIST, MIL.M_ENABLE);
|
|
}
|
|
|
|
public static void AddText(
|
|
MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics, ImageSize imageSize,
|
|
ImagePoint p, string msg) {
|
|
MIL.MgraControl(graphicContext, MIL.M_BACKGROUND_MODE, MIL.M_TRANSPARENT);
|
|
MIL.MgraColor(graphicContext, color);
|
|
MIL.MgraText(graphicContext, graphicListId, p.X, p.Y, msg);
|
|
|
|
if (milGraphics != null) {
|
|
milGraphics.Add();
|
|
}
|
|
}
|
|
|
|
public static void SetFontScale(MIL_ID graphicContext, ImageSize imageSize) {
|
|
var xScale = imageSize.Width / DEFAULT_IMAGE_WIDTH;
|
|
xScale = (xScale < 1.0) ? 1.0 : xScale;
|
|
var yScale = imageSize.Height / DEFAULT_IMAGE_HEIGHT;
|
|
yScale = (yScale < 1.0) ? 1.0 : yScale;
|
|
|
|
MIL.MgraControl(graphicContext, MIL.M_FONT_X_SCALE, xScale);
|
|
MIL.MgraControl(graphicContext, MIL.M_FONT_Y_SCALE, yScale);
|
|
}
|
|
|
|
private static void SetEditable(MIL_ID graphicListId, MIL_ID graphicLabel, bool isEditable) {
|
|
if (isEditable) {
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_EDITABLE, MIL.M_ENABLE);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_SELECTABLE, MIL.M_ENABLE);
|
|
}
|
|
else {
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_EDITABLE, MIL.M_DISABLE);
|
|
MIL.MgraControlList(graphicListId, MIL.M_GRAPHIC_LABEL(graphicLabel), MIL.M_DEFAULT, MIL.M_SELECTABLE, MIL.M_DISABLE);
|
|
|
|
}
|
|
}
|
|
|
|
public static eColor GetGraphicColor(AlignStatus alignStatus) {
|
|
var color = eColor.Green;
|
|
switch (alignStatus) {
|
|
case AlignStatus.NOT_FOUND:
|
|
color = eColor.Red;
|
|
break;
|
|
case AlignStatus.ALIGN_LIMIT_OVER:
|
|
color = eColor.Orange;
|
|
break;
|
|
case AlignStatus.RETRY_COUNT_OVER:
|
|
color = eColor.Yellow;
|
|
break;
|
|
case AlignStatus.DISTANCE_NG:
|
|
color = eColor.DarkRed;
|
|
break;
|
|
}
|
|
return color;
|
|
}
|
|
|
|
public static eColor GetGraphicColor(InspStatus inspStatus) {
|
|
var color = eColor.Green;
|
|
switch (inspStatus) {
|
|
case InspStatus.NG:
|
|
color = eColor.Red;
|
|
break;
|
|
}
|
|
return color;
|
|
}
|
|
}
|
|
}
|