Beispiel #1
0
        public void SaveSettings(TypeSize _p)
        {
            DefCL    dcl = new DefCL(Tp);
            L_L502Ch lch = dcl.LCh;

            if (Sensors != lch.Count)
            {
                throw (new Exception("RDPars.SaveSettings: Не соответствует количество датчиков в текущем типоразмере"));
            }
            for (int i_s = 0; i_s < Sensors; i_s++)
            {
                lch[i_s].Gain = Gains[i_s];
            }
            dcl.Border1        = borders[0];
            dcl.Border2        = borders[1];
            dcl.Border1In      = bordersIn[0];
            dcl.Border2In      = bordersIn[1];
            dcl.DeadZoneStart  = DeadZoneStart;
            dcl.DeadZoneFinish = DeadZoneFinish;

            dcl.Filter = filterPars.Clone();
            if (filterParsIn != null)
            {
                dcl.FilterIn = filterParsIn.Clone();
            }

            dcl.Tails.LenghtStart                   = LenghtStart;
            dcl.Tails.LenghtEnd                     = LenghtEnd;
            dcl.Tails.MultStart                     = MultStart;
            dcl.Tails.MultEnd                       = MultEnd;
            dcl.L502.FrequencyPerChannel            = SampleRate;
            ParAll.ST.ZoneSize                      = ZoneSize;
            ParAll.ST.Defect.Some.WidthMedianFilter = WidthMedianFilter;
            ParAll.ST.Defect.Some.IsMedianFilter    = IsMedianFilter;
        }
Beispiel #2
0
        public void CalcClassGain(double _gain)
        {
            TypeSize ts = ParAll.ST.TSSet.Current;

            if (Tp == EUnit.Line)
            {
                TSLine tsl = ParAll.CTS.Line;
                Class = EClass.None;
                foreach (Meas m in MMeas)
                {
                    m.Class   = Classer.GetDefClass(m.FilterABC * _gain, tsl.Borders, m.Dead);
                    m.ClassIn = Classer.GetDefClass(m.FilterInABC * _gain, tsl.BordersIn, m.Dead);
                    Class     = Classer.Compare(Class, m.Class);
                }
            }
            else
            {
                TSCross tsc = ParAll.CTS.Cross;
                Class = EClass.None;
                foreach (Meas m in MMeas)
                {
                    m.Class = Classer.GetDefClass(m.FilterABC * _gain, tsc.Borders, m.Dead);
                    Class   = Classer.Compare(Class, m.Class);
                }
            }
        }
Beispiel #3
0
        public Type ReadDynamicType <T>(long position, TypeSize typeSize)
        {
            var startposition = position;
            var endposition   = position + typeSize.Size;

            var typproperty = FindPropertyByName <T>("#Type");

            if (typproperty == null)
            {
                throw new Exception();
            }

            var propname = ReadPropertyName();

            if (propname != "#Type")
            {
                throw new Exception();
            }

            var value_typeSize = ReadTypeAndSize(_reader.BaseStream.Position);
            var obj            = ReadObjectValue(value_typeSize, null, value_typeSize.Type);

            if (obj == null || !(obj is Int32))
            {
                throw new Exception();
            }

            if (!SubTyper.Instance.TryGetValue((int)obj, out Type type))
            {
                Debug.WriteLine($"Problem at: {_reader.BaseStream.Position} can not find: {SubTyper.Instance.GetMissingType((int)obj)}");
                throw new Exception();
            }

            return(type);
        }
