Esempio n. 1
0
        [HttpGet("Split/{xSplit:float}/{splitDegrees:float}/{zClearance:float}/{index:int}")]          // GET /api/Editor/Split/20/10/20/0
        public IActionResult Split(float xSplit, float splitDegrees, float zClearance, int index)
        {
            // index means which side to get back
            if (xSplit != 0)
            {
                var splitPoint = new Point3D(xSplit, 0, 0);
                var drawModel  = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel");
                if (drawModel != null)
                {
                    var gCode = DrawModel.ToGCode(drawModel);
                    SaveToFile("before_split.txt", gCode);

                    var parsedInstructions = SimpleGCodeParser.ParseText(gCode);
                    var gCodeArray         = GCodeSplitter.Split(parsedInstructions, splitPoint, splitDegrees, zClearance);
                    SaveToFile("after_split_1.txt", GCodeUtils.GetGCode(gCodeArray[0]));
                    SaveToFile("after_split_2.txt", GCodeUtils.GetGCode(gCodeArray[1]));

                    // clean up the mess with too many G0 commands
                    var cleanedGCode = GCodeUtils.GetMinimizeGCode(gCodeArray[index]);
                    SaveToFile("after_split_clean.txt", GCodeUtils.GetGCode(cleanedGCode));

                    var gCodeResult = Block.BuildGCodeOutput("Block_1", cleanedGCode, false);
                    SaveToFile("after_split_build_output.txt", gCodeResult);

                    // convert gcode to draw model
                    var newDrawModel = DrawModel.FromGCode(gCodeResult, drawModel.FileName);
                    HttpContext.Session.SetObjectAsJson("DrawModel", newDrawModel);
                }
                return(Ok());
            }
            return(BadRequest());
        }
Esempio n. 2
0
        /// <summary>
        /// 画图
        /// </summary>
        /// <param name="InWindowHandle">画框的窗体</param>
        /// <param name="drawModel">框的样式</param>
        /// <param name="hRegion"></param>
        public static void DrawRegion(HTuple InWindowHandle, DrawModel drawModel, out HObject hRegion)
        {
            hRegion = new HObject();
            HOperatorSet.SetLineWidth(InWindowHandle, 1);
            HOperatorSet.SetColor(InWindowHandle, "blue");
            HOperatorSet.SetDraw(InWindowHandle, "margin");
            switch (drawModel)
            {
            case DrawModel.Rectangle1:
                HOperatorSet.DrawRectangle1(InWindowHandle, out HTuple row1, out HTuple column1, out HTuple row2, out HTuple column2);
                HOperatorSet.GenRectangle1(out hRegion, row1, column1, row2, column2);
                HOperatorSet.DispObj(hRegion, InWindowHandle);
                break;

            case DrawModel.Rectangle2:
                HOperatorSet.DrawRectangle2(InWindowHandle, out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2);
                HOperatorSet.GenRectangle2(out hRegion, row, column, phi, length1, length2);
                HOperatorSet.DispObj(hRegion, InWindowHandle);
                break;

            case DrawModel.Circle:
                HOperatorSet.DrawCircle(InWindowHandle, out HTuple row_1, out HTuple column_1, out HTuple radius);
                HOperatorSet.GenCircle(out hRegion, row_1, column_1, radius);
                HOperatorSet.DispObj(hRegion, InWindowHandle);
                break;

            default: return;
            }
        }
Esempio n. 3
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 gCode = DrawModel.ToGCode(drawModel);
                SaveToFile("before_rotate.txt", gCode);

                var parsedInstructions = SimpleGCodeParser.ParseText(gCode);

                var center = new PointF(0, 0);
                if (degrees == 0)
                {
                    degrees = 90;
                }
                var gcodeInstructions = GCodeUtils.GetRotatedGCode(parsedInstructions, center, degrees);
                SaveToFile("after_rotate.txt", GCodeUtils.GetGCode(gcodeInstructions));

                // clean up the mess with too many G0 commands
                var cleanedGCode = GCodeUtils.GetMinimizeGCode(gcodeInstructions);
                SaveToFile("after_rotate_clean.txt", GCodeUtils.GetGCode(cleanedGCode));

                var gCodeResult = Block.BuildGCodeOutput("Block_1", cleanedGCode, false);
                SaveToFile("after_rotate_build_output.txt", gCodeResult);

                // convert gcode to draw model
                var newDrawModel = DrawModel.FromGCode(gCodeResult, drawModel.FileName);
                HttpContext.Session.SetObjectAsJson("DrawModel", newDrawModel);

                return(Ok());
            }
            return(BadRequest());
        }
