- [Line.cs] LargeMOTFPositionX/Y 프로퍼티 추가 ([XmlSerializable]) - [DrawingLayer.cs] LargeMOTFOffsetX/Y 프로퍼티 추가 ([XmlSerializable]) - [RecipeWeldingLines.cs] UseLargeMOTF, LargeMOTFPageCount 프로퍼티 추가 ([XmlSerializable]) - Load() 에 XmlUtil.ParseProperties() 추가하여 로드 시 반영 - [MainPage.cs] - UpdateLargeMOTFPosition() 추가: 저장 직전 Layer별 마지막 Line PF2를 LargeMOTFPositionX/Y에 자동 SET - OnRecipeReloaded 이벤트 추가: 레시피 로드 완료 시 콜백 - GenerateFlippedPages() 추가: EndSet 시 Page3(P2 Y플립), Page4(P1 Y플립) 자동 생성 - [UCScannerObjectTeachingViewModel.cs] - OnSaved(): UpdateLargeMOTFPosition, UseLargeMOTF/LargeMOTFPageCount 저장 직전 반영 - OnChanged(), Reloaded(): 레시피 로드 시 IsUseLargeMOTF, LargeMOTFPageCount UI 반영 - 생성자: OnRecipeReloaded 이벤트 등록하여 프로그램 시작 시 UI 반영 - [UCScannerObjectTeachingControlBoxViewModel.cs] - PerformCmdLargeMOTFEndSet(): LargeMOTFOffsetX 계산 후 GenerateFlippedPages() 호출 - OnRecipeReloaded 시 LargeMOTFOffsetX UI 반영 (Layer[1] 기준)
371 lines
12 KiB
C#
371 lines
12 KiB
C#
|
|
using AuroraLaser;
|
|
using CoreUnit.Common;
|
|
using CoreUnit.Control.UserControl.Canvas;
|
|
using CoreUnit.Scanner.UserControl.ScannerCanvas;
|
|
using Microsoft.Office.Interop.Excel;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using System.Xml;
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
|
|
|
|
namespace DB.Recipe
|
|
{
|
|
// 설명 추가 : XML 기반 저장/로딩 구조 - XmlUtil.WriteProperties 프로퍼티를 자동을 저장하는 방식이라서 프로퍼티만 추가하면 된다고 한다.
|
|
// XmlUtil.WriteProperties(this, wr) 가 this의 프로퍼티를 자동 직렬화 하니깐 Save() / Load() 수정 없이 프로퍼티 추가만으로 XML에 자동 저장 / 로딩되는 형태
|
|
|
|
public class RecipeWeldingLines : Recipe
|
|
{
|
|
|
|
#region 26.04.09 NDY
|
|
// 26.04.09 NDY [대면적 MOTF] 레시피 레벨 파라미터 추가 - 04.10 [XmlSerializable] 추가함.
|
|
[XmlSerializable]
|
|
public bool UseLargeMOTF { get; set; } = false;
|
|
[XmlSerializable]
|
|
public int LargeMOTFPageCount { get; set; } = 1;
|
|
#endregion
|
|
|
|
DataModel m_model;
|
|
public DataModel Model
|
|
{
|
|
get { lock (this) { return m_model; } }
|
|
set { lock (this) { m_model = value; } }
|
|
}
|
|
|
|
public LaserPowerCalibrationParam laserPowerCalibrationParam = new LaserPowerCalibrationParam();
|
|
|
|
List<PowerProfile> m_powerProfiles = new List<PowerProfile>();
|
|
|
|
public List<PowerProfile> PowerProfiles
|
|
{
|
|
get { lock (this) { return m_powerProfiles; } }
|
|
set { lock (this) { m_powerProfiles = value; } }
|
|
}
|
|
|
|
|
|
|
|
// 생성자
|
|
public RecipeWeldingLines()
|
|
{
|
|
}
|
|
#region 메서드 영역
|
|
public void Reset()
|
|
{
|
|
}
|
|
|
|
public override void Save(XmlWriter wr, bool includeModel)
|
|
{
|
|
try
|
|
{
|
|
XmlUtil.WriteProperties(this, wr);
|
|
SaveWeldingParam(wr);
|
|
if (includeModel) Model.Save(wr);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
UtilUnit.logUnit.SetLog(LogUnit.eLogType.ALARM, MethodBase.GetCurrentMethod().Name, ex.Message);
|
|
}
|
|
}
|
|
|
|
public override string Save()
|
|
{
|
|
string jsonString = string.Empty;
|
|
var options = new JsonSerializerOptions { WriteIndented = true };
|
|
try
|
|
{
|
|
jsonString += JsonSerializer.Serialize(ScannerCanvasUserCtrl.ScannerParams, options);
|
|
jsonString += Model.Save();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
UtilUnit.logUnit.SetLog(LogUnit.eLogType.ALARM, MethodBase.GetCurrentMethod().Name, ex.Message);
|
|
}
|
|
return jsonString;
|
|
}
|
|
|
|
public override void Load(XmlElement xmlElement)
|
|
{
|
|
try
|
|
{
|
|
#region 26.04.10 NDY [대면적 MOTF] 레시피 레벨 파라미터 로드
|
|
CoreUnit.Common.XmlUtil.ParseProperties(xmlElement, this);
|
|
#endregion
|
|
LoadWeldingParam(xmlElement); // WeldingParameters만 로드
|
|
Model.Load(xmlElement); // DrawingObjects만 로드
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
UtilUnit.logUnit.SetLog(LogUnit.eLogType.ALARM, MethodBase.GetCurrentMethod().Name, ex.Message);
|
|
}
|
|
}
|
|
|
|
public override void SubLoad(string fileName)
|
|
{
|
|
var options = new JsonSerializerOptions() { WriteIndented = true };
|
|
ScannerCanvasUserCtrl.ScannerParams = JsonSerializer.Deserialize<List<ScannerParam>>(fileName, options);
|
|
}
|
|
|
|
private void SaveWeldingParam(XmlWriter wr)
|
|
{
|
|
#region 1.Scanner Objects에 대한 데이터 저장
|
|
wr.WriteStartElement("WeldingParameters");
|
|
wr.WriteStartElement("items");
|
|
foreach (ScannerParam param in ScannerCanvasUserCtrl.ScannerParams)
|
|
{
|
|
wr.WriteStartElement("WeldingParameter");
|
|
CoreUnit.Common.XmlUtil.WriteProperties(param, wr);
|
|
wr.WriteEndElement();
|
|
}
|
|
wr.WriteEndElement();
|
|
wr.WriteEndElement();
|
|
#endregion
|
|
}
|
|
|
|
private void LoadWeldingParam(XmlElement root)
|
|
{
|
|
try
|
|
{
|
|
ScannerCanvasUserCtrl.ScannerParams.Clear();
|
|
|
|
int paramNo = 0;
|
|
foreach (XmlElement node in root.ChildNodes)
|
|
{
|
|
if (node.Name == "WeldingParameters")
|
|
{
|
|
#region 1.Scanner Objects에 대한 데이터 로딩
|
|
foreach (XmlElement subNode in node.ChildNodes)
|
|
{
|
|
if (subNode.Name == "items")
|
|
{
|
|
//ScannerCanvasUserCtrl.ScannerParams.Clear();
|
|
|
|
foreach (XmlElement itemNode in subNode.ChildNodes)
|
|
{
|
|
ScannerParam param = new ScannerParam();
|
|
CoreUnit.Common.XmlUtil.ParseProperties(itemNode, param);
|
|
param.No = paramNo;
|
|
paramNo++;
|
|
ScannerCanvasUserCtrl.ScannerParams.Add((ScannerParam)param);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
if (ScannerCanvasUserCtrl.ScannerParams.Count < 128)
|
|
{
|
|
CreateScannerParams();
|
|
}
|
|
|
|
for (int i = 0; i < ScannerCanvasUserCtrl.ScannerParams.Count; i++)
|
|
{
|
|
WeldingParameterIDEditor.UpdateColorList(i, ScannerCanvasUserCtrl.ScannerParams[i].Color);
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
public void CreateScannerParams()
|
|
{
|
|
ScannerCanvasUserCtrl.ScannerParams.Clear();
|
|
|
|
for (int i = 0; i < 128; i++)
|
|
{
|
|
ScannerParam param = new ScannerParam();
|
|
param.No = i;
|
|
ScannerCanvasUserCtrl.ScannerParams.Add(param);
|
|
}
|
|
}
|
|
|
|
private void AddPowerProfile()
|
|
{
|
|
PowerProfile powerProfile = new PowerProfile();
|
|
m_powerProfiles.Add(powerProfile);
|
|
}
|
|
|
|
public void LoadPowerProfile(string fileName)
|
|
{
|
|
// 사용하지 않으므로 주석 처리
|
|
//try
|
|
//{
|
|
// FileInfo fi = new FileInfo(fileName);
|
|
|
|
// StreamReader sr = new StreamReader(fileName);
|
|
// XmlDocument doc = new XmlDocument();
|
|
// doc.Load(sr);
|
|
// sr.Dispose();
|
|
|
|
// XmlElement root = doc.DocumentElement;
|
|
|
|
// m_powerProfiles.Clear();
|
|
// foreach (XmlElement node in root.ChildNodes)
|
|
// {
|
|
// if (node.Name == "PowerProfile")
|
|
// {
|
|
// PowerProfile profile = new PowerProfile();
|
|
|
|
// foreach (XmlElement childnode in node.ChildNodes)
|
|
// {
|
|
// PowerProfile.PowerProfileParam param = new PowerProfile.PowerProfileParam();
|
|
|
|
// CoreUnit.Common.XmlUtil.ParseProperties(childnode, param);
|
|
|
|
// profile.PowerProfileParams.Add(param);
|
|
// }
|
|
|
|
// m_powerProfiles.Add(profile);
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// throw ex;
|
|
//}
|
|
}
|
|
|
|
public void SavePowerProfile(string fileName)
|
|
{
|
|
// 사용하지 않으므로 주석 처리
|
|
//try
|
|
//{
|
|
// XmlTextWriter wr = new XmlTextWriter(fileName, null);
|
|
// wr.Formatting = Formatting.Indented;
|
|
// wr.WriteStartElement("PowerProfileList");
|
|
|
|
// foreach (PowerProfile powerProfile in m_powerProfiles)
|
|
// {
|
|
// wr.WriteStartElement("PowerProfile");
|
|
// foreach(PowerProfile.PowerProfileParam param in powerProfile.PowerProfileParams)
|
|
// {
|
|
// wr.WriteStartElement("PowerProfileParam");
|
|
// CoreUnit.Common.XmlUtil.WriteProperties(param, wr);
|
|
// wr.WriteEndElement();
|
|
// }
|
|
// wr.WriteEndElement();
|
|
// }
|
|
|
|
// wr.WriteEndElement();
|
|
|
|
// wr.Close();
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// throw ex;
|
|
//}
|
|
}
|
|
|
|
#region Data Readonly
|
|
public List<ScannerParam> ReadOnlyScanParams { get; private set; }
|
|
public void LoadFileReadOnly(string fileName)
|
|
{
|
|
try
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
var extenstion = Path.GetExtension(fileName);
|
|
if (extenstion == ".json")
|
|
{
|
|
|
|
var jsonString = File.ReadAllText(fileName);
|
|
|
|
doc = JsonConvert.DeserializeXmlNode(jsonString, "RecipeBody");
|
|
|
|
}
|
|
else
|
|
{
|
|
FileInfo fi = new FileInfo(fileName);
|
|
StreamReader sr = new StreamReader(fileName);
|
|
doc.Load(sr);
|
|
sr.Dispose();
|
|
}
|
|
|
|
XmlElement root = doc.DocumentElement;
|
|
|
|
foreach (XmlElement childnode in root.ChildNodes)
|
|
{
|
|
foreach (Recipe recipe in recipeList)
|
|
{
|
|
if (childnode.Name == recipe.GetType().Name)
|
|
{
|
|
recipe.LoadReadOnly(childnode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public override void LoadReadOnly(XmlElement xmlElement)
|
|
{
|
|
try
|
|
{
|
|
ReadOnlyScanParams = LoadWeldingParamReadOnly(xmlElement);
|
|
if (Model is null)
|
|
Model = new DataModel();
|
|
|
|
Model.Load(xmlElement);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
UtilUnit.logUnit.SetLog(LogUnit.eLogType.ALARM, MethodBase.GetCurrentMethod().Name, ex.Message);
|
|
}
|
|
}
|
|
|
|
private List<ScannerParam> LoadWeldingParamReadOnly(XmlElement root)
|
|
{
|
|
try
|
|
{
|
|
List<ScannerParam> weldingParam = new List<ScannerParam>();
|
|
weldingParam.Clear();
|
|
|
|
int paramNo = 0;
|
|
foreach (XmlElement node in root.ChildNodes)
|
|
{
|
|
if (node.Name == "WeldingParameters")
|
|
{
|
|
#region 1.Scanner Objects에 대한 데이터 로딩
|
|
foreach (XmlElement subNode in node.ChildNodes)
|
|
{
|
|
if (subNode.Name == "items")
|
|
{
|
|
foreach (XmlElement itemNode in subNode.ChildNodes)
|
|
{
|
|
ScannerParam param = new ScannerParam();
|
|
CoreUnit.Common.XmlUtil.ParseProperties(itemNode, param);
|
|
param.No = paramNo;
|
|
paramNo++;
|
|
weldingParam.Add((ScannerParam)param);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
return weldingParam;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
} |