Use Interlock ON 시 ① 안전구역 게이트(기존) 유지 + ② 레시피별 방향 차단(신규). Recipe 폴더의 Recipe_Laser_Interlock.json(Front/Down 0/1)에 저장하고, 경로는 FieldHelper.json과 동일 소스(DB.Dao.SystemRecipe.WorkRecipeFile) 사용. Auto/Manual 양쪽 적용(Manual은 ①+② 신규), VM 체크박스는 레시피 전환 시 Background 우선순위 재로드로 stale 방지. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using DB;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace WeldingCommon.Settings
|
|
{
|
|
// 레시피별 Laser 방향(Front/Down) 발진 차단 체크값.
|
|
// 활성 레시피 폴더의 Recipe_Laser_Interlock.json 에 저장/로드한다.
|
|
// 경로 소스는 FieldHelper.json 과 동일한 DB.Dao.SystemRecipe.WorkRecipeFile 을 사용해
|
|
// 같은 레시피 폴더에 떨어지도록 보장한다.
|
|
public class RecipeLaserInterlock
|
|
{
|
|
public bool Front { get; set; } // json 1=true(차단) / 0=false
|
|
public bool Down { get; set; }
|
|
|
|
private const string FileName = "Recipe_Laser_Interlock.json";
|
|
private const string WrapperKey = "Laser Interlock";
|
|
|
|
// 활성 레시피 폴더의 Recipe_Laser_Interlock.json 전체 경로.
|
|
// (FieldHelper.json 과 동일 소스/폴더. 파일명만 치환)
|
|
public static string GetActiveFilePath()
|
|
{
|
|
string recipeFile = DB.Dao.SystemRecipe.WorkRecipeFile;
|
|
if (string.IsNullOrEmpty(recipeFile))
|
|
{
|
|
return null;
|
|
}
|
|
return recipeFile.Replace(Path.GetFileName(recipeFile), FileName);
|
|
}
|
|
|
|
// 파일이 없거나 파싱 실패 시 기본값(Front=false, Down=false) = 차단 없음.
|
|
public static RecipeLaserInterlock Load()
|
|
{
|
|
var result = new RecipeLaserInterlock();
|
|
try
|
|
{
|
|
string path = GetActiveFilePath();
|
|
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
var root = JObject.Parse(File.ReadAllText(path));
|
|
var node = root[WrapperKey];
|
|
if (node != null)
|
|
{
|
|
result.Front = (node["Front"]?.Value<int>() ?? 0) == 1;
|
|
result.Down = (node["Down"]?.Value<int>() ?? 0) == 1;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// 손상/파싱 실패 → 기본값(차단 없음) 반환
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static void Save(RecipeLaserInterlock value)
|
|
{
|
|
string path = GetActiveFilePath();
|
|
if (string.IsNullOrEmpty(path))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var root = new JObject
|
|
{
|
|
[WrapperKey] = new JObject
|
|
{
|
|
["Front"] = value.Front ? 1 : 0,
|
|
["Down"] = value.Down ? 1 : 0,
|
|
}
|
|
};
|
|
File.WriteAllText(path, root.ToString(Formatting.Indented));
|
|
}
|
|
}
|
|
}
|