Exemplo n.º 1
0
        void openJson(string path)
        {
            string file = "";

            using (StreamReader sr = new StreamReader(new FileStream(path, FileMode.Open)))
            {
                file = sr.ReadToEnd();
            }

            try
            {
                string[] lines = file.Split('\n');

                for (int i = 0; i < lines.Length - 1; i++) //point round
                {
                    if (lines[i].Split('{')[0] == "Point")
                    {
                        Point p = new Point(lines[i].Split('{')[1].Split('}')[0]);
                        objectsInSketch.Add(p);
                        if (p.Name == "origin")
                        {
                            origin = p;
                        }
                    }
                }
                for (int i = 0; i < lines.Length - 1; i++) //line round
                {
                    if (lines[i].Split('{')[0] == "Line")
                    {
                        Line l = new Line(lines[i].Split('{')[1].Split('}')[0]);

                        Object p0 = objectsInSketch.Where(x => x.Name == l.StartPoint.Name).First();
                        Object p1 = objectsInSketch.Where(x => x.Name == l.EndPoint.Name).First();

                        l.StartPoint = p0 as Point;
                        l.EndPoint   = p1 as Point;

                        objectsInSketch.Add(l);
                    }
                }
                for (int i = 0; i < lines.Length - 1; i++) //circle round
                {
                    if (lines[i].Split('{')[0] == "Circle")
                    {
                        Circle c = new Circle(lines[i].Split('{')[1].Split('}')[0]);

                        Object p = objectsInSketch.Where(x => x.Name == c.Center.Name).First();

                        c.Center = p as Point;

                        objectsInSketch.Add(c);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Invalid file");
            }

            refreshObjectListView();
        }
Exemplo n.º 2
0
        private void drawingArea_Click(object sender, EventArgs e)
        {
            if (MouseButtons.Right == ((MouseEventArgs)e).Button)
            {
                selectedTool = "";
                resetselectedTool(null);
            }

            setTopLabel();
            this.Text += "*";
            drawingArea.Focus();

            if (selectedTool != "")
            {
                //use the mouse point in order to allow point snapping
                firstLastPoint = mousePoint;

                if (secondLastPoint == null)//if it is the first click
                {
                    secondLastPoint = firstLastPoint;
                    firstLastPoint  = null;
                    secondLastPoint = pointSnapping(secondLastPoint);

                    //reset the lenght input
                    prewievLenghtValue.Text = "";
                }
                else
                {
                    switch (selectedTool) //tool switch
                    {
                    case "line":
                        if (!objectsInSketch.Contains(secondLastPoint))
                        {
                            secondLastPoint = addPoint(secondLastPoint.systemPoint);
                        }
                        if (!objectsInSketch.Contains(firstLastPoint))
                        {
                            firstLastPoint = addPoint(firstLastPoint.systemPoint);
                        }
                        addLine(secondLastPoint, firstLastPoint);
                        break;

                    case "rectangle":
                        if (!objectsInSketch.Contains(firstLastPoint))
                        {
                            firstLastPoint = addPoint(firstLastPoint.systemPoint);
                        }
                        if (!objectsInSketch.Contains(secondLastPoint))
                        {
                            secondLastPoint = addPoint(secondLastPoint.systemPoint);
                        }

                        Point p0 = addPoint(new System.Drawing.Point(secondLastPoint.X, firstLastPoint.Y));
                        Point p1 = addPoint(new System.Drawing.Point(firstLastPoint.X, secondLastPoint.Y));

                        Line l0 = addLine(firstLastPoint, p0);
                        Line l1 = addLine(firstLastPoint, p1);
                        Line l2 = addLine(p0, secondLastPoint);
                        Line l3 = addLine(p1, secondLastPoint);

                        //add parael ties
                        //l0.ParaelLines.Add(l3);
                        //l3.ParaelLines.Add(l0);
                        //l2.ParaelLines.Add(l1);
                        l1.ParaelLines.Add(l2);

                        //add perpendicular ties
                        l0.PerpLines.Add(l1);
                        l0.PerpLines.Add(l2);
                        l1.PerpLines.Add(l0);
                        l1.PerpLines.Add(l3);
                        l2.PerpLines.Add(l0);
                        l2.PerpLines.Add(l3);
                        l3.PerpLines.Add(l1);
                        l3.PerpLines.Add(l2);

                        break;

                    case "circle":
                        if (!objectsInSketch.Contains(secondLastPoint))
                        {
                            secondLastPoint = addPoint(secondLastPoint.systemPoint);
                        }
                        addCircle(secondLastPoint, firstLastPoint.distance(secondLastPoint));
                        break;
                    }

                    //if tool require it, set last point to second one
                    if (selectedTool == "line")
                    {
                        secondLastPoint = firstLastPoint;
                    }
                    else
                    {
                        secondLastPoint = null;
                    }
                    firstLastPoint = null;
                }
            }

            refreshObjectListView();

            //set point label
            if (secondLastPoint != null)
            {
                secondLastPointLabelValue.Text = secondLastPoint.ToString();
            }
            else
            {
                secondLastPointLabelValue.Text = "";
            }
        }