예제 #1
0
        public void AddPolygonLine(int xi1, int yi1, int xi2, int yi2,
                                   double xv1, double yv1, double xv2, double yv2)
        {
            if (ActivePolygon == null)
            {
                ActivePolygon = new PolygonModel();
            }

            double xp1 = xi1 * Config.XIncrement + Config.XStart;
            double yp1 = yi1 * Config.YIncrement + Config.YStart;
            double xp2 = xi2 * Config.XIncrement + Config.XStart;
            double yp2 = yi2 * Config.YIncrement + Config.YStart;

            var line = new Line();

            line.Stroke          = new SolidColorBrush(Colors.Red);
            line.StrokeThickness = 3;
            line.Fill            = new SolidColorBrush(Colors.Red);
            line.X1 = xp1;
            line.Y1 = yp1;
            line.X2 = xp2;
            line.Y2 = yp2;

            ActivePolygon.Lines.Add(new LineModel
            {
                StartPoint = new Vector {
                    X = xv1, Y = yv1, Alternates = new CanvasPoint {
                        DotIndexLeft = xi1, DotIndexTop = yi1
                    }
                },
                EndPoint = new Vector {
                    X = xv2, Y = yv2, Alternates = new CanvasPoint {
                        DotIndexLeft = xi2, DotIndexTop = yi2
                    }
                }
            });

            var cc = new CanvasComponent();

            cc.AddUiElement(line);

            line.Tag = ActivePolygon.Lines[ActivePolygon.Lines.Count - 1];

            polygonLinesInProgress.Add(cc);

            GetInputLayer().AddComponent(cc);

            // if we're at least completing a triangle...
            if (ActivePolygon.Lines.Count > 2)
            {
                // if endpoint of current line matches start point of first line, we're connecting
                // back to start of polygon
                if (GeomMath.AlmostEqual(new Vector {
                    X = xv2, Y = yv2
                }, ActivePolygon.Lines[0].StartPoint))
                {
                    CompletePolygon();
                }
            }
        }
예제 #2
0
        public void DrawLineUsingIndexes(int xi1, int yi1, int xi2, int yi2)
        {
            double xp1 = xi1 * Config.XIncrement + Config.XStart;
            double yp1 = yi1 * Config.YIncrement + Config.YStart;

            double xp2 = xi2 * Config.XIncrement + Config.XStart;
            double yp2 = yi2 * Config.YIncrement + Config.YStart;

            var line = new Line();

            line.Stroke          = new SolidColorBrush(Colors.Red);
            line.StrokeThickness = 1;
            line.Fill            = new SolidColorBrush(Colors.Red);

            line.X1  = xp1;
            line.Y1  = yp1;
            line.X2  = xp2;
            line.Y2  = yp2;
            line.Tag = new LineModel
            {
                StartPoint = new Vector(xp1, yp1, xi1, yi1),
                EndPoint   = new Vector(xp2, yp2, xi2, yi2)
            };

            var cc = new CanvasComponent();

            cc.AddUiElement(line);

            ActiveLayer.AddComponent(cc);
        }
예제 #3
0
        private void DrawGrid()
        {
            if (dotGrid == null)
            {
                dotGrid = new CanvasComponent();
            }

            if (Config == null)
            {
                // If we don't have a configuration yet, create the default...
                Config = new CanvasConfiguration();
                Config.BuildConfiguration(-800, 800, -400, 400,
                                          AttachedCanvas.ActualWidth, AttachedCanvas.ActualHeight,
                                          40, 20, 5, 5);
            }

            ResetGrid();

            double total_x   = Math.Abs(Config.XMin) + Config.XMax;
            double total_y   = Math.Abs(Config.YMin) + Config.YMax;
            double pct_x     = Math.Abs(Config.XMin) / total_x;
            double pct_y     = Math.Abs(Config.YMax) / total_y;
            int    origin_xi = (int)(pct_x * (double)Config.XCount);
            int    origin_yi = (int)(pct_y * (double)Config.YCount);
            double origin_xp = origin_xi * Config.XIncrement + Config.XStart + 1;
            double origin_yp = origin_yi * Config.YIncrement + Config.YStart + 1;

            var axisLine = CreateLine(0, origin_yp, AttachedCanvas.ActualWidth, origin_yp);

            axisLine.Stroke = new SolidColorBrush(Colors.Black);

            if (axisLineX != null)
            {
                GetBaseLayer().RemoveComponent(axisLineX);
                axisLineX.Shapes.Clear();
            }
            else
            {
                axisLineX = new CanvasComponent();
            }

            axisLineX.AddUiElement(axisLine);
            GetBaseLayer().AddComponent(axisLineX);

            axisLine        = CreateLine(origin_xp, 0, origin_xp, AttachedCanvas.ActualHeight);
            axisLine.Stroke = new SolidColorBrush(Colors.Black);

            if (axisLineY != null)
            {
                GetBaseLayer().RemoveComponent(axisLineY);
                axisLineY.Shapes.Clear();
            }
            else
            {
                axisLineY = new CanvasComponent();
            }

            axisLineY.AddUiElement(axisLine);
            GetBaseLayer().AddComponent(axisLineY);
        }