Beispiel #4
0
        void LoadSettings(TypeSize _p)
        {
            DefCL    dlc = new DefCL(Tp);
            L_L502Ch lch = dlc.LCh;

            borders      = new double[2];
            bordersIn    = new double[2];
            filterPars   = null;
            filterParsIn = null;
            Gains        = new double[lch.Count];
            for (int i_s = 0; i_s < Sensors; i_s++)
            {
                Gains[i_s] = lch[i_s].Gain;
            }

            borders[0]     = dlc.Border1;
            borders[1]     = dlc.Border2;
            bordersIn[0]   = dlc.Border1In;
            bordersIn[1]   = dlc.Border2In;
            DeadZoneStart  = dlc.DeadZoneStart;
            DeadZoneFinish = dlc.DeadZoneFinish;
            filterPars     = dlc.Filter.Clone();
            IsIn           = dlc.IsFinterIn;
            filterParsIn   = dlc.FilterIn.Clone();

            LenghtStart       = dlc.Tails.LenghtStart;
            LenghtEnd         = dlc.Tails.LenghtEnd;
            MultStart         = dlc.Tails.MultStart;
            MultEnd           = dlc.Tails.MultEnd;
            SampleRate        = dlc.L502.FrequencyPerChannel;
            ZoneSize          = ParAll.ST.ZoneSize;
            WidthMedianFilter = ParAll.ST.Defect.Some.WidthMedianFilter;
            IsMedianFilter    = ParAll.ST.Defect.Some.IsMedianFilter;
        }
Beispiel #5
0
 private static int GetPropertySize(string type)
 {
     if (TypeSize.ContainsKey(type))
     {
         return(TypeSize[type]);
     }
     else
     {
         return(0);
     }
 }
Beispiel #6
0
        public T ReadArrayObjectAs <T, G>(long position, TypeSize typeSize)
        {
            var startposition = position;
            var endposition   = position + typeSize.Size;

            _reader.BaseStream.Position = startposition;

            T instance = Activator.CreateInstance <T>();

            var tt = typeof(T);

            while (_reader.BaseStream.Position < endposition)
            {
                var desc_typeSize = ReadTypeAndSize(_reader.BaseStream.Position);

                object objectvalue;

                if (desc_typeSize.Type == PhoenixTypeCode.Object ||
                    desc_typeSize.Type == PhoenixTypeCode.Array)
                {
                    objectvalue = ReadObjectAs <G>(_reader.BaseStream.Position, desc_typeSize);
                }
                else
                {
                    objectvalue = ReadObjectValue(desc_typeSize, null, desc_typeSize.Type);

                    if (desc_typeSize.Type == PhoenixTypeCode.Float)
                    {
                        var proptype = ReflectionMaster.GetPhoenixTypeCode(typeof(G));
                        if (proptype == PhoenixTypeCode.Double)
                        {
                            ((ICollection <double>)instance).Add((double)(float)objectvalue);
                            continue;
                        }
                    }
                }

                if (tt.GetInterface("ICollection`1") != null)
                {
                    ((ICollection <G>)instance).Add((G)objectvalue);
                }
            }

            return(instance);
        }
        // возврат в байтах
        private long GetTypeSize(long bytes, TypeSize typeSize)
        {
            switch (typeSize)
            {
            case TypeSize.Byte:
                return(bytes);

            case TypeSize.Kb:
                return(bytes * 1024);

            case TypeSize.Mb:
                return(bytes * 1024 * 1024);

            case TypeSize.Gb:
                return(bytes * 1024 * 1024 * 1024);
            }

            return(bytes);
        }
