Ejemplo n.º 1
0
        private static DiameterConstraint ParseDiameterConstraint(XElement element, double scaleFactorToInches)
        {
            var minAttribute     = element.Attribute("min");
            var maxAttribute     = element.Attribute("max");
            var nominalAttribute = element.Attribute("nominal");

            if (nominalAttribute != null && minAttribute == null && maxAttribute == null)
            {
                double nominalValue;
                if (TryParseDouble(nominalAttribute.Value, out nominalValue))
                {
                    nominalValue *= scaleFactorToInches;
                    return(DiameterConstraint.FromNominalValue(nominalValue));
                }
                else
                {
                    if (nominalAttribute.Value == "Parent")
                    {
                        return(DiameterConstraint.IntersectionWithParentProfile);
                    }
                    else
                    {
                        throw new Exception(string.Format("Unrecognized nominal diameter value at line {0}.", GetLine(nominalAttribute)));
                    }
                }
            }
            else if (minAttribute != null || maxAttribute != null)
            {
                double min = 0;
                double max = double.PositiveInfinity;
                if (minAttribute != null)
                {
                    if (!TryParseDouble(minAttribute.Value, out min))
                    {
                        throw new Exception(string.Format("Could not parse minimum diameter value at line {0}.", GetLine(minAttribute)));
                    }
                }
                if (maxAttribute != null)
                {
                    if (!TryParseDouble(maxAttribute.Value, out max))
                    {
                        throw new Exception(string.Format("Could not parse maximum diameter value at line {0}.", GetLine(maxAttribute)));
                    }
                }

                min *= scaleFactorToInches;
                max *= scaleFactorToInches;

                // TODO: parse an informative nominal diameter that may have also been present

                return(DiameterConstraint.FromMinimumAndMaximum(min, max));
            }
            else
            {
                throw new Exception(string.Format("Conflicting diameter constraints at line {0}. Provide a nominal dimension or min/max dimensions.", GetLine(element)));
            }
        }
        public AbsolutelyPositionedPointProfileConstraint(string name, DiameterConstraint diameterConstraint, double minimumPosition, double maximumPosition)
            : base(name)
        {
            if (double.IsNaN(minimumPosition))
            {
                throw new ArgumentException();
            }
            if (double.IsNaN(maximumPosition))
            {
                throw new ArgumentException();
            }
            if (maximumPosition < minimumPosition)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (Math.Sign(minimumPosition) == -Math.Sign(maximumPosition))
            {
                throw new ArgumentException("Absolute position must definitely lie to one side of the origin or to the other side.");
            }

            _diameterConstraint = diameterConstraint;
            _minimumPosition    = minimumPosition;
            _maximumPosition    = maximumPosition;
        }
Ejemplo n.º 3
0
 public OriginProfileConstraint(string name, DiameterConstraint diameter)
     : base(name)
 {
     _diameter = diameter;
 }