Esempio n. 1
0
        [HttpGet("Scale/{scaleFactor:float}")]          // GET /api/Editor/scale/2.5
        public IActionResult Scale(float scaleFactor)
        {
            var drawModel = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel");

            if (drawModel != null)
            {
                var newDrawModel = new DrawModel();
                newDrawModel.FileName = drawModel.FileName;

                // circles
                foreach (var circle in drawModel.Circles)
                {
                    var newCenterPoint = Transformation.Scale(circle.Center.PointF, scaleFactor);
                    newDrawModel.AddCircle(newCenterPoint, circle.Radius * scaleFactor, circle.IsVisible);
                }

                // lines
                foreach (var line in drawModel.Lines)
                {
                    var newStartPoint = Transformation.Scale(line.StartPoint.PointF, scaleFactor);
                    var newEndPoint   = Transformation.Scale(line.EndPoint.PointF, scaleFactor);
                    newDrawModel.AddLine(newStartPoint, newEndPoint, line.IsVisible);
                }

                // arcs
                foreach (var a in drawModel.Arcs)
                {
                    var newCenterPoint = Transformation.Scale(a.Center.PointF, scaleFactor);
                    newDrawModel.AddArc(newCenterPoint, a.Radius * scaleFactor, a.StartAngle, a.EndAngle, a.IsClockwise, a.IsVisible);
                }

                // polylines
                foreach (var p in drawModel.Polylines)
                {
                    var newVertexes = new List <PointF>();
                    for (var i = 0; i < p.Vertexes.Count; i++)
                    {
                        var vertex    = p.Vertexes[i];
                        var newVertex = Transformation.Scale(vertex.PointF, scaleFactor);
                        newVertexes.Add(newVertex);
                    }
                    newDrawModel.AddPolyline(newVertexes, p.IsVisible);
                }

                // texts
                foreach (var t in drawModel.Texts)
                {
                    var newStartPoint = Transformation.Scale(t.StartPoint.PointF, scaleFactor);
                    newDrawModel.AddText(newStartPoint, t.Font, t.FontSize * scaleFactor, t.Text);
                }

                // make sure to recalculate the bounds
                newDrawModel.CalculateBounds();

                HttpContext.Session.SetObjectAsJson("DrawModel", newDrawModel);

                return(Ok());
            }
            return(BadRequest());
        }
Esempio n. 2
0
        [HttpGet("Rotate/{degrees:float}")]          // GET /api/Editor/Rotate/20
        public IActionResult Rotate(float degrees)
        {
            var drawModel = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel");

            if (drawModel != null)
            {
                var newDrawModel = new DrawModel();
                newDrawModel.FileName = drawModel.FileName;

                // circles
                foreach (var circle in drawModel.Circles)
                {
                    var newCenterPoint = Transformation.Rotate(circle.Center.PointF, degrees);
                    newDrawModel.AddCircle(newCenterPoint, circle.Radius, circle.IsVisible);
                }

                // lines
                foreach (var line in drawModel.Lines)
                {
                    var newStartPoint = Transformation.Rotate(line.StartPoint.PointF, degrees);
                    var newEndPoint   = Transformation.Rotate(line.EndPoint.PointF, degrees);
                    newDrawModel.AddLine(newStartPoint, newEndPoint, line.IsVisible);
                }

                // arcs
                foreach (var a in drawModel.Arcs)
                {
                    var newCenterPoint = Transformation.Rotate(a.Center.PointF, degrees);

                    // from:
                    // "center":{"x":74.99847,"y":222.5,"z":0}
                    // "radius":10
                    // "thickness":0
                    // "startAngle":-0
                    // "endAngle":90,"

                    // to:
                    // "center":{"x":-104.2983,"y":210.3642,"z":0}
                    // "radius": 10.000049
                    // "thickness": 0
                    // "startAngle": 45.00003
                    // "endAngle": 134.99957

                    newDrawModel.AddArc(newCenterPoint, a.Radius, a.StartAngle + degrees, a.EndAngle + degrees, a.IsVisible, a.IsVisible);
                }

                // polylines
                foreach (var p in drawModel.Polylines)
                {
                    var newVertexes = new List <PointF>();
                    for (var i = 0; i < p.Vertexes.Count; i++)
                    {
                        var vertex    = p.Vertexes[i];
                        var newVertex = Transformation.Rotate(vertex.PointF, degrees);
                        newVertexes.Add(newVertex);
                    }
                    newDrawModel.AddPolyline(newVertexes, p.IsVisible);
                }

                // make sure to recalculate the bounds
                newDrawModel.CalculateBounds();

                HttpContext.Session.SetObjectAsJson("DrawModel", newDrawModel);

                return(Ok());
            }
            return(BadRequest());
        }