376 lines
14 KiB
C#
376 lines
14 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using CogCommon;
|
|
using VisionCommon;
|
|
using Cognex.VisionPro;
|
|
using System.Collections.Generic;
|
|
using CogPattern;
|
|
using VisionAligner;
|
|
using Cognex.VisionPro.Display;
|
|
using System.Drawing;
|
|
using System;
|
|
using Cognex.VisionPro.PMAlign;
|
|
using Cognex.VisionPro.Blob;
|
|
using VisionInspector;
|
|
|
|
namespace CogUI {
|
|
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 AddCross(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
Cross cross, string groupName) {
|
|
AddCrossesInternal(cogDisplay, color, new List<Cross>() { cross }, groupName);
|
|
}
|
|
|
|
public static void AddCrosses(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
List<Cross> crosses, string groupName) {
|
|
AddCrossesInternal(cogDisplay, color, crosses, groupName);
|
|
}
|
|
|
|
public static void AddCrossesInternal(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
List<Cross> crosses, string groupName) {
|
|
|
|
if (crosses == null) {
|
|
return;
|
|
}
|
|
foreach (Cross cross in crosses) {
|
|
if (cross == null) {
|
|
continue;
|
|
}
|
|
var cogPointMarker = new CogPointMarker();
|
|
cogPointMarker.Color = color;
|
|
cogPointMarker.SetCenterRotationSize(cross.Origin.X, cross.Origin.Y, cross.Angle.Radian, (int)cross.Length);
|
|
cogDisplay.InteractiveGraphics.Add(cogPointMarker, groupName, false);
|
|
}
|
|
}
|
|
|
|
public static void AddLines(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
List<Line<ImagePoint>> lines, string groupName) {
|
|
foreach (var line in lines) {
|
|
AddLine(cogDisplay, color, line.StartPoint, line.EndPoint, groupName);
|
|
}
|
|
}
|
|
|
|
public static void AddLine(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
ImagePoint startPoint, ImagePoint endPoint, string groupName) {
|
|
|
|
var cogLineSeg = new CogLineSegment();
|
|
cogLineSeg.SetStartEnd(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
|
|
cogLineSeg.Color = color;
|
|
cogLineSeg.LineStyle = CogGraphicLineStyleConstants.Solid;
|
|
cogDisplay.InteractiveGraphics.Add(cogLineSeg, groupName, false);
|
|
}
|
|
|
|
public static void AddVectors(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
ImagePoint startPoint, List<ImagePoint> endPoints, string groupName) {
|
|
|
|
var cogCoordAxes = new CogCoordinateAxes();
|
|
cogCoordAxes.Color = color;
|
|
cogCoordAxes.XAxisLabel.Visible = false;
|
|
cogCoordAxes.YAxisLabel.Visible = false;
|
|
cogCoordAxes.SetOriginCornerXCornerY(startPoint.X, startPoint.Y,
|
|
startPoint.X + endPoints[0].X, startPoint.Y + endPoints[0].Y,
|
|
startPoint.X + endPoints[1].X, startPoint.Y + endPoints[1].Y);
|
|
cogDisplay.InteractiveGraphics.Add(cogCoordAxes, groupName, false);
|
|
}
|
|
|
|
public static void AddRoi(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
ROI roi, string groupName) {
|
|
|
|
var cogRectangleAffine = new CogRectangleAffine();
|
|
cogRectangleAffine.Color = color;
|
|
cogRectangleAffine.SetCenterLengthsRotationSkew(roi.CenterX, roi.CenterY,
|
|
roi.Width, roi.Height,
|
|
roi.Angle.Radian, 0);
|
|
cogDisplay.StaticGraphics.Add(cogRectangleAffine, groupName);
|
|
}
|
|
|
|
public static void AddCircle(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
ImagePoint point, double radius, string groupName) {
|
|
|
|
var cogCircle = new CogCircle();
|
|
cogCircle.Color = color;
|
|
cogCircle.SetCenterRadius(point.X, point.Y, radius);
|
|
cogDisplay.InteractiveGraphics.Add(cogCircle, groupName, false);
|
|
}
|
|
|
|
public static void AddMask(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
CogMaskGraphic maskGraphic, string groupName) {
|
|
|
|
cogDisplay.InteractiveGraphics.Add(maskGraphic, groupName, false);
|
|
}
|
|
|
|
public static void AddTrainEdge(CogDisplay cogDisplay, PatternAgentBase patternAgent, PatternInfo patternInfo) {
|
|
var cogPMAlignTool = patternAgent.GetTool(patternInfo) as CogPMAlignTool;
|
|
if (cogPMAlignTool.Pattern.Trained) {
|
|
AddCogGraphicCollection(
|
|
cogDisplay,
|
|
CogColorConstants.Yellow,
|
|
cogPMAlignTool.Pattern.CreateGraphicsCoarse(CogColorConstants.Yellow), CogConstants.KEY_TRAIN_RESULT);
|
|
AddCogGraphicCollection(
|
|
cogDisplay,
|
|
CogColorConstants.Yellow,
|
|
cogPMAlignTool.Pattern.CreateGraphicsFine(CogColorConstants.Green), CogConstants.KEY_TRAIN_RESULT);
|
|
}
|
|
}
|
|
|
|
public static void AddBlobEdge(CogDisplay cogDisplay, PatternAgentBase patternAgent, PatternInfo patternInfo) {
|
|
var cogBlobTool = patternAgent.GetTool(patternInfo) as CogBlobTool;
|
|
if (cogBlobTool != null) {
|
|
CogBlobResultCollection blobResults = (cogBlobTool.Results as CogBlobResults).GetBlobs();
|
|
|
|
foreach (CogBlobResult cogBlobResult in blobResults) {
|
|
AddCogCompositeShape(
|
|
cogDisplay,
|
|
cogBlobResult.CreateResultGraphics(CogBlobResultGraphicConstants.Boundary), CogConstants.KEY_BLOB);
|
|
AddCogCompositeShape(
|
|
cogDisplay,
|
|
cogBlobResult.CreateResultGraphics(CogBlobResultGraphicConstants.CenterOfMass), CogConstants.KEY_BLOB);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void AddTextList(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
ImagePoint p, List<string> msgs, string groupName) {
|
|
|
|
int lineInterval = 80;
|
|
if (cogDisplay.Image != null) {
|
|
var imageSize = CogEnvironment.GetImageSize(cogDisplay.Image);
|
|
lineInterval = (int)(85 * (imageSize.Height / DEFAULT_IMAGE_HEIGHT));
|
|
}
|
|
|
|
AddTextList(
|
|
cogDisplay,
|
|
color,
|
|
p, msgs, groupName, lineInterval);
|
|
}
|
|
|
|
public static void AddTextList(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
ImagePoint p, List<string> msgs, string groupName, int lineInterval) {
|
|
|
|
int offsetX = 10;
|
|
int offsetY = 80;
|
|
foreach (var msg in msgs) {
|
|
AddText(
|
|
cogDisplay, color,
|
|
new ImagePoint(p.X + offsetX, p.Y + offsetY), msg, groupName);
|
|
offsetY += lineInterval;
|
|
}
|
|
}
|
|
|
|
public static void AddColorTextList(
|
|
CogDisplay cogDisplay,
|
|
ImagePoint p, List<ColorText> colorTextList, string groupName) {
|
|
|
|
int lineInterval = 80;
|
|
if (cogDisplay.Image != null) {
|
|
var imageSize = CogEnvironment.GetImageSize(cogDisplay.Image);
|
|
lineInterval = (int)(60 * (imageSize.Height / DEFAULT_IMAGE_HEIGHT));
|
|
}
|
|
|
|
AddColorTextList(
|
|
cogDisplay,
|
|
p, colorTextList, groupName, lineInterval);
|
|
}
|
|
|
|
public static void AddColorTextList(
|
|
CogDisplay cogDisplay,
|
|
ImagePoint p, List<ColorText> colorTextList, string groupName, int lineInterval) {
|
|
|
|
int offsetY = 0;
|
|
|
|
foreach (var colorText in colorTextList) {
|
|
AddText(
|
|
cogDisplay,
|
|
CogCommon.ColorConverter.ConvertColor(colorText.Color),
|
|
new ImagePoint(p.X, p.Y + offsetY), colorText.Text, groupName);
|
|
offsetY += lineInterval;
|
|
}
|
|
}
|
|
|
|
public static void AddText(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
ImagePoint p, string msg, string groupName) {
|
|
|
|
var label = new CogGraphicLabel();
|
|
label.Alignment = CogGraphicLabelAlignmentConstants.BottomLeft;
|
|
label.Color = color;
|
|
label.Font = new Font("Consolas", 10, System.Drawing.FontStyle.Bold);
|
|
label.SetXYText(p.X, p.Y, msg);
|
|
cogDisplay.InteractiveGraphics.Add(label, groupName, false);
|
|
}
|
|
|
|
public static void AddCogGraphicCollection(
|
|
CogDisplay cogDisplay,
|
|
CogColorConstants color,
|
|
CogGraphicCollection cogGraphicCollection,
|
|
string groupName) {
|
|
|
|
foreach (var gc in cogGraphicCollection) {
|
|
cogDisplay.InteractiveGraphics.Add(gc as ICogGraphicInteractive, groupName, false);
|
|
}
|
|
}
|
|
|
|
public static void AddCogCompositeShape(
|
|
CogDisplay cogDisplay,
|
|
CogCompositeShape cogCompositeShape,
|
|
string groupName) {
|
|
|
|
cogDisplay.InteractiveGraphics.Add(cogCompositeShape, groupName, false);
|
|
}
|
|
|
|
public static void AddInteractiveGraphic(CogDisplay cogDisplay, ICogGraphicInteractive graphicInteractive, string groupName, bool checkForDuplicates) {
|
|
cogDisplay.InteractiveGraphics.Add(graphicInteractive, groupName, checkForDuplicates);
|
|
}
|
|
|
|
public static bool ExistsGetInteractiveGraphic(CogDisplay cogDisplay, string groupName) {
|
|
int index = cogDisplay.InteractiveGraphics.FindItem(groupName, CogDisplayZOrderConstants.Front);
|
|
if (index != -1) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static ICogGraphicInteractive GetInteractiveGraphic(CogDisplay cogDisplay, string groupName) {
|
|
try {
|
|
int index = cogDisplay.InteractiveGraphics.FindItem(groupName, CogDisplayZOrderConstants.Front);
|
|
if (index != -1) {
|
|
return cogDisplay.InteractiveGraphics[index];
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_logger.FuncE(e.Message);
|
|
}
|
|
|
|
_logger.FuncE("{0} does Not exist", groupName);
|
|
return null;
|
|
}
|
|
|
|
public static void RemoveGraphic(CogDisplay cogDisplay, eGraphicToClear graphicToClear, string groupName) {
|
|
switch (graphicToClear) {
|
|
case eGraphicToClear.ALL:
|
|
RemoveInteractiveGraphic(cogDisplay, groupName);
|
|
RemoveStaticGraphic(cogDisplay, groupName);
|
|
break;
|
|
case eGraphicToClear.INTERACTIVE:
|
|
RemoveInteractiveGraphic(cogDisplay, groupName);
|
|
break;
|
|
case eGraphicToClear.STATIC:
|
|
RemoveStaticGraphic(cogDisplay, groupName);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static void RemoveInteractiveGraphic(CogDisplay cogDisplay, string groupName) {
|
|
try {
|
|
int index = cogDisplay.InteractiveGraphics.FindItem(groupName, CogDisplayZOrderConstants.Front);
|
|
if (index != -1) {
|
|
cogDisplay.InteractiveGraphics.Remove(groupName);
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
public static void RemoveStaticGraphic(CogDisplay cogDisplay, string groupName) {
|
|
try {
|
|
foreach (string grpName in cogDisplay.StaticGraphics.ZOrderGroups) {
|
|
if (grpName == groupName) {
|
|
cogDisplay.StaticGraphics.Remove(groupName);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
public static void ClearGraphics(CogDisplay cogDisplay) {
|
|
ClearInteractiveGraphics(cogDisplay);
|
|
ClearStaticGraphics(cogDisplay);
|
|
}
|
|
|
|
public static void ClearInteractiveGraphics(CogDisplay cogDisplay) {
|
|
try {
|
|
cogDisplay.InteractiveGraphics.Clear();
|
|
}
|
|
catch (Exception e) {
|
|
_logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
public static void ClearStaticGraphics(CogDisplay cogDisplay) {
|
|
try {
|
|
cogDisplay.StaticGraphics.Clear();
|
|
}
|
|
catch (Exception e) {
|
|
_logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
public static object GetGraphicColor(AlignStatus alignStatus) {
|
|
var color = GraphicColors.OK;
|
|
switch (alignStatus) {
|
|
case AlignStatus.NOT_FOUND:
|
|
color = GraphicColors.NG;
|
|
break;
|
|
case AlignStatus.ALIGN_LIMIT_OVER:
|
|
color = GraphicColors.Orange;
|
|
break;
|
|
case AlignStatus.RETRY_COUNT_OVER:
|
|
color = GraphicColors.Yellow;
|
|
break;
|
|
case AlignStatus.DISTANCE_NG:
|
|
color = GraphicColors.DarkRed;
|
|
break;
|
|
}
|
|
return color;
|
|
}
|
|
|
|
public static object GetGraphicColor(InspStatus inspStatus) {
|
|
var color = GraphicColors.OK;
|
|
switch (inspStatus) {
|
|
case InspStatus.NG:
|
|
color = GraphicColors.NG;
|
|
break;
|
|
case InspStatus.OK:
|
|
case InspStatus.DRY_RUN_OK:
|
|
color = GraphicColors.OK;
|
|
break;
|
|
}
|
|
return color;
|
|
}
|
|
}
|
|
}
|