184 lines
6.4 KiB
C#
184 lines
6.4 KiB
C#
using Aurora;
|
|
using Aurora.Api.Manager;
|
|
using CoreUnit.Control.UserControl.Canvas;
|
|
using CoreUnit.Scanner.UserControl.ScannerCanvas;
|
|
using DB;
|
|
using GUI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using VisionCommon;
|
|
|
|
namespace WeldingCommon.Recipes
|
|
{
|
|
public static class WeldingRecipeManager
|
|
{
|
|
public static (int id, string name) SelectedRecipe;
|
|
private static IRecipeManager _AuroraRecipeManager = Application.Current.AuroraEnv().RecipeManager;
|
|
|
|
#region LASA MAinPage Handler && Contorl Recipe
|
|
private class WeldingMainPage
|
|
{
|
|
private static MainPage _Instance;
|
|
public static MainPage Instance {
|
|
get {
|
|
if (_Instance == null) {
|
|
_Instance = new GUI.MainPage() {
|
|
IsMdiContainer = false,
|
|
TopLevel = false,
|
|
};
|
|
}
|
|
return _Instance;
|
|
}
|
|
}
|
|
}
|
|
public static MainPage GetWeldingPage()
|
|
{
|
|
var rtn = WeldingMainPage.Instance;
|
|
return rtn;
|
|
}
|
|
public static void UpdateAutoRunWeldingPage()
|
|
{
|
|
WeldingMainPage.Instance.UpdateAutoRunPage();
|
|
}
|
|
public static void SaveWeldingRecipe(string recipeName, bool includeModel = true)
|
|
{
|
|
WeldingMainPage.Instance.SaveRecipe(GetTeachingEditorFullPath(recipeName), includeModel);
|
|
}
|
|
public static void ReloadWeldingRecipe(string recipeName)
|
|
{
|
|
WeldingMainPage.Instance.ReloadRecipe(GetTeachingEditorFullPath(recipeName));
|
|
}
|
|
private static string GetTeachingEditorFullPath(string recipeName)
|
|
{
|
|
var recipePath = ConfigurationManager.AppSettings.Get("DATA_PATH");
|
|
var fullPath = Path.Combine(
|
|
recipePath,
|
|
RecipeExIds.RECIPE_DIR,
|
|
recipeName,
|
|
RecipeExIds.TEACHING_EDITOR_RECIPE);
|
|
var dir = Path.GetDirectoryName(fullPath);
|
|
if (!Directory.Exists(dir)) {
|
|
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
|
|
}
|
|
return fullPath;
|
|
}
|
|
public static void UpdateRecipeView()
|
|
{
|
|
WeldingMainPage.Instance.ScannerCanvasCtrlTeaching.Update();
|
|
WeldingMainPage.Instance.UpdateObjetsInTreeView();
|
|
}
|
|
|
|
public static void OnSaveRecipeForEditing()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(SelectedRecipe.name)) {
|
|
return;
|
|
}
|
|
|
|
SaveWeldingRecipe(SelectedRecipe.name);
|
|
|
|
if (SelectedRecipe.name == _AuroraRecipeManager.ActivatedRecipe().Name) {
|
|
UpdateAutoRunWeldingPage();
|
|
}
|
|
}
|
|
|
|
public static void OnActiveReloaded()
|
|
{
|
|
var activeRecipe = _AuroraRecipeManager.ActivatedRecipe();
|
|
ReloadWeldingRecipe(activeRecipe.Name);
|
|
}
|
|
|
|
public static void OnActiveRecipe(int recipeId, string recipeName)
|
|
{
|
|
_AuroraRecipeManager.ActivateRecipe(recipeId, recipeName);
|
|
}
|
|
|
|
public static string SearchRecipeItem(int recipeID)
|
|
{
|
|
string recipeName = string.Empty;
|
|
var listRecipe = _AuroraRecipeManager.Recipes();
|
|
|
|
// Find the recipe with the matching ID
|
|
var recipe = listRecipe.FirstOrDefault(r => r.Id == recipeID);
|
|
|
|
// If a recipe is found, assign its name to recipeName
|
|
if (recipe != null) {
|
|
recipeName = recipe.Name;
|
|
}
|
|
|
|
return recipeName;
|
|
}
|
|
|
|
//LASA는 Recipe를 1개만 사용 할 수 있음
|
|
//TechingRecipe -> ActiavatedReicpe(AutoRun) -> TeachingRecipe
|
|
//AutoRun 완료 후 다시 Teching 중인 Recipe로 Rollback 해줘야 함
|
|
public static void RollbackRecipe()
|
|
{
|
|
Application.Current.Dispatcher.InvokeAsync(() => {
|
|
ReloadWeldingRecipe(SelectedRecipe.name);
|
|
});
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Welding Object && Welding Parameter Handler
|
|
public static int GetWeldingLayerLength()
|
|
{
|
|
var layersLength = WeldingMainPage.Instance.ScannerCanvasCtrlTeaching.Model.Layers.Length;
|
|
return layersLength;
|
|
}
|
|
public static List<IDrawObject> GetWeldingLayerObjects(int layerIdx = 0)
|
|
{
|
|
var layerObjectList = WeldingMainPage.Instance.ScannerCanvasCtrlTeaching.Model.Layers[layerIdx].Objects;
|
|
return layerObjectList;
|
|
}
|
|
public static List<IDrawObject> GetWeldingActivateLayerObjects()
|
|
{
|
|
var layerObjectList = WeldingMainPage.Instance.ScannerCanvasCtrlTeaching.Model.ActiveLayer.Objects;
|
|
return layerObjectList;
|
|
}
|
|
public static ScannerParam GetScannerParam(int index)
|
|
{
|
|
var scannerParam = ScannerCanvasUserCtrl.ScannerParams[index];
|
|
return scannerParam;
|
|
}
|
|
public static ScannerParam GetScannerParam(IDrawObject obj)
|
|
{
|
|
var scannerParam = ScannerCanvasUserCtrl.ScannerParams[obj.ScannerParamID - 1];
|
|
return scannerParam;
|
|
}
|
|
#endregion
|
|
|
|
#region FieldScanParameter Handler
|
|
public static ChildBufRowCol GetFieldScanParam(int scoutNo)
|
|
{
|
|
var camConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(eCamId.CAM1.ToString()) as CamConfig;
|
|
var rtn = camConfig.ChildImage.ChildBufRowCols[scoutNo];
|
|
return rtn;
|
|
}
|
|
public static bool CheckFieldScanEnable(int scoutNo)
|
|
{
|
|
var rtn = GetFieldScanParam(scoutNo).Enabled;
|
|
return rtn;
|
|
}
|
|
public static double GetCorrectionScannerXPos(int scoutNo)
|
|
{
|
|
var scannerPos = GetFieldScanParam(scoutNo).MotorPos.X;
|
|
var offsetPos = GetFieldScanParam(scoutNo).MotorPosOffset.X;
|
|
return scannerPos + offsetPos;
|
|
}
|
|
public static double GetCorrectionScannerYPos(int scoutNo)
|
|
{
|
|
var scannerPos = GetFieldScanParam(scoutNo).MotorPos.Y;
|
|
var offsetPos = GetFieldScanParam(scoutNo).MotorPosOffset.Y;
|
|
return scannerPos + offsetPos;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|