using Aurora; using Aurora.Api; using Aurora.Api.Manager; using DB; using DB.Recipe; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Windows; using VisionCommon; using WeldingCommon.Sequences; namespace WeldingCommon.Utils { public static class RecipeHelper { public static (int id, string name) SelectedRecipe; static IRecipeManager mRecipeManager = Application.Current.AuroraEnv().RecipeManager; 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 SaveRecipe(string recipeName, bool includeModel = true) { CommonHelper.GetMainPage().SaveRecipe(GetTeachingEditorFullPath(recipeName), includeModel); } public static void OnSaveRecipeForEditing() { if (string.IsNullOrWhiteSpace(SelectedRecipe.name)) { return; } SaveRecipe(SelectedRecipe.name); if (SelectedRecipe.name == mRecipeManager.ActivatedRecipe().Name) { CommonHelper.UpdateAutoRunPage(); } } public static void UpdateAutorunRecipe() { if (string.IsNullOrWhiteSpace(SelectedRecipe.name)) { return; } if (SelectedRecipe.name == mRecipeManager.ActivatedRecipe().Name) { CommonHelper.UpdateAutoRunPage(); } } public static void ReloadRecipe(string recipeName) { var camConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(eCamId.CAM1.ToString()) as CamConfig; CommonHelper.GetMainPage().UpdateDefaultField(camConfig.ChildImage.ChildBufRowCols); CommonHelper.GetMainPage().ReloadRecipe(GetTeachingEditorFullPath(recipeName)); } public static RecipeWeldingLines getRecipeInfo(string recipeName) => CommonHelper.GetMainPage().getRecipeInfo(GetTeachingEditorFullPath(recipeName)); public static void OnActiveReloaded() { var activeRecipe = mRecipeManager.ActivatedRecipe(); SelectedRecipe = (activeRecipe.Id, activeRecipe.Name); ReloadRecipe(activeRecipe.Name); } public static void OnActiveRecipe(int recipeId, string recipeName) { mRecipeManager.ActivateRecipe(recipeId, recipeName); } public static string SearchRecipeItem(int recipeID) { string recipeName = string.Empty; var listRecipe = mRecipeManager.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(() => { ReloadRecipe(SelectedRecipe.name); }); } public static bool OnChangeRecipe(int RecipeID) { IList recipes = mRecipeManager.Recipes(); //list 에서 정보 얻을 수 있는것을 찾아보자 return true; } } }