Esempio n. 4
0
        public void Save(DrawModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }
            var strModel = JsonConvert.SerializeObject(model);

            sqlConnet(_path);
            db.CreateTable <Stock>();

            if (db.Table <Stock>().Count() > 0)
            {
                db.DropTable <Stock>();
                db.CreateTable <Stock>();
            }

            if (db.Table <Stock>().Count() == 0)
            {
                var newStock = new Stock();
                newStock.Data = strModel;
                db.Insert(newStock);
            }
            db.Close();
        }
        public DrawPage(int tournamentID)
        {
            _tournamentID = tournamentID;
            InitializeComponent();

            _model         = new DrawModel(Navigation, tournamentID);
            BindingContext = _model;

            var st    = new StackLayout {
            };
            var frame = new Frame
            {
                CornerRadius      = 20,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Start,
                HasShadow         = true,
                IsClippedToBounds = true,
                Padding           = 0,
                HeightRequest     = 450,
                WidthRequest      = 300,
                BackgroundColor   = Color.FromHex("#D7812A"),
            };

            st.Children.Add(RandomButton);
            st.Children.Add(ManualButton);
            frame.Content = st;
            Layout.Children.Add(frame);
        }
Esempio n. 6
0
 private void TestDrawEvent(DrawEvent evt)
 {
     if (DrawModel.TryGetEventAction(evt, out _))
     {
         PostEvent(evt);
     }
 }
Esempio n. 7
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());
        }
        public JsonResult DrawUpdate(DrawModel draw)
        {
            DrawDAC.Upsert(draw);

            return(Json(new DrawModel {
            }, JsonRequestBehavior.AllowGet));
        }
        public void Setup()
        {
            List <Paint.Draw.Point> points1 = new List <Paint.Draw.Point>()
            {
                new Paint.Draw.Point(10f, 10f), new Paint.Draw.Point(20f, 20f)
            };
            List <Paint.Draw.Point> points2 = new List <Paint.Draw.Point>()
            {
                new Paint.Draw.Point(50f, 50f), new Paint.Draw.Point(20f, 20f)
            };

            Path path  = new Paint.Draw.Path(points1, new Paint.Draw.Color(1, 2, 3), 10f);
            Path path2 = new Paint.Draw.Path(points2, new Paint.Draw.Color(1, 2, 3), 10f);

            testDrawModel = new DrawModel(new List <Paint.Draw.Path>()
            {
                path, path2
            }, new Paint.Draw.Color(1, 2, 3), 15f);


            string pathOne = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string dbPath  = System.IO.Path.Combine(pathOne, "ormbase.db3");

            sQLite = new Paint.Keeper.SQLiteKepper(dbPath);
        }
Esempio n. 10
0
        [HttpGet("SaveSvg/{doSave:bool}")]          // GET /api/Editor/SaveSvg/false
        public IActionResult SaveSvg(bool doSave)
        {
            // traverse through all circles and set the layer whenever the radius is the same
            var drawModel = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel");

            if (drawModel != null)
            {
                // convert to a real svg document
                var svg = DrawModel.ToSvgDocument(drawModel);

                // build new filename
                string fileName    = drawModel.FileName;
                var    newFileName = Path.GetFileNameWithoutExtension(fileName);

                // always use the svg extension since thats what we are saving
                var newFileExtension = ".svg";
                var newFullFileName  = newFileName + newFileExtension;

                if (doSave)
                {
                    var  basePath       = Path.Combine(Directory.GetCurrentDirectory() + "\\Files\\");
                    bool basePathExists = System.IO.Directory.Exists(basePath);
                    if (!basePathExists)
                    {
                        Directory.CreateDirectory(basePath);
                    }

                    var filePath = Path.Combine(basePath, newFullFileName);
                    svg.Write(filePath);
                }
                else
                {
                    // download converted file to user
                    var memoryStream = new MemoryStream();
                    svg.Write(memoryStream);

                    // At this point, the Offset is at the end of the MemoryStream
                    // Either do this to seek to the beginning
                    memoryStream.Position = 0;

                    // have to fix the xml / svg document since
                    // the library used creates tags
                    // that TinkerCad doesn't support
                    var fixedMemStream = FixSvgDocument(memoryStream);

                    return(File(fixedMemStream, "APPLICATION/octet-stream", newFullFileName));
                }
            }
            else
            {
                _logger.LogError("Saving Svg unsuccessfull!");
                return(BadRequest());
            }

            return(Ok());
        }
        public void SerializeKeeperTest()
        {
            string strModel = JsonConvert.SerializeObject(drawModel);

            actualDrawModel = JsonConvert.DeserializeObject <DrawModel>(strModel);

            Assert.AreEqual(drawModel.CurrentLineWidth, actualDrawModel.CurrentLineWidth);
            Assert.AreEqual(drawModel.CurrentColor, actualDrawModel.CurrentColor);
            Assert.AreEqual(drawModel.Paths.Count, actualDrawModel.Paths.Count);
        }
