Example #1
0
        public static SWinKeyInfo[] GetWinKeyInfos(IKey inWinKeyParent, CWindowTypeDescrs inWindowTypeDescrs, ILogPrinter inLogger)
        {
            int count = inWinKeyParent.GetChildCount();
            List <SWinKeyInfo> res = new List <SWinKeyInfo>(count);

            for (int i = 0; i < count; i++)
            {
                IKey window_key = inWinKeyParent.GetChild(i);

                var info = new SWinKeyInfo();

                info.WinKey = window_key;

                info.Name = Utils.GetWindowNameFromKey(window_key, i.ToString(), inLogger);

                string[] a = Utils.TryGetParamsByNameFromSubKey("Type", window_key, inLogger, true, 1);
                if (a.Length > 0)
                {
                    string stype = a[0];

                    NamedId?id = inWindowTypeDescrs.GetWinType(stype);

                    if (id.HasValue)
                    {
                        info.WinType = id.Value;
                        res.Add(info);
                    }
                    else
                    {
                        inLogger.LogError(string.Format("Undefined type. Key [{0}]!", window_key.GetPath()));
                    }
                }
            }
            return(res.ToArray());
        }
Example #2
0
        internal void Build(IKey inChildsKey, ILogPrinter inLogger)
        {
            SWinKeyInfo[] keys = Utils.GetWinKeyInfos(inChildsKey, _window_type_descrs, inLogger);

            List <CBaseWindow> unused_windows_cache = new List <CBaseWindow>(_childs);
            List <CBaseWindow> new_childs           = new List <CBaseWindow>();

            for (int i = 0; i < keys.Length; i++)
            {
                SWinKeyInfo window_key_info = keys[i];

                CBaseWindow window = Utils.FindMostSuitableWindow(unused_windows_cache, window_key_info);
                if (window == null)
                {
                    window = new CBaseWindow(this, window_key_info.Name, window_key_info.WinType, new Rect(0, 0, 10, 10), _gui_realization, _window_type_descrs);
                }
                else
                {
                    unused_windows_cache.Remove(window);
                }

                new_childs.Add(window);

                window.CheckChanging(window_key_info, inLogger);
            }

            for (int i = 0; i < unused_windows_cache.Count; i++)
            {
                unused_windows_cache[i].Dispose();
            }

            _childs.Clear();
            _childs = new_childs;
        }
Example #3
0
        internal void CheckChanging(SWinKeyInfo inKeyInfo, ILogPrinter inLogger)
        {
            CWindowTypeDescr type_descr = _window_type_descrs.GetDescr(WindowType);

            List <NamedId> unusing_params = new List <NamedId>(_params.Keys);

            foreach (SWindowParamDescr param_descr in type_descr)
            {
                if (param_descr == SWindowParamDescr.Name)
                {
                    CheckParam(param_descr, new string[] { inKeyInfo.Name });
                    unusing_params.Remove(param_descr.Id);
                }
                else
                {
                    bool     must_be = type_descr.IsMustBe(param_descr.Id);
                    string[] a       = Utils.TryGetParamsByNameFromSubKey(param_descr.Id.Name, inKeyInfo.WinKey, inLogger, must_be, CBaseParam.GetParamCount(param_descr.ParamType));
                    if (a != null)
                    {
                        CheckParam(param_descr, a);
                        unusing_params.Remove(param_descr.Id);
                    }
                }
            }

            unusing_params.ForEach(id =>
            {
                _params.Remove(id);

                SWindowParamDescr?pd = type_descr.GetWindowParamDescr(id);

                if (pd.HasValue)
                {
                    CBaseParam def_val = CBaseParam.CreateParam(pd.Value.ParamType, null);
                    OnWindowChange(pd.Value, def_val);
                }
            });

            IKey childs_key = inKeyInfo.WinKey.FindChildByName("Childs", StringComparison.InvariantCultureIgnoreCase);

            if (childs_key != null)
            {
                Build(childs_key, inLogger);
            }
        }
Example #4
0
        //public static SWinKeyInfo FindMostSuitableKey(SWinKeyInfo[] inKeys, string inName, EWindowType inWindowType, ILogPrinter inLogger)
        //{
        //    int min_dist = int.MaxValue;
        //    SWinKeyInfo res_key = new SWinKeyInfo();

        //    for (int i = 0; i < inKeys.Length; i++)
        //    {
        //        SWinKeyInfo window_key_info = inKeys[i];

        //        if (inWindowType == window_key_info.WinType)
        //        {
        //            int d = LevenshteinDistance.GetDistance(window_key_info.Name, inName, 10);
        //            if (d < min_dist)
        //            {
        //                min_dist = d;
        //                res_key = window_key_info;
        //            }
        //        }
        //    }

        //    return res_key;
        //}

        public static CBaseWindow FindMostSuitableWindow(List <CBaseWindow> unused_windows_cache, SWinKeyInfo inKeyInfo)
        {
            int         priority   = int.MaxValue;
            CBaseWindow sel_window = null;

            for (int i = 0; i < unused_windows_cache.Count; i++)
            {
                CBaseWindow window = unused_windows_cache[i];

                if (window.WindowType == inKeyInfo.WinType)
                {
                    int dist = LevenshteinDistance.GetDistance(window.Name, inKeyInfo.Name);

                    if (dist < priority)
                    {
                        sel_window = window;
                        priority   = dist;
                    }
                }
            }

            return(sel_window);
        }