示例#1
0
        public override void ParseGroupCode(int groupcode, string value)
        {
            base.ParseGroupCode(groupcode, value);
            switch (groupcode)
            {
            case 210:
                Normal.X = double.Parse(value);
                break;

            case 220:
                Normal.Y = double.Parse(value);
                break;

            case 230:
                Normal.Z = double.Parse(value);
                break;

            case 70:
                Flags = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), value);
                break;

            case 71:
                Degree = int.Parse(value);
                break;

            case 72:
                KnotCount = int.Parse(value);
                break;

            case 73:
                ControlPointCount = int.Parse(value);
                break;

            case 74:
                FitPointCount = int.Parse(value);
                break;

            case 42:
                KnotTolerance = double.Parse(value);
                break;

            case 43:
                ControlPointTolerance = double.Parse(value);
                break;

            case 44:
                FitPointTolerance = double.Parse(value);
                break;

            case 12:
                StartTangent.X = double.Parse(value);
                break;

            case 22:
                StartTangent.Y = double.Parse(value);
                break;

            case 32:
                StartTangent.Z = double.Parse(value);
                break;

            case 13:
                EndTangent.X = double.Parse(value);
                break;

            case 23:
                EndTangent.Y = double.Parse(value);
                break;

            case 33:
                EndTangent.Z = double.Parse(value);
                break;

            case 40:
                KnotValues.Add(double.Parse(value));
                break;

            case 41:
                Weight = double.Parse(value);
                break;

            case 10:
                if (LastControlPoint == null || LastControlPoint.X != null)
                {
                    LastControlPoint = new DXFPoint();
                }
                LastControlPoint.X = double.Parse(value);
                break;

            case 20:
                if (LastControlPoint == null || LastControlPoint.Y != null)
                {
                    LastControlPoint = new DXFPoint();
                }
                LastControlPoint.Y = double.Parse(value);
                break;

            case 30:
                if (LastControlPoint == null || LastControlPoint.Z != null)
                {
                    LastControlPoint = new DXFPoint();
                }
                LastControlPoint.Z = double.Parse(value);
                break;

            case 11:
                if (LastFitPoint == null || LastFitPoint.X != null)
                {
                    LastFitPoint = new DXFPoint();
                }
                LastFitPoint.X = double.Parse(value);
                break;

            case 21:
                if (LastFitPoint == null || LastFitPoint.Y != null)
                {
                    LastFitPoint = new DXFPoint();
                }
                LastFitPoint.Y = double.Parse(value);
                break;

            case 31:
                if (LastFitPoint == null || LastFitPoint.Z != null)
                {
                    LastFitPoint = new DXFPoint();
                }
                LastFitPoint.Z = double.Parse(value);
                break;
            }
        }
示例#2
0
        public void ParseGroupCode(DXFDocument doc, int groupcode, string value)
        {
            if (fields.Count == 0)
            {
                Type header = doc.Header.GetType();
                foreach (PropertyInfo info in header.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                {
                    if (info.CanWrite && info.CanRead)
                    {
                        object[] attrs = info.GetCustomAttributes(true);
                        foreach (object attr in attrs)
                        {
                            HeaderAttribute casted = attr as HeaderAttribute;
                            if (casted != null)
                            {
                                fields[casted.Name] = info;
                            }
                        }
                    }
                }
            }

            if (groupcode == 9)
            {
                string name = value.Trim();
                if (fields.ContainsKey(name))
                {
                    currentVar = fields[name];
                }
                else
                {
                    currentVar = null;
                }
            }
            else if (currentVar != null)
            {
                //at first we need to differentiate the types: nullable vs string and nullable vs rest
                if (currentVar.PropertyType.Equals(typeof(string)))
                {
                    currentVar.SetValue(doc.Header, value, null);
                }
                else if (currentVar.PropertyType.IsGenericType && currentVar.PropertyType.GetGenericTypeDefinition().Equals(typeof(Nullable <>)))
                {
                    Type boxedType = currentVar.PropertyType.GetGenericArguments()[0];
                    if (boxedType.Equals(typeof(int)))
                    {
                        int?parsed;
                        if (value.ToLower().Contains('a') ||
                            value.ToLower().Contains('b') ||
                            value.ToLower().Contains('c') ||
                            value.ToLower().Contains('d') ||
                            value.ToLower().Contains('e') ||
                            value.ToLower().Contains('f'))
                        {
                            parsed = int.Parse(value, System.Globalization.NumberStyles.HexNumber);
                        }
                        else
                        {
                            parsed = int.Parse(value, System.Globalization.NumberStyles.Any);
                        }
                        currentVar.SetValue(doc.Header, parsed, null);
                    }
                    else if (boxedType.Equals(typeof(double)))
                    {
                        double?parsed = double.Parse(value);
                        currentVar.SetValue(doc.Header, parsed, null);
                    }
                    else if (boxedType.Equals(typeof(bool)))
                    {
                        int?parsed = int.Parse(value);
                        if (parsed != 0)
                        {
                            currentVar.SetValue(doc.Header, (bool?)true, null);
                        }
                        else
                        {
                            currentVar.SetValue(doc.Header, (bool?)false, null);
                        }
                    }
                    else if (boxedType.IsEnum)
                    {
                        object parsed = Enum.Parse(boxedType, value);
                        currentVar.SetValue(doc.Header, parsed, null);
                    }
                }
                else if (currentVar.PropertyType.Equals(typeof(DXFPoint)))
                {
                    DXFPoint p = (DXFPoint)currentVar.GetValue(doc.Header, null);
                    if (p == null)
                    {
                        p = new DXFPoint();
                        currentVar.SetValue(doc.Header, p, null);
                    }
                    switch (groupcode)
                    {
                    case 10:
                        p.X = double.Parse(value);
                        break;

                    case 20:
                        p.Y = double.Parse(value);
                        break;

                    case 30:
                        p.Z = double.Parse(value);
                        break;

                    default:
                        break;
                    }
                }
            }
        }