Beispiel #8
0
        void RDraw0()
        {
            if (RK.ST.cDef(Tp).Sensor == null)
            {
                Clear();
                return;
            }
            cursor.Visible = false;
            Text           = string.Format("{0}: Зона: {1}, Датчик: {2}", title, RK.ST.cDef(Tp).Zone.Value + 1, RK.ST.cDef(Tp).Sensor.Value + 1);
            m = RK.ST.cDef(Tp).result.MZone[RK.ST.cDef(Tp).Zone.Value].MSensor[RK.ST.cDef(Tp).Sensor.Value].MMeas;

            double gain = dcl.LCh[RK.ST.cDef(Tp).Sensor.Value].Gain;

            sv = ParAll.ST.Some.SignalsView;
            TypeSize ts = ParAll.ST.TSSet.Current;

            Source.Load(m, gain, sv.Source, ParAll.ST.Colors.NotMeasured, dcl.Borders, true);
            Median.Load(m, gain, sv.Median, ParAll.ST.Colors.NotMeasured, dcl.Borders, true);
            Filter.Load(m, gain, sv.Filter, ParAll.ST.Colors.NotMeasured, dcl.Borders, dcl.Filter.IsFilter);
            FilterIn.Load(m, gain, sv.FilterIn, ParAll.ST.Colors.NotMeasured, dcl.BordersIn, dcl.FilterIn.IsFilter);
            cursorBorder.DrawSingle2(RK.ST.cDef(Tp).Zone.Value, RK.ST.cDef(Tp).Sensor.Value);
            base.Init();
        }
        private bool readInformation(ushort msglen)
        {
            int    keylen  = reader.ReadByte();
            string key     = readASCIIString(keylen);
            string keytype = key.Substring(0, key.IndexOf(' '));
            string keyname = key.Substring(keytype.Length + 1);
            int    arrlen  = getArrayLength(ref keytype);
            int    len     = msglen - 1 - keylen;

            string info = "";

            if (!TypeSize.ContainsKey(keytype))
            {
                for (int i = 0; i < len; i++)
                {
                    info += reader.ReadByte().ToString("X2");
                }
            }
            else
            {
                if (len != typeSize[keytype] * arrlen)
                {
                    Debug.WriteLine("[I]:msglen not match.");
                    return(false);
                }
                if (keytype == "char")
                {
                    info = readASCIIString(len);
                }
                else
                {
                    for (int i = 0; i < arrlen; i++)
                    {
                        switch (keytype)
                        {
                        case "int8_t":
                            info += reader.ReadSByte().ToString();
                            break;

                        case "uint8_t":
                            info += reader.ReadByte().ToString();
                            break;

                        case "int16_t":
                            info += reader.ReadInt16().ToString();
                            break;

                        case "uint16_t":
                            info += reader.ReadUInt16().ToString();
                            break;

                        case "int32_t":
                            info += reader.ReadInt32().ToString();
                            break;

                        case "uint32_t":
                            info += reader.ReadUInt32().ToString();
                            break;

                        case "int64_t":
                            info += reader.ReadInt64().ToString();
                            break;

                        case "uint64_t":
                            info += reader.ReadUInt64().ToString();
                            break;

                        case "float":
                            info += reader.ReadSingle().ToString();
                            break;

                        case "double":
                            info += reader.ReadDouble().ToString();
                            break;

                        case "bool":
                            info += reader.ReadBoolean().ToString();
                            break;
                        }
                        if (i != arrlen - 1)
                        {
                            info += ",";
                        }
                    }
                }
            }
            infomations.Add(new Tuple <string, string>(keyname, info));
            return(true);
        }
