123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.View.Common;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using Microsoft.VisualBasic;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Xml;
- using Venus_Core;
- using Venus_Core.Attributes;
- using Venus_MainPages.PMs;
- using Venus_MainPages.Unity;
- using Venus_MainPages.Views;
- using Venus_Themes.UserControls;
- using WPF.Themes.UserControls;
- using MessageBox = System.Windows.MessageBox;
- using RecipeStep = Venus_Core.RecipeStep;
- namespace Venus_MainPages.ViewModels
- {
- internal class RecipeViewModel : BindableBase
- {
- #region 私有字段
- public string ModuleName = "PMA";
- private string m_CurrentRecipeName;
- private UiRecipeManager m_uiRecipeManager = new UiRecipeManager();
- private RecipeView recipeView;
- private TreeView treeViewRcpList;
- private Recipe m_currentRecipe;
- private string m_recipeType;
- private bool firstLoad = true;
- private WrapPanel headWrapPanel;
- private int copyIndex = -1;
- private List<string> EPDCfgList = new List<string>();
- private EPDType currentEPDType = EPDType.None;
- private JetChamber currentChamber;
- private bool isInstalledEPD;
- private bool m_IsFrozen;
- private bool m_PMAIsInstalled;
- private bool m_PMBIsInstalled;
- private bool m_PMCIsInstalled;
- private bool m_PMDIsInstalled;
- private List<string> moduleList = new List<string>();
- TreeViewFileItem selectedItem;
- private string typeFolder = "";
- private bool m_HeadExpand = true;
- private Grid leftGrid;
- private Grid rightGrid;
- private int controlHeight = 24;
- #endregion
- #region 属性
- public bool HeadExpand
- {
- get { return m_HeadExpand; }
- set { SetProperty(ref m_HeadExpand, value); }
- }
- public string CurrentRecipeName
- {
- get { return m_CurrentRecipeName; }
- set { SetProperty(ref m_CurrentRecipeName, value); }
- }
- public Recipe CurrentRecipe
- {
- get { return m_currentRecipe; }
- set
- {
- m_currentRecipe = value;
- RecipeType = m_currentRecipe?.Header?.Type.ToString();
- }
- }
- public string RecipeType
- {
- get { return m_recipeType; }
- set { SetProperty(ref m_recipeType, value); }
- }
- public bool IsFrozen
- {
- get { return m_IsFrozen; }
- set { SetProperty(ref m_IsFrozen, value); }
- }
- public bool PMAIsInstalled
- {
- get { return m_PMAIsInstalled; }
- set { SetProperty(ref m_PMAIsInstalled, value); }
- }
- public bool PMBIsInstalled
- {
- get { return m_PMBIsInstalled; }
- set { SetProperty(ref m_PMBIsInstalled, value); }
- }
- public bool PMCIsInstalled
- {
- get { return m_PMCIsInstalled; }
- set { SetProperty(ref m_PMCIsInstalled, value); }
- }
- public bool PMDIsInstalled
- {
- get { return m_PMDIsInstalled; }
- set { SetProperty(ref m_PMDIsInstalled, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand<Object> _MouseRightButtonDownCommand;
- public DelegateCommand<Object> MouseRightButtonDownCommand =>
- _MouseRightButtonDownCommand ?? (_MouseRightButtonDownCommand = new DelegateCommand<Object>(OnMouseRightButtonDown));
- private DelegateCommand<Object> _LoadedCommand;
- public DelegateCommand<Object> LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand<Object>(OnLoaded));
- private DelegateCommand _SaveRecipeCommand;
- public DelegateCommand SaveRecipeCommand =>
- _SaveRecipeCommand ?? (_SaveRecipeCommand = new DelegateCommand(OnSaveRecipe));
- private DelegateCommand<object> _SaveToRecipeCommand;
- public DelegateCommand<object> SaveToRecipeCommand =>
- _SaveToRecipeCommand ?? (_SaveToRecipeCommand = new DelegateCommand<object>(OnSaveToRecipe));
- private DelegateCommand _AddStepCommand;
- public DelegateCommand AddStepCommand =>
- _AddStepCommand ?? (_AddStepCommand = new DelegateCommand(OnAddStep));
- private DelegateCommand _DeleteStepCommand;
- public DelegateCommand DeleteStepCommand =>
- _DeleteStepCommand ?? (_DeleteStepCommand = new DelegateCommand(OnDeleteStep));
- private DelegateCommand _RefreshCommand;
- public DelegateCommand RefreshCommand =>
- _RefreshCommand ?? (_RefreshCommand = new DelegateCommand(OnRefresh));
- private DelegateCommand _ExpandCommand;
- public DelegateCommand ExpandCommand =>
- _ExpandCommand ?? (_ExpandCommand = new DelegateCommand(OnExpand));
- private DelegateCommand _UnloadCommand;
- public DelegateCommand UnloadCommand =>
- _UnloadCommand ?? (_UnloadCommand = new DelegateCommand(OnUnload));
- private DelegateCommand _ClearRecipeCommand;
- public DelegateCommand ClearRecipeCommand =>
- _ClearRecipeCommand ?? (_ClearRecipeCommand = new DelegateCommand(OnClearRecipe));
- private DelegateCommand<Object> _MouseLeftButtonDownCommand;
- public DelegateCommand<Object> MouseLeftButtonDownCommand =>
- _MouseLeftButtonDownCommand ?? (_MouseLeftButtonDownCommand = new DelegateCommand<Object>(OnMouseLeftButtonDown));
- #endregion
- #region 命令方法
- private void OnAddStep()
- {
- if (CurrentRecipe != null)
- {
- var index = rightGrid.ColumnDefinitions.Count;
- RecipeStep recipeStep;
- if (copyIndex == -1)
- {
- recipeStep = new RecipeStep();
- recipeStep.StepNo = index + 1;
- if(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.WaferSize").ToString() == "8")
- recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type, 8);
- else
- recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
- CurrentRecipe.Steps.Add(recipeStep);
- }
- else
- {
- var t = JsonConvert.SerializeObject(CurrentRecipe);
- recipeStep = Recipe.Load(t).Steps[copyIndex - 1];
- recipeStep.StepNo = index + 1;
- CurrentRecipe.Steps.Add(recipeStep);
- }
- ColumnDefinition col1 = new ColumnDefinition();
- col1.Width = GridLength.Auto;
- rightGrid.ColumnDefinitions.Insert(index, col1);
- RecipeStepToGridColumn(recipeStep, rightGrid, index);
- }
- }
- private void OnDeleteStep()
- {
- if (CurrentRecipe != null)
- {
- OnDeleteStep(CurrentRecipe.Steps.Count - 1);
- }
- }
- private void OnSaveRecipe()
- {
- if (WPFMessageBox.ShowQuestion($"Save recipe file?", "") == MessageBoxResult.Yes)
- {
- var inUseRecipe = QueryDataClient.Instance.Service.GetData($"Scheduler.InUsingRecipe");
- if (inUseRecipe != null)
- {
- if ((inUseRecipe as List<string>).Contains($"{ModuleName}.{CurrentRecipe.Header.Type}.{CurrentRecipeName}"))
- {
- WPFMessageBox.ShowError($"{CurrentRecipeName} Recipe is In Use,can not edit");
- return;
- }
- }
- }
- CurrentRecipe.Header.EditTime = DateTime.Now.ToString();
- //SaveRecipe(CurrentRecipeName, RecipeUnity.RecipeToString(CurrentRecipe));
- var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
- FileInfo fi = new FileInfo(newrecipePath);
- var di = fi.Directory;
- if (!di.Exists)
- {
- di.Create();
- }
- //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(CurrentRecipe),Encoding.UTF8);
- string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
- for (int index = 0; index < CurrentRecipe.Steps.Count; index++)
- {
- if (CurrentRecipe.Steps[index].Type == StepType.OverEtch)
- {
- if (index == 0)
- {
- WPFMessageBox.ShowError($"{CurrentRecipeName} Recipe has first item type is OverEtch");
- return;
- }
- if (CurrentRecipe.Steps[index - 1].Type != StepType.EndPoint)
- {
- WPFMessageBox.ShowError($"{CurrentRecipeName} Recipe contains steps not EndPoint before OverEtch");
- return;
- }
- }
- }
- SaveRecipe(CurrentRecipe.Header.Name, CurrentRecipe.Header.Type.ToString(), recipeContent);
- //LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
- SaveEAPRecipe(recipeContent, CurrentRecipe.Steps);
- }
- private void SaveEAPRecipe(string recipeContent, ObservableCollection<RecipeStep> Steps)
- {
- if (currentChamber == JetChamber.Kepler2200A || currentChamber == JetChamber.Kepler2200B)
- {
- var newrecipePath2 = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{typeFolder}_EAP", CurrentRecipeName + ".rcp");
- FileInfo fi2 = new FileInfo(newrecipePath2);
- var di2 = fi2.Directory;
- if (!di2.Exists)
- {
- di2.Create();
- }
- var newContent = Recipe.ShowEAPRecipe(recipeContent, CurrentRecipe.Steps);
- File.WriteAllText(newrecipePath2, newContent, Encoding.UTF8);
- }
- }
- private void OnSaveToRecipe(object obj)
- {
- if (CurrentRecipe == null)
- {
- return;
- }
- string moduleName = "";
- switch (obj.ToString())
- {
- case "0":
- moduleName = "PMA";
- break;
- case "1":
- moduleName = "PMB";
- break;
- case "2":
- moduleName = "PMC";
- break;
- case "3":
- moduleName = "PMD";
- break;
- case "4":
- moduleName = "ALL";
- break;
- }
- if (moduleName == "")
- {
- return;
- }
- if (moduleName == "ALL")
- {
- var newName = Interaction.InputBox(" ", $"Save Recipe To All", CurrentRecipeName, -1, -1);
- OnSaveRecipe();
- foreach (var x in moduleList)
- {
- if (newName != "")
- {
- var targetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{x}.ChamberType").ToString());
- if (currentChamber != targetChamber || x == ModuleName)
- {
- continue;
- }
- var newRecipe = CurrentRecipe;
- newRecipe.Header.Name = newName;
- newRecipe.Header.CreateTime = DateTime.Now.ToString();
- var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", x, typeFolder, newName + ".rcp");
- FileInfo fi = new FileInfo(newrecipePath);
- var di = fi.Directory;
- if (!di.Exists)
- {
- di.Create();
- }
- //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
- if (m_uiRecipeManager.SaveAsRecipeWithType(x, CurrentRecipe.Header.Type.ToString(), newName, RecipeUnity.RecipeToString(newRecipe)))
- {
- UpdateRecipeFileList();
- }
- UpdateRecipeFileList();
- }
- }
- }
- else
- {
- var targetChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{moduleName}.ChamberType").ToString());
- if (currentChamber != targetChamber)
- {
- WPFMessageBox.ShowError($"Recipe can not from {currentChamber.ToString()} copy to {targetChamber.ToString()}");
- return;
- }
- var newName = Interaction.InputBox(" ", $"Save Recipe To {moduleName}", CurrentRecipeName, -1, -1);
- if (newName != "")
- {
- OnSaveRecipe();
- var newRecipe = CurrentRecipe;
- newRecipe.Header.Name = newName;
- newRecipe.Header.CreateTime = DateTime.Now.ToString();
- var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", moduleName, typeFolder, newName + ".rcp");
- FileInfo fi = new FileInfo(newrecipePath);
- var di = fi.Directory;
- if (!di.Exists)
- {
- di.Create();
- }
- //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
- if (m_uiRecipeManager.SaveAsRecipeWithType(moduleName, CurrentRecipe.Header.Type.ToString(), newName, RecipeUnity.RecipeToString(newRecipe)))
- {
- UpdateRecipeFileList();
- }
- //if (SaveAsRecipeWithType(newName, CurrentRecipe.Header.Type.ToString(), RecipeUnity.RecipeToString(newRecipe)))
- //{
- //}
- }
- }
- }
- private async void OnLoaded(Object myrecipeView)
- {
- if (firstLoad == true)
- {
- currentChamber = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
- if (currentChamber != JetChamber.Kepler2200A && currentChamber != JetChamber.Kepler2200B)
- {
- isInstalledEPD = bool.Parse(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.IsEnabled").ToString());
- }
- firstLoad = false;
- recipeView = myrecipeView as RecipeView;
- treeViewRcpList = recipeView.treeViewRcpList;
- headWrapPanel = recipeView.headWrapPanel;
- //bodyStackPanel = recipeView.bodyStackPanel;
- leftGrid = recipeView.leftGrid;
- rightGrid = recipeView.rightGrid;
- UpdateRecipeFileList();
- treeViewRcpList.SelectedItemChanged += TreeViewRcpList_SelectedItemChanged;
- string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString();
- if (allModules.Contains("PMA"))
- {
- PMAIsInstalled = true;
- moduleList.Add("PMA");
- }
- if (allModules.Contains("PMB"))
- {
- PMBIsInstalled = true;
- moduleList.Add("PMB");
- }
- if (allModules.Contains("PMC"))
- {
- PMCIsInstalled = true;
- moduleList.Add("PMC");
- }
- if (allModules.Contains("PMD"))
- {
- PMDIsInstalled = true;
- moduleList.Add("PMD");
- }
- }
- if (isInstalledEPD)
- {
- for (int i = 0; i < 5; i++)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EndPoint.SearchCfg");
- await Task.Delay(200);
- currentEPDType = (EPDType)System.Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.EPD.EPDType"));
- if (currentEPDType == EPDType.Socket)
- {
- EPDCfgList = (List<string>)QueryDataClient.Instance.Service.GetData($"{ModuleName}.EPDCfgList");
- }
- if (EPDCfgList != null)
- {
- EPDCfgList.Add("");
- break;
- }
- }
- }
- UpdateRecipeFileList();
- }
- private void TreeViewRcpList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- //rightGrid.Visibility = Visibility.Visible;
- selectedItem = e.NewValue as TreeViewFileItem;
- if (selectedItem == null)
- return;
- try
- {
- string[] info = selectedItem.FileName.Split('\\');
- //string path;
- string xmlRecipeData = "";
- if (info.Length == 1)
- {
- CurrentRecipeName = info[0];
- typeFolder = "";
- string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, $"{CurrentRecipeName}.rcp");
- xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
- }
- else if (info.Length == 2)
- {
- string type = info[0];
- typeFolder = type;
- CurrentRecipeName = info[1];
- string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, type, $"{CurrentRecipeName}.rcp");
- xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
- }
- else
- {
- return;
- }
- if (xmlRecipeData == "")
- {
- treeViewRcpList.Items.Remove(selectedItem);
- return;
- }
- CurrentRecipe = Recipe.Load(xmlRecipeData);
- if (CurrentRecipe.Header.ChamberType != currentChamber)
- {
- WPFMessageBox.ShowError($"Can not Open {CurrentRecipe.Header.ChamberType} Recipe in {currentChamber} Chamber,please delete it.");
- return;
- }
- LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
- LoadRecipe(CurrentRecipe);
- }
- catch (Exception ex)
- {
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- e.Handled = true;
- }
- public bool SaveRecipe(string recipeName, string type, string recipeContent)
- {
- return m_uiRecipeManager.SaveRecipeWithType(ModuleName, type, recipeName, recipeContent);
- }
- private void OnMouseRightButtonDown(Object treeView)
- {
- //treeViewRcpList = treeView as TreeView;
- treeViewRcpList.ContextMenu = new ContextMenu() { Background = new SolidColorBrush(Colors.AliceBlue) };
- MenuItem menuItem = new MenuItem();
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_CreateRecipe);
- menuItem.Header = "New Recipe";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_DeleteRecipe);
- menuItem.Header = "Delete Recipe";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_SaveAsRecipe);
- menuItem.Header = "Save As Recipe";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.Tag = "\\";
- menuItem.Click += new RoutedEventHandler(menuItem_MouseClick_RenameRecipe);
- menuItem.Header = "Rename";
- treeViewRcpList.ContextMenu.Items.Add(menuItem);
- treeViewRcpList.ContextMenu.Visibility = Visibility.Visible;
- }
- private void OnMouseLeftButtonDown(Object treeView)
- {
- //treeViewRcpList = treeView as TreeView;
- }
- private void menuItem_MouseClick_CreateRecipe(object sender, RoutedEventArgs e)
- {
- MenuItem mit = sender as MenuItem;
- string folderName = mit.Tag as string;
- PerformCreateRecipe(folderName);
- }
- private void PerformCreateRecipe(string folderName)
- {
- try
- {
- bool hasHV = false;
- if (currentChamber == JetChamber.VenusSE || currentChamber == JetChamber.VenusDE)
- {
- hasHV = true;
- }
- //RecipeNameInputDlg dlg = new RecipeNameInputDlg(Application.Current.Resources["GlobalLableMsgInputRecipeName"].ToString(), hasHV)
- RecipeNameInputDlg dlg = new RecipeNameInputDlg("Input Recipe Name", hasHV)
- {
- Owner = Application.Current.MainWindow
- };
- if (dlg.ShowDialog() == true)
- {
- var recipeName = dlg.InputText;
- //var recipeName = folderName + dlg.InputText;
- //var recipeName = folderName + "\\" + dlg.InputText;
- if (!RecipeNameIsOk(recipeName))
- {
- return;
- }
- RecipeType type = (RecipeType)Enum.Parse(typeof(RecipeType), dlg.SelectedType);
- //string newRecipe = RecipeUnity.CreateRecipe(currentChamber, type, dlg.InputText);
- string newRecipe = RecipeUnity.CreateRecipe(currentChamber, type, dlg.InputText, GlobalUser.Instance.User.Name);
- if (QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.WaferSize").ToString() == "8")
- newRecipe = RecipeUnity.CreateRecipe(currentChamber, type, dlg.InputText, GlobalUser.Instance.User.Name, 8);
- else
- newRecipe = RecipeUnity.CreateRecipe(currentChamber, type, dlg.InputText, GlobalUser.Instance.User.Name);
- if (SaveAsRecipeWithType(recipeName, type.ToString(), newRecipe))
- {
- UpdateRecipeFileList();
- }
- }
- }
- catch (Exception ex)
- {
- LOG.WriteExeption(ex);
- MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableMsgRecipeCreateException"].ToString(), ex.Message), Application.Current.Resources["GlobalLableTitleRecipeEditor"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void menuItem_MouseClick_DeleteRecipe(object sender, RoutedEventArgs e)
- {
- //if (CurrentRecipe == null)
- //{
- // return;
- //}
- if (WPFMessageBox.ShowQuestion($"Delete {typeFolder}Recipe {CurrentRecipeName}?", "删除后无法恢复!!!") == MessageBoxResult.Yes)
- {
- MenuItem mit = sender as MenuItem;
- //string recipename = mit.Header.ToString();
- string path = typeFolder == "" ? CurrentRecipeName : $"{typeFolder}\\{CurrentRecipeName}";
- m_uiRecipeManager.DeleteRecipe(ModuleName, path);
- //PerformCreateRecipe(folderName);
- //treeViewRcpList.Items.Remove(selectedItem);
- UpdateRecipeFileList();
- }
- }
- private void menuItem_MouseClick_SaveAsRecipe(object sender, RoutedEventArgs e)
- {
- if (CurrentRecipe == null)
- {
- return;
- }
- var newName = Interaction.InputBox(" ", "Save As Recipe", CurrentRecipeName, -1, -1);
- if (!RecipeNameIsOk(newName))
- {
- return;
- }
- //newName = newName.Trim();
- if (newName != CurrentRecipeName && newName != "")
- {
- var newRecipe = CurrentRecipe;
- if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
- {
- //MessageBox.Show($"Save as recipe {newName} ?", "Save As Recipe", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
- newRecipe.Header.Name = newName;
- newRecipe.Header.CreateTime = DateTime.Now.ToString();
- //var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
- //File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
- if (SaveAsRecipeWithType(newName, CurrentRecipe.Header.Type.ToString(), RecipeUnity.RecipeToString(newRecipe)))
- {
- UpdateRecipeFileList();
- CurrentRecipeName = newName;
- //LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
- LoadRecipe(CurrentRecipe);
- }
- }
- }
- else if (newName == CurrentRecipeName || newName == "")
- {
- WPFMessageBox.Show("Please input right recipename", MessageBoxButton.OK);
- }
- }
- private void menuItem_MouseClick_RenameRecipe(object sender, RoutedEventArgs e)
- {
- if (CurrentRecipe == null)
- {
- return;
- }
- var newName = Interaction.InputBox(" ", "Rename Recipe", CurrentRecipeName, -1, -1);
- //newName = newName.Trim();
- if (!RecipeNameIsOk(newName))
- {
- return;
- }
- if (newName != CurrentRecipeName && newName != "")
- {
- var newRecipe = CurrentRecipe;
- if (WPFMessageBox.ShowQuestion($"Save recipe file {newName} ?", "") == MessageBoxResult.Yes)
- {
- newRecipe.Header.Name = newName;
- newRecipe.Header.CreateTime = DateTime.Now.ToString();
- var oldrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, CurrentRecipeName + ".rcp");
- var newrecipePath = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, newName + ".rcp");
- File.Delete(oldrecipePath);
- File.WriteAllText(newrecipePath, RecipeUnity.RecipeToString(newRecipe));
- UpdateRecipeFileList();
- }
- }
- else if (newName == CurrentRecipeName || newName == "")
- {
- WPFMessageBox.Show("Please input right recipename", MessageBoxButton.OK);
- }
- }
- public bool SaveAsRecipeWithType(string recipeName, string type, string recipeContent)
- {
- return m_uiRecipeManager.SaveAsRecipeWithType(ModuleName, type, recipeName, recipeContent);
- }
- public string GetXmlRecipeList()
- {
- return m_uiRecipeManager.GetXmlRecipeList(ModuleName, true) ?? "";
- }
- void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
- {
- foreach (XmlElement ele in curElementNode.ChildNodes)
- {
- if (ele.Name == "File")
- {
- string fileName = ele.Attributes["Name"].Value;
- fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
- TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
- item.Tag = ele.Attributes["Name"].Value;
- if (!item.Tag.ToString().Contains("\\"))
- {
- continue;
- }
- itemsControl.Items.Add(item);
- }
- else if (ele.Name == "Folder")
- {
- string folderName = ele.Attributes["Name"].Value;
- folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
- if (folderName == Venus_Core.RecipeType.Process.ToString() || folderName == Venus_Core.RecipeType.Clean.ToString() || folderName == Venus_Core.RecipeType.Chuck.ToString() || folderName == Venus_Core.RecipeType.DeChuck.ToString())
- {
- TreeViewFolderItem item = new TreeViewFolderItem(folderName);
- item.Tag = ele.Attributes["Name"].Value;
- CreateTreeViewItems(ele, item);
- item.IsExpanded = false;
- itemsControl.Items.Add(item);
- }
- }
- }
- }
- private IEnumerable<string> GetFilesNames(string path)
- {
- if (Directory.Exists(path))
- {
- return Directory.GetFiles(path, "*.rcp")?
- .Select(Path.GetFileNameWithoutExtension);
- }
- else
- {
- return new List<string>();
- }
- }
- private void LoadHeadWrapPanel(WrapPanel HeadWrapPanel, Recipe recipe)
- {
- HeadWrapPanel.Children.Clear();
- Type type = recipe.Header.GetType();
- foreach (var propertyInfo in type.GetProperties())
- {
- TextBlock textBlock = new TextBlock();
- textBlock.FontSize = 16;
- textBlock.Margin = new Thickness(0, 20, 0, 0);
- textBlock.Width = 200;
- if ((currentChamber != JetChamber.VenusDE && currentChamber != JetChamber.VenusSE) && propertyInfo.Name == "WallTemperature")
- {
- continue;
- }
- if ((currentChamber == JetChamber.VenusDE || currentChamber == JetChamber.VenusSE) && propertyInfo.Name == "Barcode")
- {
- continue;
- }
- switch (propertyInfo.Name)
- {
- case "ChuckRecipe":
- if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
- {
- continue;
- }
- textBlock.Text = "Chuck:";
- break;
- case "DechuckRecipe":
- if (currentChamber != JetChamber.VenusSE && currentChamber != JetChamber.VenusDE)
- {
- continue;
- }
- textBlock.Text = "DeChuck:";
- break;
- default:
- object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
- string name;
- if (NameAttrs.Length > 0)
- {
- name = (NameAttrs[0] as CustomName).Name;
- }
- else
- {
- name = propertyInfo.Name;
- }
- textBlock.Text = name + ":";
- break;
- }
- textBlock.Margin = new Thickness(15, 0, 0, 0);
- textBlock.VerticalAlignment = VerticalAlignment.Center;
- HeadWrapPanel.Children.Add(textBlock);
- Binding binding = new Binding()
- {
- Source = recipe.Header, // 数据源
- Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, //触发器
- };
- var propertyTypeName = propertyInfo.PropertyType.Name;
- var propertyInfoName = propertyInfo.Name;
- Control control = new Control();
- switch (propertyInfoName)
- {
- case "ChamberType":
- control = new ComboBox();
- control.IsEnabled = false;
- //control.Height = 23;
- control.SetBinding(ComboBox.SelectedItemProperty, binding);
- control.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
- break;
- case "Type":
- ComboBox cb = new ComboBox();
- cb.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- cb.IsEnabled = false;
- cb.SelectionChanged += ChangeUI;
- control = cb;
- //control.Height = 23;
- ItemsControlHelper.SetEnumValuesToItemsSource(control, true);
- control.SetBinding(ComboBox.SelectedItemProperty, binding);
- break;
- case "ChuckRecipe":
- StringBuilder stringBuilder = new StringBuilder();
- control = new ComboBox()
- {
- ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck"))
- };
- //control.Height = 23;
- control.MinWidth = 100;
- control.MaxWidth = 300;
- control.SetBinding(ComboBox.SelectedItemProperty, binding);
- control.PreviewMouseLeftButtonDown += ChuckControl_PreviewMouseLeftButtonDown;
- break;
- case "DechuckRecipe":
- //if (currentChamber != JetChamber.Venus)
- //{
- // continue;
- //}
- //string[] dechucklist = new string[] { "" };
- //ArrayList dearrayList = new ArrayList(dechucklist.ToList());
- //IEnumerable<string> delist = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName)).ToList().Where(item => item.ToLower().Contains("dechuck"));
- //foreach (var i in delist)
- //{
- // dearrayList.Add(i);
- //}
- //dechucklist = (string[])dearrayList.ToArray(typeof(string));
- //StringBuilder destringBuilder = new StringBuilder();
- //for (int i = 0; i < dechucklist.Length; i++)
- //{
- // destringBuilder.Append(dechucklist[i] + "\t");
- //}
- control = new ComboBox()
- {
- ItemsSource = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck"))
- };
- //control.Height = 23;
- control.MinWidth = 100;
- control.MaxWidth = 300;
- control.SetBinding(ComboBox.SelectedItemProperty, binding);
- control.PreviewMouseLeftButtonDown += DechuckControl_PreviewMouseLeftButtonDown;
- break;
- case "IsShowTolerance":
- control = new CheckBox();
- control.SetBinding(CheckBox.IsCheckedProperty, binding);
- control.Style = null;
- control.VerticalAlignment = VerticalAlignment.Center;
- (control as CheckBox).Checked += RecipeViewModel_Checked;
- (control as CheckBox).Unchecked += RecipeViewModel_Checked;
- break;
- default:
- control = new TextBox();
- control.Margin = new Thickness(1, 0, 0, 0);
- control.BorderThickness = new Thickness(0, 0, 0, 1);
- control.BorderBrush = Brushes.White;
- control.FontSize = 15;
- control.Foreground = Brushes.Green;
- control.Background = Brushes.Transparent;
- control.VerticalAlignment = VerticalAlignment.Center;
- control.MinWidth = 15;
- control.SetBinding(TextBox.TextProperty, binding);
- object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
- if (objAttrs.Length > 0)
- {
- (control as TextBox).IsReadOnly = true;
- }
- break;
- }
- control.Margin = new Thickness(20, 3, 0, 7);
- control.Width = 250;
- HeadWrapPanel.Children.Add(control);
- }
- }
- private void RecipeViewModel_Checked(object sender, RoutedEventArgs e)
- {
- LoadRecipe(CurrentRecipe);
- }
- private void ChuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\Chuck")).ToList();
- items.Add("");
- (sender as ComboBox).ItemsSource = items;
- }
- private void DechuckControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var items = GetFilesNames(Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", $"{ModuleName}\\DeChuck")).ToList();
- items.Add("");
- (sender as ComboBox).ItemsSource = items;
- }
- private void ChangeUI(object sender, SelectionChangedEventArgs e)
- {
- var t = sender as ComboBox;
- if (t.SelectedValue.ToString() != "Process")
- {
- headWrapPanel.Children[8].Visibility = Visibility.Collapsed;
- headWrapPanel.Children[9].Visibility = Visibility.Collapsed;
- headWrapPanel.Children[10].Visibility = Visibility.Collapsed;
- headWrapPanel.Children[11].Visibility = Visibility.Collapsed;
- }
- else
- {
- headWrapPanel.Children[8].Visibility = Visibility.Visible;
- headWrapPanel.Children[9].Visibility = Visibility.Visible;
- headWrapPanel.Children[10].Visibility = Visibility.Visible;
- headWrapPanel.Children[11].Visibility = Visibility.Visible;
- }
- }
- private void MenuItemLeftInsert_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- int insertIndex = Convert.ToInt32(t.Text) - 1;
- RecipeStep recipeStep;
- if (copyIndex == -1)
- {
- recipeStep = new RecipeStep();
- if (QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.WaferSize").ToString() == "8")
- recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type, 8);
- else
- recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
- CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
- }
- else
- {
- var t1 = JsonConvert.SerializeObject(CurrentRecipe);
- recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
- CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
- }
- for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
- {
- CurrentRecipe.Steps[i].StepNo = i + 1;
- }
- ColumnDefinition col1 = new ColumnDefinition();
- col1.Width = GridLength.Auto;
- rightGrid.ColumnDefinitions.Add(col1);
- for (int i = 0; i < rightGrid.Children.Count; i++)
- {
- if (Grid.GetColumn(rightGrid.Children[i]) >= insertIndex)
- {
- Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) + 1);
- }
- }
- RecipeStepToGridColumn(recipeStep, rightGrid, insertIndex);
- }
- private void MenuItemRightInsert_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- int insertIndex = Convert.ToInt32(t.Text);
- RecipeStep recipeStep;
- if (copyIndex == -1)
- {
- recipeStep = new RecipeStep();
- if (QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.WaferSize").ToString() == "8")
- recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type, 8);
- else
- recipeStep.LstUnit = RecipeUnity.GetAllUnits(currentChamber, CurrentRecipe.Header.Type);
- CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
- }
- else
- {
- var t1 = JsonConvert.SerializeObject(CurrentRecipe);
- recipeStep = Recipe.Load(t1).Steps[copyIndex - 1];
- CurrentRecipe.Steps.Insert(insertIndex, recipeStep);
- }
- for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
- {
- CurrentRecipe.Steps[i].StepNo = i + 1;
- }
- ColumnDefinition col1 = new ColumnDefinition();
- col1.Width = GridLength.Auto;
- rightGrid.ColumnDefinitions.Add(col1);
- for (int i = 0; i < rightGrid.Children.Count; i++)
- {
- if (Grid.GetColumn(rightGrid.Children[i]) >= insertIndex)
- {
- Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) + 1);
- }
- }
- RecipeStepToGridColumn(recipeStep, rightGrid, insertIndex);
- }
- private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- int deleteIndex = Convert.ToInt32(t.Text) - 1;
- CurrentRecipe.Steps.RemoveAt(deleteIndex);
- for (int i = 0; i < CurrentRecipe.Steps.Count; i++)
- {
- CurrentRecipe.Steps[i].StepNo = i + 1;
- }
- RemoveColumnFromGrid(rightGrid, deleteIndex);
- rightGrid.ColumnDefinitions.RemoveAt(deleteIndex);
- for (int i = 0; i < rightGrid.Children.Count; i++)
- {
- if (Grid.GetColumn(rightGrid.Children[i]) >= deleteIndex)
- {
- Grid.SetColumn(rightGrid.Children[i], Grid.GetColumn(rightGrid.Children[i]) - 1);
- }
- }
- }
- private void MenuItemCopy_Click(object sender, RoutedEventArgs e)
- {
- var t = ((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox;
- copyIndex = Convert.ToInt32(t.Text);
- }
- #endregion
- #region 私有方法
- private void RecipeStepToGridColumn(RecipeStep recipeStep, Grid grid, int columnIndex)
- {
- Type recipeType = recipeStep.GetType();
- int rowIndex = 0;
- foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
- {
- string propertyInfoName = propertyInfo.Name;
- string propertyTypeName = propertyInfo.PropertyType.Name;
- if (propertyInfoName != "LstUnit")
- {
- if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
- {
- continue;
- }
- if (columnIndex == 0)
- {
- RowDefinition row1 = new RowDefinition();
- row1.Height = new GridLength(controlHeight);
- grid.RowDefinitions.Add(row1);
- }
- Binding binding = new Binding()
- {
- Source = recipeStep, // 数据源
- Path = new PropertyPath(propertyInfoName), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- switch (propertyTypeName)
- {
- case "Int32":
- case "String":
- case "Single":
- case "Double":
- if (propertyInfoName == "EPDConfig")
- {
- if (currentEPDType == EPDType.Socket)
- {
- ComboBox EPDcomboBox = new ComboBox();
- EPDcomboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- EPDcomboBox.Background = new SolidColorBrush(Colors.Black);
- EPDcomboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
- EPDcomboBox.ItemsSource = EPDCfgList;
- grid.Children.Add(EPDcomboBox);
- Grid.SetRow(EPDcomboBox, rowIndex);
- Grid.SetColumn(EPDcomboBox, columnIndex);
- }
- else if (currentEPDType == EPDType.WCF)
- {
- Button EPDButton = new Button();
- EPDButton.Content = "EndPoint";
- EPDButton.Cursor = Cursors.Hand;
- EPDButton.Tag = $"{CurrentRecipeName}.{(columnIndex).ToString()}";
- EPDButton.Style = null;
- EPDButton.Click += EPDButton_Click;
- grid.Children.Add(EPDButton);
- Grid.SetRow(EPDButton, rowIndex);
- Grid.SetColumn(EPDButton, columnIndex);
- }
- break;
- }
- TextBox textBox = new TextBox();
- textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
- textBox.VerticalContentAlignment = VerticalAlignment.Center;
- textBox.SetBinding(TextBox.TextProperty, binding);
- grid.Children.Add(textBox);
- Grid.SetRow(textBox, rowIndex);
- Grid.SetColumn(textBox, columnIndex);
- object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
- if (objAttrs.Length > 0)
- {
- textBox.IsReadOnly = true;
- ContextMenu contextmenu = new ContextMenu();
- textBox.ContextMenu = contextmenu;
- MenuItem menuItemDelete = new MenuItem();
- menuItemDelete.Header = "Delete";
- menuItemDelete.Click += MenuItemDelete_Click;
- MenuItem menuItemLeftInsert = new MenuItem();
- menuItemLeftInsert.Header = "Left Insert";
- menuItemLeftInsert.Click += MenuItemLeftInsert_Click;
- MenuItem menuItemRightInsert = new MenuItem();
- menuItemRightInsert.Header = "Right Insert";
- menuItemRightInsert.Click += MenuItemRightInsert_Click;
- MenuItem menuItemCopy = new MenuItem();
- menuItemCopy.Tag = textBox.Text;
- menuItemCopy.Header = "Copy";
- menuItemCopy.Click += MenuItemCopy_Click;
- contextmenu.Items.Add(menuItemCopy);
- contextmenu.Items.Add(menuItemDelete);
- contextmenu.Items.Add(menuItemLeftInsert);
- contextmenu.Items.Add(menuItemRightInsert);
- }
- break;
- case "Boolean":
- CheckBox checkBox = new CheckBox();
- checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
- grid.Children.Add(checkBox);
- Grid.SetRow(checkBox, rowIndex);
- Grid.SetColumn(checkBox, columnIndex);
- break;
- default:
- ComboBox comboBox = new ComboBox();
- comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- //comboBox.BorderThickness = new Thickness(1, 0, 1, 0);
- comboBox.Background = new SolidColorBrush(Colors.Black);
- comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
- ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
- grid.Children.Add(comboBox);
- Grid.SetRow(comboBox, rowIndex);
- Grid.SetColumn(comboBox, columnIndex);
- break;
- }
- rowIndex++;
- }
- }
- int unitIndex = 0;
- foreach (var x in recipeStep.LstUnit.ToList())
- {
- Type unitType = x.GetType();
- Binding checkbinding = null;
- foreach (PropertyInfo propertyInfo in unitType.GetProperties())
- {
- object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
- bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
- if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
- {
- break;
- }
- object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
- if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance == false)
- {
- continue;
- }
- if (propertyInfo.Name == "UnitName")
- {
- continue;
- }
- //if (propertyInfo.Name.Contains("Gas"))
- //{
- // if (!(bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas1.Enable"))
- // {
- // continue;
- // }
- //}
- if (columnIndex == 0)
- {
- RowDefinition row1 = new RowDefinition();
- row1.Height = new GridLength(controlHeight);
- grid.RowDefinitions.Add(row1);
- }
- Binding binding = new Binding()
- {
- Source = recipeStep.LstUnit[unitIndex], // 数据源
- //Path = new PropertyPath($"LstUnit[{k}]." + propertyInfo.Name), // 需绑定的数据源属性名
- Path = new PropertyPath(propertyInfo.Name), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- var item = propertyInfo.PropertyType.Name;
- switch (item)
- {
- case "Int32":
- case "String":
- case "Single":
- case "Double":
- TextBox textBox = new TextBox();
- textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
- textBox.VerticalContentAlignment = VerticalAlignment.Center;
- if (checkbinding == null)
- {
- textBox.IsEnabled = true;
- }
- else
- {
- textBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
- }
- textBox.SetBinding(TextBox.TextProperty, binding);
- grid.Children.Add(textBox);
- Grid.SetRow(textBox, rowIndex);
- Grid.SetColumn(textBox, columnIndex);
- //object[] objAttrs = propertyInfo.GetCustomAttributes(typeof(IsOnlyReadAttribute), true);
- //if (objAttrs.Length > 0)
- //{
- // textBox.IsReadOnly = true;
- //}
- break;
- case "Boolean":
- CheckBox checkBox = new CheckBox();
- if (checkbinding == null)
- {
- checkbinding = new Binding
- {
- Source = checkBox, // 数据源
- Path = new PropertyPath("IsChecked"), // 需绑定的数据源属性名
- Mode = BindingMode.TwoWay, // 绑定模式
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged //触发器
- };
- }
- checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
- grid.Children.Add(checkBox);
- Grid.SetRow(checkBox, rowIndex);
- Grid.SetColumn(checkBox, columnIndex);
- break;
- default:
- //if (checkbinding != null)
- //{
- // break;
- //}
- ComboBox comboBox = new ComboBox();
- comboBox.BorderBrush = Brushes.Gray;
- comboBox.Style = (Style)recipeView.FindResource("customeComboBoxStyle");
- //comboBox.BorderThickness =new Thickness(1,0,1,0);
- if (checkbinding == null)
- {
- comboBox.IsEnabled = true;
- }
- else
- {
- comboBox.SetBinding(TextBox.IsEnabledProperty, checkbinding);
- }
- comboBox.Background = Brushes.White;
- string path = propertyInfo.Name;
- comboBox.SetBinding(ComboBox.SelectedItemProperty, binding);
- ItemsControlHelper.SetEnumValuesToItemsSource(comboBox, true);
- grid.Children.Add(comboBox);
- Grid.SetRow(comboBox, rowIndex);
- Grid.SetColumn(comboBox, columnIndex);
- break;
- }
- rowIndex++;
- }
- unitIndex++;
- }
- }
- private void RecipeStepToGridColumnOnlyTitle(RecipeStep recipeStep, Grid grid)
- {
- Type recipeType = recipeStep.GetType();
- int i = 0;
- ColumnDefinition col1 = new ColumnDefinition();
- grid.ColumnDefinitions.Add(col1);
- foreach (PropertyInfo propertyInfo in recipeType.GetProperties())
- {
- string propertyInfoName = propertyInfo.Name;
- string propertyTypeName = propertyInfo.PropertyType.Name;
- if (propertyInfoName != "LstUnit")
- {
- if ((propertyInfoName == "EPDConfig" || propertyInfoName == "MinEndPointTime" || propertyInfoName == "MaxEndPointTime" || propertyInfoName == "OverEtchPercent") && isInstalledEPD == false)
- {
- continue;
- }
- RowDefinition row1 = new RowDefinition();
- row1.Height = new GridLength(controlHeight);
- grid.RowDefinitions.Add(row1);
- TextBox textBlock = new TextBox();
- textBlock.Padding = new Thickness(0, 3, 0, 0);
- textBlock.IsReadOnly = true;
- object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
- string name;
- if (NameAttrs.Length > 0)
- {
- name = (NameAttrs[0] as CustomName).Name;
- }
- else
- {
- name = propertyInfo.Name;
- }
- textBlock.Text = name;
- //textBlock.FontSize = 15;
- grid.Children.Add(textBlock);
- textBlock.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FAFAFA"));
- Grid.SetRow(textBlock, i);
- Grid.SetColumn(textBlock, 0);
- i++;
- }
- }
- foreach (var x in recipeStep.LstUnit.ToList())
- {
- Type unitType = x.GetType();
- bool isUnitFirstRow = true;
- foreach (PropertyInfo propertyInfo in unitType.GetProperties())
- {
- object[] IgnoreAttrs = propertyInfo.GetCustomAttributes(typeof(IsCanConfigIgnore), true);
- bool IsEnableRecipeExtension = Convert.ToBoolean(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.IsEnableRecipeExtension"));
- if (IgnoreAttrs.Length > 0 && IsEnableRecipeExtension == false)
- {
- break;
- }
- object[] toleranceAttrs = propertyInfo.GetCustomAttributes(typeof(IsTolerance), true);
- if (toleranceAttrs.Length > 0 && CurrentRecipe.Header.IsShowTolerance == false)
- {
- continue;
- }
- if (propertyInfo.Name == "UnitName")
- {
- continue;
- }
- if (propertyInfo.Name.Contains("Gas"))
- {
- if (!(bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas1.Enable"))
- {
- continue;
- }
- }
- RowDefinition row1 = new RowDefinition();
- row1.Height = new GridLength(controlHeight);
- grid.RowDefinitions.Add(row1);
- TextBox textBlock = new TextBox();
- if (isUnitFirstRow)
- {
- textBlock.FontWeight = FontWeights.Bold;
- textBlock.FontSize = 15;
- isUnitFirstRow = false;
- textBlock.Padding = new Thickness(0, 2, 0, 0);
- }
- else
- {
- textBlock.Padding = new Thickness(0, 3, 0, 0);
- }
- textBlock.IsReadOnly = true;
- switch (propertyInfo.Name)
- {
- case "Gas1":
- var data1 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas1");
- textBlock.Text = $"{propertyInfo.Name}({data1.DisplayName},{data1.Scale})";
- break;
- case "Gas2":
- var data2 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas2");
- textBlock.Text = $"{propertyInfo.Name}({data2.DisplayName},{data2.Scale})";
- break;
- case "Gas3":
- var data3 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas3");
- textBlock.Text = $"{propertyInfo.Name}({data3.DisplayName},{data3.Scale})";
- break;
- case "Gas4":
- var data4 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas4");
- textBlock.Text = $"{propertyInfo.Name}({data4.DisplayName},{data4.Scale})";
- break;
- case "Gas5":
- var data5 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas5");
- textBlock.Text = $"{propertyInfo.Name}({data5.DisplayName},{data5.Scale})";
- break;
- case "Gas6":
- var data6 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas6");
- textBlock.Text = $"{propertyInfo.Name}({data6.DisplayName},{data6.Scale})";
- break;
- case "Gas7":
- var data7 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas7");
- textBlock.Text = $"{propertyInfo.Name}({data7.DisplayName},{data7.Scale})";
- break;
- case "Gas8":
- var data8 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas8");
- textBlock.Text = $"{propertyInfo.Name}({data8.DisplayName},{data8.Scale})";
- break;
- case "Gas9":
- var data9 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas9");
- textBlock.Text = $"{propertyInfo.Name}({data9.DisplayName},{data9.Scale})";
- break;
- case "Gas10":
- var data10 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas10");
- textBlock.Text = $"{propertyInfo.Name}({data10.DisplayName},{data10.Scale})";
- break;
- case "Gas11":
- var data11 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas11");
- textBlock.Text = $"{propertyInfo.Name}({data11.DisplayName},{data11.Scale})";
- break;
- case "Gas12":
- var data12 = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas12");
- textBlock.Text = $"{propertyInfo.Name}({data12.DisplayName},{data12.Scale})";
- break;
- default:
- object[] NameAttrs = propertyInfo.GetCustomAttributes(typeof(CustomName), true);
- string name;
- if (NameAttrs.Length > 0)
- {
- name = (NameAttrs[0] as CustomName).Name;
- }
- else
- {
- name = propertyInfo.Name;
- }
- textBlock.Text = name;
- break;
- }
- grid.Children.Add(textBlock);
- Grid.SetRow(textBlock, i);
- Grid.SetColumn(textBlock, 0);
- i++;
- }
- }
- }
- private void EPDButton_Click(object sender, RoutedEventArgs e)
- {
- Button button = sender as Button;
- string para = button.Tag.ToString();
- int stepno = Convert.ToInt32(para.Split('.')[1]) - 1;
- var endpointconfigitem = new MECF.Framework.Common.CommonData.EndPointConfigItem();
- if (CurrentRecipe.Steps[stepno].EPDConfig != null && CurrentRecipe.Steps[stepno].EPDConfig.Length > 20)
- {
- endpointconfigitem.SetValue(CurrentRecipe.Steps[stepno].EPDConfig);
- }
- (new EndPointDlg(para, endpointconfigitem, CurrentRecipe)).ShowDialog();
- }
- private void UpdateRecipeFileList()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(GetXmlRecipeList());
- treeViewRcpList.Items.Clear();
- CreateTreeViewItems(doc.DocumentElement, this.treeViewRcpList);
- ExpandAllItems(this.treeViewRcpList);
- }
- private void LoadRecipe(Recipe recipe)
- {
- copyIndex = -1;
- OnClearRecipe();
- CurrentRecipe = recipe;
- RecipeStepToGridColumnOnlyTitle(recipe.Steps[0], leftGrid);
- for (int i = 0; i < recipe.Steps.Count; i++)
- {
- ColumnDefinition col1 = new ColumnDefinition();
- col1.Width = GridLength.Auto;
- rightGrid.ColumnDefinitions.Insert(i, col1);
- RecipeStepToGridColumn(recipe.Steps[i], rightGrid, i);
- }
- string recipeContent = RecipeUnity.RecipeToString(CurrentRecipe);
- SaveEAPRecipe(recipeContent, CurrentRecipe.Steps);
- }
- private void OnDeleteStep(int index)
- {
- if (CurrentRecipe != null && CurrentRecipe.Steps.Count > 1)
- {
- RemoveColumnFromGrid(rightGrid, index);
- rightGrid.ColumnDefinitions.RemoveAt(index);
- CurrentRecipe.Steps.RemoveAt(index);
- }
- }
- /// <summary>
- /// 删除Grid某列数据
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="column"></param>
- public void RemoveColumnFromGrid(Grid grid, int column)
- {
- List<UIElement> listControl = new List<UIElement>();
- for (int i = 0; i < grid.Children.Count; i++)
- {
- var child = grid.Children[i];
- if (Grid.GetColumn(child) == column)
- {
- listControl.Add(child);
- }
- }
- listControl.ForEach(x =>
- {
- grid.Children.Remove(x);
- });
- }
- private void OnRefresh()
- {
- if (CurrentRecipeName != "")
- {
- string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", ModuleName, typeFolder, $"{CurrentRecipeName}.rcp");
- string xmlRecipeData = m_uiRecipeManager.LoadRecipeByPath(path);
- CurrentRecipe = Recipe.Load(xmlRecipeData);
- LoadHeadWrapPanel(headWrapPanel, CurrentRecipe);
- LoadRecipe(CurrentRecipe);
- }
- }
- private void OnExpand()
- {
- HeadExpand = !HeadExpand;
- if (HeadExpand)
- {
- recipeView.expandGrid.Width = 300;
- }
- else
- {
- recipeView.expandGrid.Width = 30;
- }
- }
- private void OnUnload()
- {
- //if (CurrentRecipeName == null || CurrentRecipeName == "")
- //{
- // return;
- //}
- //if (WPFMessageBox.ShowQuestion($"Is Save Recipe {CurrentRecipeName}", "", false) == MessageBoxResult.Yes)
- //{
- // OnSaveRecipe();
- //}
- }
- private void OnClearRecipe()
- {
- for (int i = 0; i < rightGrid.ColumnDefinitions.Count; i++)
- {
- rightGrid.ColumnDefinitions[i].Width = new GridLength(75);
- }
- leftGrid.Children.Clear();
- rightGrid.Children.Clear();
- leftGrid.ColumnDefinitions.Clear();
- rightGrid.ColumnDefinitions.Clear();
- rightGrid.RowDefinitions.Clear();
- leftGrid.RowDefinitions.Clear();
- GC.Collect(); // This should pick up the control removed at a previous MouseDown
- GC.WaitForPendingFinalizers(); // Doesn't help either
- //rightGrid.Visibility = Visibility.Visible;
- }
- private void ExpandAllItems(ItemsControl control)
- {
- if (control == null)
- {
- return;
- }
- foreach (Object item in control.Items)
- {
- System.Windows.Controls.TreeViewItem treeItem = control.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;
- if (treeItem == null || !treeItem.HasItems)
- {
- continue;
- }
- treeItem.IsExpanded = true;
- ExpandAllItems(treeItem as ItemsControl);
- }
- }
- private bool RecipeNameIsOk(string recipeName)
- {
- if (recipeName.Contains(' '))
- {
- WPFMessageBox.ShowError("Recipe Name 包含空格,不符合规格");
- return false;
- }
- if (recipeName.Length > 25)
- {
- WPFMessageBox.ShowError("Recipe Name 大于25个字符,不符合规格");
- return false;
- }
- return true;
- }
- #endregion
- }
- }
|