Esempio n. 12
0
        public void Save(DrawModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }
            var strModel = JsonConvert.SerializeObject(model);

            File.WriteAllText(FileName(), strModel);
        }
        public void SQliteKeeperIOSTest()
        {
            sQLite.Save(testDrawModel);

            actualDrawModel = sQLite.Load();

            Assert.AreEqual(testDrawModel.CurrentLineWidth, actualDrawModel.CurrentLineWidth);
            Assert.AreEqual(testDrawModel.CurrentColor, actualDrawModel.CurrentColor);
            Assert.AreEqual(testDrawModel.Paths.Count, actualDrawModel.Paths.Count);
        }
Esempio n. 14
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        ///

        // Set the position of the camera in world space, for our view matrix.
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            DrawModel.DrawBicycle(models, viewMatrix, projectionMatrix, createRotation, bicycleRotation, bicyclePosition, ref worldMatrixbb, 3);
            DrawModel.DrawRoad(models[0], vectors[0], viewMatrix, projectionMatrix);
            DrawModel.DrawRoad(models[4], vectors[4], viewMatrix, projectionMatrix);

            base.Draw(gameTime);
        }
        public void RealmKeeperIOSTest()
        {
            realm1 = new RealmKeeper();
            realm1.Save(testDrawModel);
            actualDrawModel = realm1.Load();

            Assert.AreEqual(testDrawModel.CurrentLineWidth, actualDrawModel.CurrentLineWidth);
            Assert.AreEqual(testDrawModel.CurrentColor, actualDrawModel.CurrentColor);
            Assert.AreEqual(testDrawModel.Paths.Count, actualDrawModel.Paths.Count);
        }
Esempio n. 16
0
        public void FileKeeperDroidTest()
        {
            file = new FileKeeperDroid();
            file.Save(testDrawModel);

            actualDrawModel = file.Load();

            Assert.AreEqual(testDrawModel.CurrentLineWidth, actualDrawModel.CurrentLineWidth);
            Assert.AreEqual(testDrawModel.CurrentColor, actualDrawModel.CurrentColor);
            Assert.AreEqual(testDrawModel.Paths.Count, actualDrawModel.Paths.Count);
        }
Esempio n. 17
0
        public static void Upsert(DrawModel draw)
        {
            SqlConnection oCon = new SqlConnection();
            SqlCommand    oCmd = new SqlCommand();

            try
            {
                oCon.ConnectionString = ConfigurationManager.ConnectionStrings["Quiniela"].ToString();
                oCon.Open();
                oCmd.Connection = oCon;

                oCmd.CommandText = "Draw_Upsert";
                oCmd.CommandType = CommandType.StoredProcedure;

                if (draw.Id.HasValue)
                {
                    oCmd.Parameters.AddWithValue("@Id", draw.Id);
                }
                if (draw.GameId.HasValue)
                {
                    oCmd.Parameters.AddWithValue("@GameId", draw.GameId);
                }
                if (draw.GameModeId.HasValue)
                {
                    oCmd.Parameters.AddWithValue("@GameModeId", draw.GameModeId);
                }
                if (draw.Date.HasValue)
                {
                    oCmd.Parameters.AddWithValue("@Date", draw.Date);
                }
                if (draw.Number.HasValue)
                {
                    oCmd.Parameters.AddWithValue("@Number", draw.Number);
                }
                if (draw.StatusId.HasValue)
                {
                    oCmd.Parameters.AddWithValue("@StatusId", draw.StatusId);
                }

                Int64 Id = Convert.ToInt64(oCmd.ExecuteScalar());

                oCmd.Dispose();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                oCon.Close();
                oCon.Dispose();
            }
        }