Beispiel #10
0
        public void InitRange(ResultDef _resultDef, int _iz0, int _iz1, int _is, double _gain)
        {
            chart1.Series.SuspendUpdates();
            Clear();
            TypeSize ts = ParAll.ST.TSSet.Current;

            resultDef = _resultDef;
            iz0       = _iz0;
            iz1       = _iz1;
            ise       = _is;
            Color DeviderColor      = ParAll.ST.Some.SignalsView.DeviderColor;
            DataPointCollection p   = chart1.Series[0].Points;
            DataPointCollection pIn = chart1.Series[0].Points;
            int ip     = 0;
            int ipIn   = 0;
            int istrip = 0;

            chart1.ChartAreas[0].AxisX.StripLines.Clear();
            DefCL dcl  = new DefCL(_resultDef.Tp);
            bool  IsIn = dcl.IsFinterIn;

            for (int ii = _iz0; ii <= _iz1; ii++)
            {
                Meas[] MMeas = _resultDef.MZone[ii].MSensor[ise].MMeas;
                if (istrip > 0)
                {
                    StripLine sl = new StripLine();
                    sl.BorderColor    = DeviderColor;
                    sl.BorderWidth    = 2;
                    sl.IntervalOffset = ip;
                    chart1.ChartAreas[0].AxisX.StripLines.Add(sl);
                }
                istrip++;
                for (int i = 0; i < MMeas.Length; i++)
                {
                    Meas      m  = MMeas[i];
                    DataPoint dp = new DataPoint(ip, m.FilterABC * _gain);
                    dp.Color = m.Dead ? Classer.GetColor(EClass.None) : Classer.GetColor(m.Class);
                    dp.Tag   = new PointSubj(ii, ise, i);
                    p.Add(dp);
                    ip++;
                    if (IsIn)
                    {
                        pIn.AddXY(ipIn, -m.FilterInABC * _gain);
                        p[ipIn].Color = m.Dead ? Classer.GetColor(EClass.None) : Classer.GetColor(m.ClassIn);
                        ipIn++;
                    }
                }
                istrip++;
            }
            if (bline != null)
            {
                bline.Visible = false;
            }
            if (blineIn != null)
            {
                blineIn.Visible = false;
            }
            bline   = new BorderLine(chart1.ChartAreas[0].AxisY, Classer.GetColor(EClass.Brak), Classer.GetColor(EClass.Class2));
            blineIn = new BorderLine(chart1.ChartAreas[0].AxisY, Classer.GetColor(EClass.Brak), Classer.GetColor(EClass.Class2));
            bline.SetBorders(dcl.Borders);
            bline.Visible = true;

            if (IsIn)
            {
                double[] borders = new double[2];
                borders[0] = -dcl.Border1In;
                borders[1] = -dcl.Border2In;
                blineIn.SetBorders(borders);
                blineIn.Visible = true;
            }
            chart1.ChartAreas[0].AxisY.Maximum = 100;
            if (IsIn)
            {
                chart1.ChartAreas[0].AxisY.Minimum = -100;
            }
            else
            {
                chart1.ChartAreas[0].AxisY.Minimum = 0;
            }
            if (cursor.Visible)
            {
                OnMove(cursor.Position);
            }
            chart1.Series[0].Enabled = true;
            chart1.Series[1].Enabled = IsIn;
            chart1.Series.ResumeUpdates();
        }
 public ValueConverter()
 {
     this.size = TypeSize.SizeOf <T>();
 }
        protected static void SetParametry(FrameworkElement fe, int procent, bool UsePosition, AgeType at, TypeSize type)
        {
            Size primarySize = new Size(SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);

            if (GetUseParentSize(fe))
            {
                if (fe.Parent is FrameworkElement)
                {
                    var parent = (FrameworkElement)fe.Parent;
                    primarySize = new Size(parent.Width == 0 ? parent.ActualWidth : parent.Width, parent.Height == 0 ? parent.ActualHeight : parent.Height);
                }
                else if (fe.Parent is Decorator)
                {
                    var parent = (Decorator)fe.Parent;
                    primarySize = new Size(parent.Width == 0 ? parent.ActualWidth : parent.Width, parent.Height == 0 ? parent.ActualHeight : parent.Height);
                }
            }

            fe.Width     = double.NaN;
            fe.MinWidth  = 0;
            fe.MaxWidth  = double.PositiveInfinity;
            fe.Height    = double.NaN;
            fe.MinHeight = 0;
            fe.MaxHeight = double.PositiveInfinity;

            if (!GetUsePosition(fe))
            {
                switch (at)
                {
                case AgeType.Width:
                    switch (type)
                    {
                    case TypeSize.Current:
                        fe.Width  = primarySize.Width * procent / 100;
                        fe.Height = double.NaN;
                        break;

                    case TypeSize.Static:
                        fe.Width     = fe.MinWidth = fe.MaxWidth = primarySize.Width * procent / 100;
                        fe.Height    = double.NaN;
                        fe.MinHeight = 0;
                        fe.MaxHeight = double.PositiveInfinity;
                        break;

                    case TypeSize.Max:
                        fe.MaxWidth  = primarySize.Width * procent / 100;
                        fe.MaxHeight = double.PositiveInfinity;
                        break;

                    case TypeSize.Min:
                        fe.MinWidth  = primarySize.Width * procent / 100;
                        fe.MinHeight = 0;
                        break;
                    }
                    break;

                case AgeType.Height:
                    switch (type)
                    {
                    case TypeSize.Current:
                        fe.Width  = double.NaN;
                        fe.Height = primarySize.Height * procent / 100;
                        break;

                    case TypeSize.Static:
                        fe.Width  = fe.MinWidth = fe.MaxWidth = double.NaN;
                        fe.Height = fe.MinHeight = fe.MaxHeight = primarySize.Height * procent / 100;
                        break;

                    case TypeSize.Max:
                        fe.MaxWidth  = double.PositiveInfinity;
                        fe.MaxHeight = primarySize.Height * procent / 100;
                        break;

                    case TypeSize.Min:
                        fe.MinWidth  = 0;
                        fe.MinHeight = primarySize.Height * procent / 100;
                        break;
                    }
                    break;

                case AgeType.FullSize:
                    switch (type)
                    {
                    case TypeSize.Current:
                        fe.Width  = primarySize.Width * procent / 100;
                        fe.Height = primarySize.Height * procent / 100;
                        break;

                    case TypeSize.Static:
                        fe.Width  = fe.MinWidth = fe.MaxWidth = primarySize.Width * procent / 100;
                        fe.Height = fe.MinHeight = fe.MaxHeight = primarySize.Height * procent / 100;
                        break;

                    case TypeSize.Max:
                        fe.MaxWidth  = primarySize.Width * procent / 100;
                        fe.MaxHeight = primarySize.Height * procent / 100;
                        break;

                    case TypeSize.Min:
                        fe.MinWidth  = primarySize.Width * procent / 100;
                        fe.MinHeight = primarySize.Height * procent / 100;
                        break;
                    }
                    break;
                }
            }
            else
            {
                Window parent = NTW.Common.FindAncestor <Window>(fe);
                if (parent != null)
                {
                    switch (WindowPositionBehaviour.GetWindowPosition(parent))
                    {
                    case Data.WindowPosition.Left:
                    case Data.WindowPosition.LeftBottom:
                    case Data.WindowPosition.LeftTop:
                    case Data.WindowPosition.Right:
                    case Data.WindowPosition.RightBottom:
                    case Data.WindowPosition.RightTop:
                        switch (type)
                        {
                        case TypeSize.Current:
                            fe.Width  = double.NaN;
                            fe.Height = primarySize.Height * procent / 100;
                            break;

                        case TypeSize.Static:
                            fe.Width    = double.NaN;
                            fe.MinWidth = 0;
                            fe.MaxWidth = double.PositiveInfinity;
                            fe.Height   = fe.MinHeight = fe.MaxHeight = primarySize.Height * procent / 100;
                            break;

                        case TypeSize.Max:
                            fe.MaxWidth  = double.PositiveInfinity;
                            fe.MaxHeight = primarySize.Height * procent / 100;
                            break;

                        case TypeSize.Min:
                            fe.MinWidth  = 0;
                            fe.MinHeight = primarySize.Height * procent / 100;
                            break;
                        }
                        break;

                    case Data.WindowPosition.Top:
                    case Data.WindowPosition.Bottom:
                        switch (type)
                        {
                        case TypeSize.Current:
                            fe.Width  = primarySize.Width * procent / 100;
                            fe.Height = double.NaN;
                            break;

                        case TypeSize.Static:
                            fe.Width     = fe.MinWidth = fe.MaxWidth = primarySize.Width * procent / 100;
                            fe.Height    = double.NaN;
                            fe.MinHeight = 0;
                            fe.MaxHeight = double.PositiveInfinity;
                            break;

                        case TypeSize.Max:
                            fe.MaxWidth  = primarySize.Width * procent / 100;
                            fe.MaxHeight = double.PositiveInfinity;
                            break;

                        case TypeSize.Min:
                            fe.MinWidth  = primarySize.Width * procent / 100;
                            fe.MinHeight = 0;
                            break;
                        }
                        break;
                    }
                }
                else
                {
                    Popup pParent = NTW.Common.FindAncestor <Popup>(fe);

                    if (pParent != null)
                    {
                        switch (FrameworkElementPositionBehaviour.GetFrameworkElementPosition(pParent))
                        {
                        case Data.WindowPosition.Left:
                        case Data.WindowPosition.LeftBottom:
                        case Data.WindowPosition.LeftTop:
                        case Data.WindowPosition.Right:
                        case Data.WindowPosition.RightBottom:
                        case Data.WindowPosition.RightTop:
                            switch (type)
                            {
                            case TypeSize.Current:
                                fe.Width  = double.NaN;
                                fe.Height = primarySize.Height * procent / 100;
                                break;

                            case TypeSize.Static:
                                fe.Width  = fe.MinWidth = fe.MaxWidth = double.NaN;
                                fe.Height = fe.MinHeight = fe.MaxHeight = primarySize.Height * procent / 100;
                                break;

                            case TypeSize.Max:
                                fe.MaxWidth  = double.NaN;
                                fe.MaxHeight = primarySize.Height * procent / 100;
                                break;

                            case TypeSize.Min:
                                fe.MinWidth  = double.NaN;
                                fe.MinHeight = primarySize.Height * procent / 100;
                                break;
                            }
                            break;

                        case Data.WindowPosition.Top:
                        case Data.WindowPosition.Bottom:
                            switch (type)
                            {
                            case TypeSize.Current:
                                fe.Width  = primarySize.Width * procent / 100;
                                fe.Height = double.NaN;
                                break;

                            case TypeSize.Static:
                                fe.Width  = fe.MinWidth = fe.MaxWidth = primarySize.Width * procent / 100;
                                fe.Height = fe.MinHeight = fe.MaxHeight = double.NaN;
                                break;

                            case TypeSize.Max:
                                fe.MaxWidth  = primarySize.Width * procent / 100;
                                fe.MaxHeight = double.NaN;
                                break;

                            case TypeSize.Min:
                                fe.MinWidth  = primarySize.Width * procent / 100;
                                fe.MinHeight = double.NaN;
                                break;
                            }
                            break;
                        }
                    }
                }
            }
        }
