Exemple #1
0
        private static FlushGapPoint DeserializePoint(XmlReader reader)
        {
            var deviation = Property.ObjectToNullableDouble(reader.GetAttribute("Deviation"), CultureInfo.InvariantCulture) ?? 0.0;
            var tolerance = default(Tolerance);
            var position  = new Vector();
            var normal    = new Vector();

            while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
            {
                switch (reader.Name)
                {
                case "Tolerance":
                    tolerance = Tolerance.Deserialize(reader);
                    break;

                case "Position":
                    position = Vector.Deserialize(reader);
                    break;

                case "Normal":
                    normal = Vector.Deserialize(reader);
                    break;
                }
            }

            return(new FlushGapPoint
            {
                Position = position,
                Deviation = deviation,
                Direction = normal,
                Tolerance = tolerance
            });
        }
Exemple #2
0
        /// <summary>
        /// Deserializes formplot data.
        /// </summary>
        /// <param name="metaDataReader">An XML reader to the header xml.</param>
        /// <param name="pointDataStream">A stream of binary formplot point data.</param>
        /// <returns></returns>
        private static Formplot Deserialize(XmlReader metaDataReader, Stream pointDataStream)
        {
            if (metaDataReader == null)
            {
                throw new ArgumentNullException(nameof(metaDataReader));
            }

            var creatorSoftware        = "unknown";
            var creatorSoftwareVersion = new Version(0, 0);
            var properties             = new List <Property>();
            var tolerance           = default(Tolerance);
            var defaultErrorScaling = default(double?);
            var projectionAxis      = ProjectionAxis.None;
            var nominal             = default(Geometry);
            var actual = default(Geometry);
            var points = default(Point[]);

            Enum.TryParse(metaDataReader.GetAttribute("Type"), out FormplotTypes formplotType);

            while (metaDataReader.Read() && metaDataReader.NodeType != XmlNodeType.EndElement)
            {
                switch (metaDataReader.Name)
                {
                case "CreatorSoftware":
                    creatorSoftware = metaDataReader.ReadString();
                    break;

                case "CreatorSoftwareVersion":
                    creatorSoftwareVersion = new Version(metaDataReader.ReadString());
                    break;

                case "Property":
                    properties.Add(Property.Deserialize(metaDataReader));
                    break;

                case "Tolerance":
                    tolerance = Tolerance.Deserialize(metaDataReader);
                    break;

                case "ErrorScaling":
                    defaultErrorScaling = XmlConvert.ToDouble(metaDataReader.ReadString());
                    break;

                case "ProjectionAxis":
                    if (formplotType == FormplotTypes.Straightness)
                    {
                        projectionAxis = ( ProjectionAxis )Enum.Parse(typeof(ProjectionAxis), metaDataReader.ReadString());
                    }
                    else
                    {
                        throw new NotSupportedException("only straightness formplot data supports a projection axis");
                    }
                    break;

                case "Geometry":
                    var geometryString = metaDataReader.GetAttribute("Type");
                    if (EnumParser <GeometryTypes> .TryParse(geometryString, out var geometryType))
                    {
                        if (geometryType != Geometry.GetGeometryTypeFromFormplotType(formplotType))
                        {
                            throw new NotSupportedException($"geometry type \"{geometryType}\" for plot type \"{formplotType}\" is not supported");
                        }

                        while (metaDataReader.Read() && metaDataReader.NodeType != XmlNodeType.EndElement)
                        {
                            switch (metaDataReader.Name)
                            {
                            case "Nominal":
                                nominal = Geometry.DeserializeGeometry(metaDataReader, geometryType);
                                break;

                            case "Actual":
                                actual = Geometry.DeserializeGeometry(metaDataReader, geometryType);
                                break;
                            }
                        }
                    }
                    else
                    {
                        throw new NotSupportedException($"geometry type \"{geometryString}\" is not supported");
                    }

                    break;

                case "Points":
                    points = ReadPoints(formplotType, metaDataReader, pointDataStream);
                    break;
                }
            }

            var plot = CreateFormplot(formplotType);

            plot.CreatorSoftware        = creatorSoftware;
            plot.CreatorSoftwareVersion = creatorSoftwareVersion;
            plot.Properties             = properties.ToArray();
            plot.Tolerance           = tolerance;
            plot.DefaultErrorScaling = defaultErrorScaling;
            plot.ProjectionAxis      = projectionAxis;
            plot.Nominal             = nominal;
            plot.Actual = actual;
            plot.Points = points;

            return(plot);
        }