예제 #4
0
        public void HighlightLineUsingValues(double xv1, double yv1, double xv2, double yv2)
        {
            // -------------------------------
            // works-ish
            double xrange = Math.Abs(Config.XMin) + Config.XMax;
            double yrange = Math.Abs(Config.YMin) + Config.YMax;

            double xper = (Config.CanvasWidth - Config.XStart) / xrange;
            double yper = (Config.CanvasHeight - Config.YStart) / yrange;

            var cp_x1 = (Math.Abs(Config.XMin) + xv1) * xper + Config.XStart;
            var cp_y1 = (Math.Abs(Config.YMax) - yv1) * yper + Config.YStart;

            var cp_x2 = (Math.Abs(Config.XMin) + xv2) * xper + Config.XStart;
            var cp_y2 = (Math.Abs(Config.YMax) - yv2) * yper + Config.YStart;
            // -------------------------------

            var line = new Line();

            line.Stroke          = new SolidColorBrush(Colors.Yellow);
            line.StrokeThickness = 6;
            line.Fill            = new SolidColorBrush(Colors.Yellow);

            line.X1 = cp_x1;
            line.Y1 = cp_y1;
            line.X2 = cp_x2;
            line.Y2 = cp_y2;

            var cc = new CanvasComponent();

            cc.AddUiElement(line);
            cc.SendToFarBack();

            ActiveLayer.AddComponent(cc);
        }
예제 #5
0
        public void HighlightPointUsingValues(double xv1, double yv1, int highlightLevel)
        {
            double xrange = Math.Abs(Config.XMin) + Config.XMax;
            double yrange = Math.Abs(Config.YMin) + Config.YMax;

            double xper = (Config.CanvasWidth - Config.XStart) / xrange;
            double yper = (Config.CanvasHeight - Config.YStart) / yrange;

            var cxp = (Math.Abs(Config.XMin) + xv1) * xper + Config.XStart;
            var cyp = (Math.Abs(Config.YMax) - yv1) * yper + Config.YStart;
            // -------------------------------

            double size    = 12;
            double offset  = size / 2;
            var    ellipse = CreateEllipse(size, cxp - offset, cyp - offset);

            ellipse.Stroke = new SolidColorBrush(Colors.Yellow);

            var cc = new CanvasComponent();

            cc.AddUiElement(ellipse);
            cc.SendToFarBack();

            ActiveLayer.AddComponent(cc);
        }
예제 #6
0
파일: CanvasLayer.cs 프로젝트: jsgmu/cs633
        public void AddComponent(CanvasComponent c)
        {
            Components.Add(c);

            if (IsVisible)
            {
                foreach (var s in c.Shapes)
                {
                    AttachedCanvas.Children.Add(s);
                }
            }
        }
예제 #7
0
파일: CanvasLayer.cs 프로젝트: jsgmu/cs633
        public void RemoveComponent(CanvasComponent c)
        {
            if (!Components.Contains(c))
            {
                return;
            }

            foreach (var s in c.Shapes)
            {
                AttachedCanvas.Children.Remove(s);
            }

            Components.Remove(c);
        }
예제 #8
0
        private void CreateDefaultShapes()
        {
            gridPointHighlight = new CanvasComponent();

            double highlightPointSize = 9;

            highlightPointOffset = highlightPointSize / 2;

            Ellipse e = CreateEllipse(highlightPointSize, -10, -10);

            e.Stroke     = new SolidColorBrush(Colors.Red);
            e.Visibility = Visibility.Collapsed;

            gridPointHighlight.AddUiElement(e);
            gridPointHighlight.SendToFarBack();

            GetBaseLayer().AddComponent(gridPointHighlight);
        }
예제 #9
0
        public void AddInputLine(int xi1, int yi1, int xi2, int yi2)
        {
            double xp1 = xi1 * Config.XIncrement + Config.XStart;
            double yp1 = yi1 * Config.YIncrement + Config.YStart;
            double xp2 = xi2 * Config.XIncrement + Config.XStart;
            double yp2 = yi2 * Config.YIncrement + Config.YStart;

            if (InputLines.Count > 0)
            {
                InputLines[InputLines.Count - 1].HighlightLevel = 0;
            }

            EventBus.Publish <LineSetUpdated>(new LineSetUpdated
            {
                Label = "Raw Input",
                Lines = InputLines
            });

            InputLines.Add(new LineModel {
                StartPoint     = new Vector(xp1, yp1, xi1, yi1),
                EndPoint       = new Vector(xp2, yp2, xi2, yi2),
                HighlightLevel = 1
            });

            var line = new Line();

            line.Stroke          = new SolidColorBrush(Colors.Red);
            line.StrokeThickness = 3;
            line.Fill            = new SolidColorBrush(Colors.Red);
            line.Tag             = InputLines[InputLines.Count - 1];
            line.X1 = xp1;
            line.Y1 = yp1;
            line.X2 = xp2;
            line.Y2 = yp2;

            var cc = new CanvasComponent();

            cc.AddUiElement(line);

            GetInputLayer().AddComponent(cc);
        }
예제 #10
0
        public void AddInputPoint(int xi, int yi, double xp, double yp)
        {
            double cxp = xi * Config.XIncrement + Config.XStart;
            double cyp = yi * Config.YIncrement + Config.YStart;

            InputPoints.Add(new Vector {
                X          = xp, Y = yp, HighlightLevel = 1,
                Alternates = new CanvasPoint {
                    DotIndexLeft = xi, DotIndexTop = yi, DotTopPostOffset = -3, DotLeftPostOffset = -3
                }
            });

            if (InputPoints.Count > 0)
            {
                InputPoints[InputPoints.Count - 1].HighlightLevel = 0;
            }

            EventBus.Publish <PointSetUpdated>(new PointSetUpdated
            {
                Label  = "Raw Input",
                Points = InputPoints
            });

            double size    = 6;
            double offset  = size / 2;
            var    ellipse = CreateEllipse(size, cxp - offset, cyp - offset);

            ellipse.Tag    = InputPoints[InputPoints.Count - 1];
            ellipse.Stroke = new SolidColorBrush(Colors.Blue);

            var cc = new CanvasComponent();

            cc.AddUiElement(ellipse);

            GetInputLayer().AddComponent(cc);
        }