Beispiel #13
0
        private object ReadObjectValue(TypeSize value_typeSize, PropertyInfo property, PhoenixTypeCode typecode)
        {
            object objectvalue = null;

            switch (typecode)
            {
            case PhoenixTypeCode.Invalid:
                objectvalue = null;
                break;

            case PhoenixTypeCode.Empty:
                objectvalue = null;
                break;

            case PhoenixTypeCode.Bool:
                objectvalue = _reader.ReadBoolean();
                break;

            case PhoenixTypeCode.Byte:
                objectvalue = _reader.ReadByte();
                break;

            case PhoenixTypeCode.Sbyte:
                objectvalue = _reader.ReadSByte();
                break;

            case PhoenixTypeCode.Char:
                objectvalue = _reader.ReadChar();
                break;

            case PhoenixTypeCode.Short:
                objectvalue = _reader.ReadInt16();
                break;

            case PhoenixTypeCode.Ushort:
                objectvalue = _reader.ReadUInt16();
                break;

            case PhoenixTypeCode.Int:
                objectvalue = _reader.ReadInt32();
                break;

            case PhoenixTypeCode.Uint:
                objectvalue = _reader.ReadUInt32();
                break;

            case PhoenixTypeCode.Long:
                objectvalue = _reader.ReadInt64();
                break;

            case PhoenixTypeCode.Ulong:
                objectvalue = _reader.ReadUInt64();
                break;

            case PhoenixTypeCode.Float:
                objectvalue = _reader.ReadSingle();
                break;

            case PhoenixTypeCode.Double:
                objectvalue = _reader.ReadDouble();
                break;

            case PhoenixTypeCode.StringRef:
            {
                int id = _reader.ReadInt32();
                objectvalue = _stringTable[id];
            }
            break;

            case PhoenixTypeCode.StringVal:
                objectvalue = _reader.ReadString();
                break;

            case PhoenixTypeCode.Array:
            {
                if (property.PropertyType.IsGenericType)            // List<XYZ>
                {
                    var mi     = typeof(BinParser).GetMethod("ReadArrayObjectAs");
                    var tg     = property.PropertyType.GetGenericArguments().Single();
                    var fooRef = mi.MakeGenericMethod(property.PropertyType, tg);
                    objectvalue = fooRef.Invoke(this, new object[] { _reader.BaseStream.Position, value_typeSize });
                }
                else          // Arraytype[]
                {
                    throw new Exception("Can not read arrays");
                }
            }
            break;

            case PhoenixTypeCode.Object:
            {
                if (property.Name == "ObjectValue")
                {
                }
                var  dynattribute = property.GetCustomAttributes(typeof(DynamicReflectAttribute), false);
                bool isDynamic    = dynattribute != null && dynattribute.Length > 0;

                Type type2Use = property.PropertyType;
                if (isDynamic)
                {
                    long currentPostion = _reader.BaseStream.Position;
                    var  mi             = typeof(BinParser).GetMethod("ReadDynamicType");
                    var  fooRef         = mi.MakeGenericMethod(property.PropertyType);
                    Type newtype        = (Type)fooRef.Invoke(this, new object[] { _reader.BaseStream.Position, value_typeSize });

                    if (newtype != null)
                    {
                        type2Use = newtype;
                    }

                    _reader.BaseStream.Position = currentPostion;
                }
                {
                    var mi     = typeof(BinParser).GetMethod("ReadObjectAs");
                    var fooRef = mi.MakeGenericMethod(type2Use);
                    objectvalue = fooRef.Invoke(this, new object[] { _reader.BaseStream.Position, value_typeSize });
                }
            }
            break;

            default:
                objectvalue = null;
                break;
            }

            return(objectvalue);
        }