Exemple #3
0
        /// <summary>
        /// Reads the points from the specified <see cref="Stream"/> and collects their specifications, such as type, tolerance, segment and metadata.
        /// </summary>
        /// <param name="formplotType">Type of the formplot.</param>
        /// <param name="metadataReader">The metadata reader.</param>
        /// <param name="pointdataStream">The pointdata stream.</param>
        /// <returns></returns>
        private static Point[] ReadPoints(FormplotTypes formplotType, XmlReader metadataReader, Stream pointdataStream)
        {
            if (metadataReader == null)
            {
                throw new ArgumentNullException(nameof(metadataReader));
            }

            if (pointdataStream == null)
            {
                throw new ArgumentNullException(nameof(pointdataStream));
            }

            var count          = 0;
            var propertyLists  = new Dictionary <Property, RangeList>();
            var statelists     = new Dictionary <PointState, RangeList>();
            var segmentlists   = new Dictionary <Segment, RangeList>();
            var tolerancelists = new Dictionary <Tolerance, RangeList>();

            while (metadataReader.Read() && metadataReader.NodeType != XmlNodeType.EndElement)
            {
                if (metadataReader.IsEmptyElement)
                {
                    continue;
                }

                switch (metadataReader.Name)
                {
                case "Count":
                    count = XmlConvert.ToInt32(metadataReader.ReadString());
                    break;

                case "Properties":
                    while (metadataReader.Read() && metadataReader.NodeType != XmlNodeType.EndElement)
                    {
                        switch (metadataReader.Name)
                        {
                        case "Property":
                            var points   = RangeList.TryParseOrEmpty(metadataReader.GetAttribute("Points"));
                            var property = Property.Deserialize(metadataReader);
                            propertyLists[property] = points;
                            break;
                        }
                    }
                    break;

                case "States":
                    while (metadataReader.Read() && metadataReader.NodeType != XmlNodeType.EndElement)
                    {
                        switch (metadataReader.Name)
                        {
                        case "State":
                            var points = RangeList.TryParseOrEmpty(metadataReader.GetAttribute("Points"));
                            var text   = metadataReader.ReadString();
                            var value  = ( PointState )Enum.Parse(typeof(PointState), text);
                            statelists[value] = points;
                            break;
                        }
                    }
                    break;

                case "Segments":
                    while (metadataReader.Read() && metadataReader.NodeType != XmlNodeType.EndElement)
                    {
                        switch (metadataReader.Name)
                        {
                        case "Segment":
                            var          points     = RangeList.TryParseOrEmpty(metadataReader.GetAttribute("Points"));
                            var          typeString = metadataReader.GetAttribute("Type");
                            SegmentTypes type;
                            Enum.TryParse(typeString, out type);
                            var name    = metadataReader.ReadString();
                            var segment = new Segment(name, type);
                            segmentlists[segment] = points;
                            break;
                        }
                    }
                    break;

                case "Tolerances":
                    var isTolerancesElement = false;
                    while (metadataReader.NodeType != XmlNodeType.EndElement || !isTolerancesElement)
                    {
                        if (metadataReader.NodeType == XmlNodeType.Element && metadataReader.Name.Equals("Tolerance"))
                        {
                            var points    = RangeList.TryParseOrEmpty(metadataReader.GetAttribute("Points"));
                            var tolerance = Tolerance.Deserialize(metadataReader);
                            tolerancelists[tolerance] = points;
                            metadataReader.Read();
                        }
                        else
                        {
                            metadataReader.Read();
                        }

                        isTolerancesElement = metadataReader.Name.Equals("Tolerances");
                    }
                    break;
                }
            }

            var result = new List <Point>();

            for (var index = 0; index < count; index++)
            {
                var point = Point.Create(formplotType);
                point.ReadFromStream(pointdataStream, index);
                result.Add(point);
            }

            SetProperties(propertyLists, result);
            SetStates(statelists, result);
            SetSegment(segmentlists, result);
            SetTolerance(tolerancelists, result);

            return(result.ToArray());
        }