Example #1
0
        private void TestParse(string text, double expected)
        {
            double actual;

            Assert.True(DrawingSettings.TryParseUnits(text, out actual));
            Assert.Equal(expected, actual);
        }
Example #2
0
        private void ReparsePoint()
        {
            if (dontParse)
            {
                return;
            }

            // TODO: make this more robust
            var parts = viewModel.PointString.Split(",".ToCharArray());

            if (parts.Length == 3)
            {
                double value;
                var    x = 0.0;
                var    y = 0.0;
                var    z = 0.0;
                if (DrawingSettings.TryParseUnits(parts[0], out value))
                {
                    x = value;
                }
                if (DrawingSettings.TryParseUnits(parts[1], out value))
                {
                    y = value;
                }
                if (DrawingSettings.TryParseUnits(parts[2], out value))
                {
                    z = value;
                }
                Point = new Point(x, y, z);
            }
        }
Example #3
0
 public void SubmitInput(string text)
 {
     if (_workspace.InputService.AllowedInputTypes.HasFlag(InputType.Directive) &&
         _workspace.InputService.AllowedDirectives.Contains(text))
     {
         _workspace.InputService.PushDirective(text);
     }
     else if (_workspace.InputService.AllowedInputTypes.HasFlag(InputType.Distance))
     {
         if (string.IsNullOrEmpty(text))
         {
             _workspace.InputService.PushNone();
         }
         else if (DrawingSettings.TryParseUnits(text, out var dist))
         {
             _workspace.InputService.PushDistance(dist);
         }
     }
     else if (_workspace.InputService.AllowedInputTypes.HasFlag(InputType.Point))
     {
         var cursorPoint = _workspace.ViewControl.GetCursorPoint(CancellationToken.None).Result;
         if (_workspace.InputService.TryParsePoint(text, cursorPoint, _workspace.InputService.LastPoint, out var point))
         {
             _workspace.InputService.PushPoint(point);
         }
     }
     else if (_workspace.InputService.AllowedInputTypes.HasFlag(InputType.Command))
     {
         _workspace.InputService.PushCommand(string.IsNullOrEmpty(text) ? null : text);
     }
     else if (_workspace.InputService.AllowedInputTypes.HasFlag(InputType.Text))
     {
         _workspace.InputService.PushText(text ?? string.Empty);
     }
 }
Example #4
0
        public (double scaleA, double scaleB) GetUnitAdjustedScale(DrawingSettings drawingSettings)
        {
            var drawingUnits      = drawingSettings.UnitFormat == UnitFormat.Architectural ? PdfMeasurementType.Inch : PdfMeasurementType.Mm;
            var scaleAValue       = DrawingSettings.TryParseUnits(ScaleA, out var parsedScaleA) ? parsedScaleA : 1.0;
            var scaleBValue       = DrawingSettings.TryParseUnits(ScaleB, out var parsedScaleB) ? parsedScaleB : 1.0;
            var scaleAMeasurement = new PdfMeasurement(scaleAValue, drawingUnits);

            return(scaleAMeasurement.ConvertTo(PdfMeasurementType.Point).RawValue, scaleBValue);
        }
Example #5
0
        internal static ClientPropertyPaneValue CreateForEntityWithUnits <TEntity>(string name, string displayName, string value, Func <TEntity, double, Entity> entityTransformer, IEnumerable <string> allowedValues = null, bool isUnrepresentable = false)
            where TEntity : Entity
        {
            return(CreateForEntity <TEntity>(name, displayName, value, (entity, valueToSet) =>
            {
                if (DrawingSettings.TryParseUnits(valueToSet, out var unitValue))
                {
                    var updatedEntity = entityTransformer(entity, unitValue);
                    return updatedEntity;
                }

                return null;
            }, allowedValues, isUnrepresentable));
        }
Example #6
0
        private void SubmitValue()
        {
            var text = inputLine.Text;

            if (Workspace.InputService.AllowedInputTypes.HasFlag(InputType.Directive) &&
                Workspace.InputService.AllowedDirectives.Contains(text))
            {
                Workspace.InputService.PushDirective(text);
            }
            else if (Workspace.InputService.AllowedInputTypes.HasFlag(InputType.Distance))
            {
                double dist = 0.0;
                if (string.IsNullOrEmpty(text))
                {
                    Workspace.InputService.PushNone();
                }
                else if (DrawingSettings.TryParseUnits(text, out dist))
                {
                    Workspace.InputService.PushDistance(dist);
                }
            }
            else if (Workspace.InputService.AllowedInputTypes.HasFlag(InputType.Point))
            {
                Point point;
                var   cursorPoint = Workspace.ViewControl.GetCursorPoint(CancellationToken.None).Result;
                if (Workspace.InputService.TryParsePoint(text, cursorPoint, Workspace.InputService.LastPoint, out point))
                {
                    Workspace.InputService.PushPoint(point);
                }
            }
            else if (Workspace.InputService.AllowedInputTypes.HasFlag(InputType.Command))
            {
                Workspace.InputService.PushCommand(string.IsNullOrEmpty(text) ? null : text);
            }
            else if (Workspace.InputService.AllowedInputTypes.HasFlag(InputType.Text))
            {
                Workspace.InputService.PushText(text ?? string.Empty);
            }

            inputLine.Text = string.Empty;
        }
Example #7
0
        private void ParseFail(string text)
        {
            double temp;

            Assert.False(DrawingSettings.TryParseUnits(text, out temp));
        }
Example #8
0
        // static to ensure there are no calls to LastPoint, Workspace, etc.
        private static bool TryParsePointHelper(string text, Point currentCursor, Point lastPoint, out Point point)
        {
            var result = false;

            point = default(Point);

            // if only 2 coordinates given
            if (text.ToCharArray().Count(c => c == ',') == 1)
            {
                text += ",0";
            }

            double value = 0.0;

            if (DrawingSettings.TryParseUnits(text, out value))
            {
                // length on current vector
                var length = value;
                var cursor = currentCursor;
                var vec    = cursor - lastPoint;
                if (vec.LengthSquared == 0.0)
                {
                    // if no change, report nothing
                }
                else
                {
                    vec    = vec.Normalize() * length;
                    point  = lastPoint + vec;
                    result = true;
                }
            }
            else if (relativePoint.IsMatch(text))
            {
                // offset from last point
                var offset = Point.Parse(text.Substring(1));
                point  = lastPoint + offset;
                result = true;
            }
            else if (relativeAngle.IsMatch(text))
            {
                // distance and angle
                var parts = text.Split("<".ToCharArray(), 2);
                if (DrawingSettings.TryParseUnits(parts[0], out value))
                {
                    var dist    = value;
                    var angle   = double.Parse(parts[1], NumberStyles.Float, CultureInfo.CurrentCulture);
                    var radians = angle * MathHelper.DegreesToRadians;
                    var offset  = new Vector(Math.Cos(radians), Math.Sin(radians), 0) * dist;
                    point  = lastPoint + offset;
                    result = true;
                }
                else
                {
                    // distance was invalid
                }
            }
            else if (Point.PointPattern.IsMatch(text))
            {
                // absolute point
                point  = Point.Parse(text);
                result = true;
            }
            else
            {
                // invalid point
            }

            return(result);
        }