Beispiel #14
0
        public T ReadObjectAs <T>(long position, TypeSize typeSize)
        {
            var startposition = position;
            var endposition   = position + typeSize.Size;


            var props = ReflectionMaster.Instance.ReflectProperties(typeof(T));

            T instance = Activator.CreateInstance <T>();

            _reader.BaseStream.Position = startposition;

            while (_reader.BaseStream.Position < endposition)
            {
                TypeSize value_typeSize;
                object   objectvalue;

                if (typeSize.Type != PhoenixTypeCode.Object)
                {
                    objectvalue = ReadObjectValue(typeSize, null, typeSize.Type);
                    return((T)objectvalue);
                }
                string parameterName = ReadPropertyName();

                value_typeSize = ReadTypeAndSize(_reader.BaseStream.Position);

                //if (!_name2Prop.TryGetValue(parameterName, out System.Reflection.PropertyInfo property))
                var propInfo = props.Find(x => x.SerializeName == parameterName);
                if (propInfo == null || propInfo.PhoenixValueType == PhoenixTypeCode.Invalid)
                {
                    _reader.BaseStream.Position += value_typeSize.Size;
                    continue;
                }

                // Special Case
                if (parameterName == "Ticks")
                {
                    if (propInfo.Property.PropertyType.Name == "PhoenixDataTimeTicks")
                    {
                        var tmp = new PhoenixDataTimeTicks();
                        tmp.Ticks = ((long)ReadObjectValue(value_typeSize, propInfo.Property, PhoenixTypeCode.Long)).ToString();
                        propInfo.Property.SetValue(instance, tmp);
                        continue;
                    }
                    else if (propInfo.Property.PropertyType.Name == "PhoenixTimeSpanTicks")
                    {
                        var tmp = new PhoenixTimeSpanTicks();
                        tmp.Ticks = ((long)ReadObjectValue(value_typeSize, propInfo.Property, PhoenixTypeCode.Long)).ToString();
                        propInfo.Property.SetValue(instance, tmp);
                        continue;
                    }
                }


                if (propInfo.PhoenixValueType != value_typeSize.Type)
                {
                    if (value_typeSize.Type == PhoenixTypeCode.Empty)
                    {
                        continue;
                    }
                    throw new Exception();
                }

                objectvalue = ReadObjectValue(value_typeSize, propInfo.Property, propInfo.PhoenixValueType);

                if (propInfo.DeserializeCast != null)
                {
                    propInfo.Property.SetValue(instance, propInfo.DeserializeCast(objectvalue));
                }
                else
                {
                    propInfo.Property.SetValue(instance, objectvalue);
                }
            }

            return(instance);
        }
