| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 | using System;using System.Collections.ObjectModel;using System.ComponentModel;using System.Diagnostics;using System.IO;using System.Linq;using Newtonsoft.Json;using Newtonsoft.Json.Converters;using Venus_Core.Attributes;namespace Venus_Core{    public enum RecipeType    {        Chuck,        DeChuck,        Process,        Clean,    }    public enum StepType    {        Time,        Stable,        EndPoint,        OverEtch,    }    public enum ProcessModule    {        Pressure,        TCP,            // Transformer Coupled Plasma (转换耦合等离子)        Bias,        Gas,        ESC,        Process,        Compound,    }    public enum GeneratorMode    {        Pulsing,        CW,    }    public enum PressureUnitMode    {        Pressure,        Valve    }    public enum Suspect    {        Origin,        Position1,        Position2,        Position3    }    public enum TargetMode    {        Step,        Cycle    }    public enum ToleranceMode    {        Value,        Percent    }    public class VenusTolerance    {         }    public class Kepler2300Tolerance    {        public bool EnableTolerance { get; set; }        public ToleranceMode ToleranceMode { get; set; }        public int Gas1ToleranceValue { get; set; }        public int Gas1TolerancePercent { get; set; }        public int Gas2ToleranceValue { get; set; }        public int Gas2TolerancePercent { get; set; }        public int Gas3ToleranceValue { get; set; }        public int Gas3TolerancePercent { get; set; }        public int Gas4ToleranceValue { get; set; }        public int Gas4TolerancePercent { get; set; }        public int Gas5ToleranceValue { get; set; }        public int Gas5TolerancePercent { get; set; }        public int Gas6ToleranceValue { get; set; }        public int Gas6TolerancePercent { get; set; }        public int Gas7ToleranceValue { get; set; }        public int Gas7TolerancePercent { get; set; }        public int Gas8ToleranceValue { get; set; }        public int Gas8TolerancePercent { get; set; }    }    public class RecipeHead : INotifyPropertyChanged    {        private string m_name;        [IsOnlyRead]        public string Name        {            get { return m_name; }            set { m_name = value; InvokePropertyChanged("Name"); }        }        private string _Version = "TestVersion";        public string Version        {            get { return _Version; }            set { _Version = value; InvokePropertyChanged("Version"); }        }        private JetChamber _ChamberType = JetChamber.Venus;        public JetChamber ChamberType        {            get { return _ChamberType; }            set { _ChamberType = value; InvokePropertyChanged("ChamberType"); }        }        private RecipeType m_Type;        [JsonConverter(typeof(StringEnumConverter))]        public RecipeType Type        {            get { return m_Type; }            set { m_Type = value; InvokePropertyChanged("Type"); }        }        private string m_ChunckRecipe;        public string ChuckRecipe        {            get { return m_ChunckRecipe; }            set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); }        }        private string m_DechuckRecipe;        public string DechuckRecipe        {            get { return m_DechuckRecipe; }            set { m_DechuckRecipe = value; InvokePropertyChanged("DechuckRecipe"); }        }        private string m_CreateTime;        [IsOnlyRead]        public string CreateTime        {            get { return m_CreateTime; }            set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); }        }        private string m_EditTime;        [IsOnlyRead]        public string EditTime        {            get { return m_EditTime; }            set { m_EditTime = value; InvokePropertyChanged("EditTime"); }        }        private string m_LastModifiedBy;        [IsOnlyRead]        public string LastModifiedBy        {            get { return m_LastModifiedBy; }            set { m_LastModifiedBy = value; InvokePropertyChanged("LastModifiedBy"); }        }        private string m_Barcode;        public string Barcode        {            get { return m_Barcode; }            set { m_Barcode = value; InvokePropertyChanged("Barcode"); }        }        private string m_BasePressure;        public string BasePressure        {            get { return m_BasePressure; }            set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); }        }        private string m_ChillerTemp;        public string ChillerTemp        {            get { return m_ChillerTemp; }            set { m_ChillerTemp = value; InvokePropertyChanged("ChillerTemp"); }        }        private int m_RFHoldTime = 1000;        public int RFHoldTime        {            get { return m_RFHoldTime; }            set { m_RFHoldTime = value; InvokePropertyChanged("RFHoldTime"); }        }        private int m_BiasRFHoldTime = 1000;        public int BiasRFHoldTime        {            get { return m_BiasRFHoldTime; }            set { m_BiasRFHoldTime = value; InvokePropertyChanged("BiasRFHoldTime"); }        }        private string m_Comment;        public string Comment        {            get { return m_Comment; }            set { m_Comment = value; InvokePropertyChanged("Comment"); }        }        //private string m_ChillerTemp1;        //public string ChillerTemp1        //{        //    get { return m_ChillerTemp1; }        //    set { m_ChillerTemp1 = value; InvokePropertyChanged("ChillerTemp1"); }        //}        //private string m_ChillerTemp2;        //public string ChillerTemp2        //{        //    get { return m_ChillerTemp2; }        //    set { m_ChillerTemp2 = value; InvokePropertyChanged("ChillerTemp2"); }        //}        //private string m_ChillerTemp3;        //public string ChillerTemp3        //{        //    get { return m_ChillerTemp3; }        //    set { m_ChillerTemp3 = value; InvokePropertyChanged("ChillerTemp3"); }        //}        //private string m_ChillerTemp4;        //public string ChillerTemp4        //{        //    get { return m_ChillerTemp4; }        //    set { m_ChillerTemp4 = value; InvokePropertyChanged("ChillerTemp4"); }        //}        public event PropertyChangedEventHandler PropertyChanged;        public void InvokePropertyChanged(string propertyName)        {            if (PropertyChanged != null)            {                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));            }        }    }    public class ProcessUnitBase    {        [JsonIgnore]        public Func<ProcessUnitBase, RecipeStep, RState> checker;        [JsonIgnore]        public Func<ProcessUnitBase, RecipeStep, RState> starter;        [JsonIgnore]        public Action<ProcessUnitBase, RecipeStep> end;        //[JsonIgnore]        //public string Name { get; set; }        //[JsonIgnore]        //public ProcessModule Moudle { get; set; }        public RState Start(RecipeStep step)        {            if (starter != null)                return starter(this, step);            return RState.Running;        }        public RState Run(RecipeStep step)        {            if (checker != null)                return checker(this, step);            return RState.Running;        }        public void End(RecipeStep step)        {            if (end != null)                end(this, step);        }    }    [Serializable]    public class RecipeStep : INotifyPropertyChanged    {        [JsonIgnore]        public Func<RecipeStep, RState> checker;        [JsonIgnore]        public Func<RecipeStep, RState> starter;        [JsonIgnore]        public Func<RecipeStep, RState> ender;        private int m_StepNo = 1;        [IsOnlyRead]        public int StepNo        {            get { return m_StepNo; }            set { m_StepNo = value; InvokePropertyChanged("StepNo"); }        }        private StepType m_StepType;        [JsonConverter(typeof(StringEnumConverter))]        public StepType Type        {            get { return m_StepType; }            set { m_StepType = value; InvokePropertyChanged("Type"); }        }        private int m_Time;        public int Time        {            get { return m_Time; }            set { m_Time = value; InvokePropertyChanged("Time"); }        }        private string m_Description;        public string Description        {            get { return m_Description; }            set { m_Description = value; InvokePropertyChanged("Description"); }        }        private string m_EPDConfigName;        public string EPDConfig        {            get { return m_EPDConfigName; }            set { m_EPDConfigName = value; InvokePropertyChanged("EPDConfig"); }        }        private int m_MinEndPointTime;        public int MinEndPointTime        {            get { return m_MinEndPointTime; }            set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }        }        private int m_MaxEndPointTime;        public int MaxEndPointTime        {            get { return m_MaxEndPointTime; }            set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }        }        //private bool m_EnableRamp;        //public bool EnableRamp        //{        //    get { return m_EnableRamp; }        //    set { m_EnableRamp = value; InvokePropertyChanged("EnableRamp"); }        //}        private int m_OverEtchPercent;        public int OverEtchPercent        {            get { return m_OverEtchPercent; }            set { m_OverEtchPercent = value; InvokePropertyChanged("OverEtchPercent"); }        }        private bool m_CycleStart;        public bool CycleStart        {            get { return m_CycleStart; }            set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }        }        private bool m_CycleEnd;        public bool CycleEnd        {            get { return m_CycleEnd; }            set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }        }        private int m_CycleNumber;        public int CycleNumber        {            get { return m_CycleNumber; }            set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }        }        private ObservableCollection<Object> lstUnit = new ObservableCollection<Object>();        public ObservableCollection<Object> LstUnit        {            get { return lstUnit; }            set { lstUnit = value; InvokePropertyChanged("LstUnit"); }        }        private Stopwatch _stepTimer = new Stopwatch();        public long ElapsedTime()        {            return _stepTimer.ElapsedMilliseconds;        }        public void StartStepTimer()        {            _stepTimer.Restart();        }        private long _lastEPDStepTimne = 0;        public void RecordEPDStepTime()        {            _lastEPDStepTimne = _stepTimer.ElapsedMilliseconds;        }        public long GetLastEPDStepTime()        {            return _lastEPDStepTimne;        }        public RState Start()        {            starter(this);            foreach (var unit in lstUnit)            {                var processUnit = unit as ProcessUnitBase;                if (processUnit != null)                {                    var state = processUnit.Start(this);                    if (state != RState.Running)                        return state;                }                else                    return RState.Failed;            }            return RState.Running;        }        public RState Start(int steps, int currentstep)        {            starter(this);            foreach (var unit in lstUnit)            {                var processUnit = unit as ProcessUnitBase;                if (processUnit != null)                {                    var state = processUnit.Start(this);                    if (state != RState.Running)                        return state;                }                else                    return RState.Failed;            }            return RState.Running;        }        public RState Run()        {            if (checker(this) == RState.End)                return RState.End;            bool bStable = true;            foreach (var unit in lstUnit)            {                var processUnit = unit as ProcessUnitBase;                if (processUnit != null)                {                    var state = processUnit.Run(this);                    if (Type == StepType.Stable)                    {                        if (state != RState.Running && state != RState.End)                            return state;                        if (state == RState.Running)                            bStable = false;                    }                    else                    {                        if (state != RState.Running)                            return state;                    }                }                else                    return RState.Failed;            }            return (Type == StepType.Stable && bStable) ? RState.End : RState.Running;        }        public void End()        {            foreach (var unit in lstUnit)            {                var processUnit = unit as ProcessUnitBase;                if (processUnit != null)                {                    processUnit.End(this);                }            }            ender(this);        }        public double RampFactor()        {            return _stepTimer.ElapsedMilliseconds / (Time * 1000.0);        }        public void AppendUnit(ProcessUnitBase unit)        {            lstUnit.Append(unit);        }        public event PropertyChangedEventHandler PropertyChanged;        public void InvokePropertyChanged(string propertyName)        {            if (PropertyChanged != null)            {                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));            }        }    }    public class Recipe : INotifyPropertyChanged    {        private RecipeHead m_Header = new RecipeHead();        public RecipeHead Header        {            get { return m_Header; }            set { m_Header = value; InvokePropertyChanged("Header"); }        }        private ObservableCollection<RecipeStep> m_Steps;        public ObservableCollection<RecipeStep> Steps        {            get { return m_Steps; }            set { m_Steps = value; InvokePropertyChanged("Steps"); }        }        public static Recipe Load(string recipeFile)        {            var recipe = JsonConvert.DeserializeObject<Recipe>(recipeFile);            if (recipe == null)            {                return null;            }            foreach (var step in recipe.Steps)            {                ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();                for (int i = 0; i < step.LstUnit.Count; i++)                {                    string value = step.LstUnit[i].ToString();                    string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);                    string item1 = striparr[1].Remove(0, 15);                    string item2 = item1.Remove(item1.Length - 2, 2);                    switch (item2)                    {                        case "PressureModeUnit":                            unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));                            break;                        //case "PressureByValveModeUnit":                        //    unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));                        //    break;                        case "TCPUnit":                            unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));                            break;                        case "BiasUnit":                            unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));                            break;                        case "GasControlUnit":                            unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));                            break;                        case "ESCHVUnit":                            unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));                            break;                        case "ProcessKitUnit":                            unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));                            break;                        case "HeaterUnit":                            unit.Add(JsonConvert.DeserializeObject<HeaterUnit>(step.LstUnit[i].ToString()));                            break;                        case "GasUnit":                            unit.Add(JsonConvert.DeserializeObject<Kepler2200GasControlUnit>(step.LstUnit[i].ToString()));                            break;                    }                }                step.LstUnit.Clear();                unit.ToList().ForEach(x =>                {                    step.LstUnit.Add(x);                });            }            return recipe;        }        public bool Validate()        {            return true;        }        public bool Save(string recipeFile)        {            return true;        }        public event PropertyChangedEventHandler PropertyChanged;        public void InvokePropertyChanged(string propertyName)        {            if (PropertyChanged != null)            {                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));            }        }    }    public class RecipeUnity    {        public static string ConvertJsonString(string str)        {            JsonSerializer serializer = new JsonSerializer();            TextReader tr = new StringReader(str);            JsonTextReader jtr = new JsonTextReader(tr);            object obj = serializer.Deserialize(jtr);            if (obj != null)            {                StringWriter textWriter = new StringWriter();                JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)                {                    Formatting = Newtonsoft.Json.Formatting.Indented,                    Indentation = 4,                    IndentChar = ' '                };                serializer.Serialize(jsonWriter, obj);                return textWriter.ToString();            }            else            {                return str;            }        }        public static string RecipeToString(Recipe recipe)        {            return JsonConvert.SerializeObject(recipe);        }        public static String CreateRecipe(JetChamber currentChamber, RecipeType recipeType, string recipeName)        {            Recipe recipe = new Recipe();            recipe.Header = new RecipeHead();            recipe.Header.CreateTime = DateTime.Now.ToString();            recipe.Header.EditTime = DateTime.Now.ToString();            recipe.Header.Type = recipeType;            recipe.Header.ChamberType = currentChamber;            recipe.Header.Name = recipeName;            recipe.Header.LastModifiedBy = "Admin";            recipe.Steps = new ObservableCollection<RecipeStep>();            RecipeStep recipeStep = new RecipeStep();            recipeStep.LstUnit = GetAllUnits(currentChamber, recipeType);            recipe.Steps.Add(recipeStep);            var recipeString = JsonConvert.SerializeObject(recipe);            return recipeString;        }        public static ObservableCollection<Object> GetAllUnits(JetChamber jetChamber)        {            ObservableCollection<Object> LstUnit = new ObservableCollection<object>();            switch (jetChamber)            {                case JetChamber.Venus:                    foreach (var item in Enum.GetValues(typeof(VenusUnits)))                    {                        Type t = Type.GetType($"Venus_Core.{item.ToString()}");                        var obj = System.Activator.CreateInstance(t);                        LstUnit.Add(obj);                    }                    break;                case JetChamber.Kepler2300:                    foreach (var item in Enum.GetValues(typeof(Kepler2300Uints)))                    {                        Type t = Type.GetType($"Venus_Core.{item.ToString()}");                        var obj = System.Activator.CreateInstance(t);                        LstUnit.Add(obj);                    }                    break;                case JetChamber.Kepler2200A:                    foreach (var item in Enum.GetValues(typeof(Kepler2200AUnits)))                    {                        Type t = Type.GetType($"Venus_Core.{item.ToString()}");                        var obj = System.Activator.CreateInstance(t);                        LstUnit.Add(obj);                    }                    break;            }            return LstUnit;        }        public static ObservableCollection<Object> GetAllUnits(JetChamber jetChamber, RecipeType recipeType)        {            ObservableCollection<Object> LstUnit = new ObservableCollection<object>();            switch (jetChamber)            {                case JetChamber.Venus:                    if (recipeType == RecipeType.Clean)                    {                        foreach (var item in Enum.GetValues(typeof(VenusCleanRecipeUnits)))                        {                            Type t = Type.GetType($"Venus_Core.{item.ToString()}");                            var obj = System.Activator.CreateInstance(t);                            LstUnit.Add(obj);                        }                    }                    else                    {                        foreach (var item in Enum.GetValues(typeof(VenusUnits)))                        {                            Type t = Type.GetType($"Venus_Core.{item.ToString()}");                            var obj = System.Activator.CreateInstance(t);                            LstUnit.Add(obj);                        }                    }                    break;                case JetChamber.Kepler2300:                    if (recipeType == RecipeType.Clean)                    {                        foreach (var item in Enum.GetValues(typeof(Kepler2300CleanRecipeUints)))                        {                            Type t = Type.GetType($"Venus_Core.{item.ToString()}");                            var obj = System.Activator.CreateInstance(t);                            LstUnit.Add(obj);                        }                    }                    else                    {                        foreach (var item in Enum.GetValues(typeof(Kepler2300Uints)))                        {                            Type t = Type.GetType($"Venus_Core.{item.ToString()}");                            var obj = System.Activator.CreateInstance(t);                            LstUnit.Add(obj);                        }                    }                    break;                case JetChamber.Kepler2200A:                    foreach (var item in Enum.GetValues(typeof(Kepler2200AUnits)))                    {                        Type t = Type.GetType($"Venus_Core.{item.ToString()}");                        var obj = System.Activator.CreateInstance(t);                        LstUnit.Add(obj);                    }                    break;            }            return LstUnit;        }    }}
 |