Esempio n. 18
0
 private void LoadFile()
 {
     try
     {
         _drawModel = _drawKeeper.Load();
         _paintView.UpdateView(_drawModel.Paths);
     }
     catch
     {
         _drawModel = new DrawModel();
         _paintView.UpdateView(_drawModel.Paths);
     }
 }
        public void Save(DrawModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var strModel = JsonConvert.SerializeObject(model);

            //Core
            NSUserDefaults.StandardUserDefaults.SetString(strModel, UserDefaultsKey);
            NSUserDefaults.StandardUserDefaults.Synchronize();
        }
Esempio n. 20
0
 private void LoadFile()
 {
     try
     {
         _drawModel = _drawKeeper.Load();
         _drawingLine.UpdateView(_drawModel.Paths);
     }
     catch (System.Exception ex)
     {
         _drawModel = new DrawModel();
         _drawingLine.UpdateView(_drawModel.Paths);
     }
 }
Esempio n. 21
0
        public void SQLiteKeeperDroidTest()
        {
            string pathOne = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string dbPath  = System.IO.Path.Combine(pathOne, "ormbase.db3");

            sqlite = new Paint.Keeper.SQLiteKepper(dbPath);
            sqlite.Save(testDrawModel);

            actualDrawModel = sqlite.Load();

            Assert.AreEqual(testDrawModel.CurrentLineWidth, actualDrawModel.CurrentLineWidth);
            Assert.AreEqual(testDrawModel.CurrentColor, actualDrawModel.CurrentColor);
            Assert.AreEqual(testDrawModel.Paths.Count, actualDrawModel.Paths.Count);
        }
Esempio n. 22
0
        public DrawModel Load()
        {
            sqlConnet(_path);
            var table = db.Table <Stock>();

            foreach (var mod in table)
            {
                drawModel = JsonConvert.DeserializeObject <DrawModel>(mod.Data);
            }
            ;

            db.Close();
            return(drawModel);
        }
Esempio n. 23
0
        public ActionResult Draw(DrawModel draw)
        {
            DrawLoadCombos();

            if (!draw.DateFrom.HasValue && !draw.DateTo.HasValue)
            {
                draw.DateFrom = DateTime.Now.AddDays(-7);
                draw.DateTo   = DateTime.Now.AddDays(7);
            }

            List <DrawModel> draws = DrawDAC.Get(draw);

            return(View(draws));
        }
Esempio n. 24
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            var menu = FindViewById <@Android.Support.V7.Widget.Toolbar>(Resource.Id.menuForSave);

            SetSupportActionBar(menu);
            LinearLayout linear = FindViewById <LinearLayout>(Resource.Id.viewDraw);

            _drawingLine = new DrawLine(this);
            linear.AddView(_drawingLine);
            _drawingLine.Delegate = this;
            _drawModel            = new DrawModel();
            ButtonInitialize();
        }
        public void Save(DrawModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var strModel    = JsonConvert.SerializeObject(model);
            var backingFile = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), UserDefaultsKey);

            using (var writer = File.CreateText(backingFile))
            {
                writer.WriteLine(strModel);
            }
        }
        public void Save(DrawModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            strModel = JsonConvert.SerializeObject(model);

            //Core
            ISharedPreferences       prefs  = PreferenceManager.GetDefaultSharedPreferences(mContext);
            ISharedPreferencesEditor editor = prefs.Edit();

            editor.PutString(UserDefaultsKey, strModel);
            editor.Apply();
        }
Esempio n. 27
0
        public void Save(DrawModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }
            var       realm    = Realm.GetInstance();
            var       strModel = JsonConvert.SerializeObject(model);
            DrawRealm draw     = new DrawRealm();

            draw.DrowModelJsong = strModel;
            realm.Write(() =>
            {
                realm.Add(draw);
            });
        }