Beispiel #15
0
 static EnumConverter()
 {
     size = TypeSize.SizeOf <ushort>();
 }
Beispiel #16
0
    protected override TreeViewItem BuildRoot()
    {
        var root = new TreeViewItem      {
            id = 0, depth = -1, displayName = "Root"
        };

        var id         = 1;
        var assemblies = AppDomain.CurrentDomain.GetAssemblies();

        foreach (var assembly in assemblies)
        {
            if (IsExcluded(assembly.GetName().Name))
            {
                continue;
            }
            var assemblyItem = new TreeViewItem   {
                id = id, displayName = assembly.GetName().Name
            };
            var problems = 0;
            foreach (var type in assembly.DefinedTypes)
            {
                if (IsExcluded(type.Name))
                {
                    continue;
                }
                if (type.IsAbstract)
                {
                    continue;
                }
                if (typeof(IComponentData).IsAssignableFrom(type))
                {
                    var size = TypeSize.GetTypeSize(type);
                    id++;

                    var warnings     = new List <String>();
                    var possibleSize = TypeSize.GetStructSize(type, warnings);
                    if (warnings.Count > 0)
                    {
                        Debug.LogWarning($"{string.Join(",\n",warnings.ToArray())}");
                    }
                    var prefix = size <= possibleSize ? "✔︎" : "✘️";
                    if (possibleSize < size)
                    {
                        problems++;
                    }

                    var show = !_showOnlyProblematicComponents || size > possibleSize;

                    if (show)
                    {
                        var fields = new List <FieldInfo>();
                        TypeSize.CollectFields(type, fields);

                        var text = $"{prefix} {type.Name} holds {fields.Count} values";
                        if (fields.Count > 0)
                        {
                            text += $" in {size} bytes";
                        }
                        if (size > possibleSize)
                        {
                            text += $", where {possibleSize} bytes is possible";
                        }
                        var componentItem = new TreeViewItem   {
                            id = id, displayName = text
                        };
                        assemblyItem.AddChild(componentItem);
                    }
                }
            }

            if (problems > 0)
            {
                assemblyItem.displayName = $"{assemblyItem.displayName} [{problems}]";
            }
            if (assemblyItem.hasChildren)
            {
                root.AddChild(assemblyItem);
            }
            id++;
        }

        if (root.hasChildren == false)
        {
            root.AddChild(new TreeViewItem(1, 1, "No components were found"));
        }

        SetupDepthsFromParentsAndChildren(root);
        return(root);
    }
Beispiel #17
0
 public RDPars1(TypeSize _typeSize, EUnit _Tp)
 {
     LoadSettings(_typeSize);
     Tp          = _Tp;
     Revolutions = null;
 }
 public static void SetType(DependencyObject obj, TypeSize value)
 {
     obj.SetValue(TypeProperty, value);
 }