Esempio n. 28
0
        [HttpPost("AddText")]         // POST /api/Editor/AddText
        public async Task <IActionResult> AddText([FromForm] string font, [FromForm] float fontSize, [FromForm] string text, [FromForm] float startX, [FromForm] float startY)
        {
            // traverse through all circles and set the layer whenever the radius is the same
            var drawModel = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel");

            if (drawModel == null)
            {
                // create model
                drawModel          = new DrawModel();
                drawModel.FileName = "Unnamed";
            }

            drawModel.AddText(new PointF(startX, startY), font, fontSize, text);

            // update model
            HttpContext.Session.SetObjectAsJson("DrawModel", drawModel);

            return(Ok());
        }
Esempio n. 29
0
        [HttpGet("Split/{xSplit:float}/{splitDegrees:float}/{zClearance:float}")]          // GET /api/Editor/Split/100/0/10
        public IActionResult Split(float xSplit, float splitDegrees, float zClearance)
        {
            // index means which side to get back
            if (xSplit != 0)
            {
                var splitPoint = new Point3D(xSplit, 0, 0);
                var drawModel  = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel");
                if (drawModel != null)
                {
                    var gCode = DrawModel.ToGCode(drawModel);
                    // SaveToFile("before_split.txt", gCode);

                    var parsedInstructions = SimpleGCodeParser.ParseText(gCode);
                    var gCodeArray         = GCodeSplitter.Split(parsedInstructions, splitPoint, splitDegrees, zClearance);
                    // SaveToFile("after_split_1.txt", GCodeUtils.GetGCode(gCodeArray[0]));
                    // SaveToFile("after_split_2.txt", GCodeUtils.GetGCode(gCodeArray[1]));

                    // clean up the mess with too many G0 commands
                    var cleanedGCode1 = GCodeUtils.GetMinimizeGCode(gCodeArray[0]);
                    var cleanedGCode2 = GCodeUtils.GetMinimizeGCode(gCodeArray[1]);
                    // SaveToFile("after_split_clean_1.txt", GCodeUtils.GetGCode(cleanedGCode1));
                    // SaveToFile("after_split_clean_2.txt", GCodeUtils.GetGCode(cleanedGCode2));

                    var gCodeResult1 = Block.BuildGCodeOutput("Block_1", cleanedGCode1, false);
                    var gCodeResult2 = Block.BuildGCodeOutput("Block_1", cleanedGCode2, false);
                    // SaveToFile("after_split_build_output_1.txt", gCodeResult1);
                    // SaveToFile("after_split_build_output_2.txt", gCodeResult2);

                    // convert gcode to draw model
                    var fileName  = Path.GetFileNameWithoutExtension(drawModel.FileName);
                    var extension = Path.GetExtension(drawModel.FileName);

                    var newDrawModel1 = DrawModel.FromGCode(gCodeResult1, fileName + "_split_1" + extension);
                    var newDrawModel2 = DrawModel.FromGCode(gCodeResult2, fileName + "_split_2" + extension);

                    // store with index
                    HttpContext.Session.SetObjectAsJson("Split-0", newDrawModel1);
                    HttpContext.Session.SetObjectAsJson("Split-1", newDrawModel2);
                }
                return(Ok());
            }
            return(BadRequest());
        }
Esempio n. 30
0
        public void Setup()
        {
            List <Paint.Draw.Point> points1 = new List <Paint.Draw.Point>()
            {
                new Paint.Draw.Point(10f, 10f), new Paint.Draw.Point(20f, 20f)
            };
            List <Paint.Draw.Point> points2 = new List <Paint.Draw.Point>()
            {
                new Paint.Draw.Point(50f, 50f), new Paint.Draw.Point(20f, 20f)
            };

            Path path  = new Path(points1, new Paint.Draw.Color(1, 2, 3), 10f);
            Path path2 = new Path(points2, new Paint.Draw.Color(1, 2, 3), 10f);

            testDrawModel = new DrawModel(new List <Paint.Draw.Path>()
            {
                path, path2
            }, new Paint.Draw.Color(1, 2, 3), 15f);
        }