Example #1
0
            public Geometry.Box Aabb(Geometry.Traits traits, bool calculateEnvelope)
            {
                Geometry.Box box = null;

                for (int i = 0; i < this.Count; ++i)
                {
                    Geometry.Point p = this[i];

                    // TODO: in general it's not necessary to create a box here
                    Geometry.Box b = new Geometry.Box(new Geometry.Point(p[0], p[1]),
                                                      new Geometry.Point(p[0], p[1]));

                    if (box == null)
                    {
                        box = b;
                    }
                    else
                    {
                        if (calculateEnvelope)
                        {
                            Geometry.Expand(box, b, traits);
                        }
                        else
                        {
                            Geometry.Expand(box, b);
                        }
                    }
                }

                if (box == null)
                {
                    Geometry.AssignInverse(box);
                }

                return(box);
            }
Example #2
0
 public void Draw(Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits)
 {
     DrawPolygon(this, box, graphics, settings, traits);
 }
Example #3
0
 public Geometry.Box Aabb(Geometry.Traits traits, bool calculateEnvelope)
 {
     return(AabbPolygon(this, traits, calculateEnvelope));
 }
Example #4
0
 public Geometry.Box Aabb(Geometry.Traits traits, bool calculateEnvelope)
 {
     return(AabbRange(this, true, traits, calculateEnvelope));
 }
Example #5
0
        private static void DrawPolygon(Geometry.Polygon polygon, Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits)
        {
            LocalCS cs     = new LocalCS(box, graphics);
            Drawer  drawer = new Drawer(graphics, settings.color);

            if (traits.Unit == Geometry.Unit.None)
            {
                PointF[] dst_outer_points = cs.Convert(polygon.Outer);
                if (dst_outer_points != null)
                {
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddPolygon(dst_outer_points);

                    if (settings.showDir)
                    {
                        drawer.DrawDirs(dst_outer_points, true);
                        drawer.DrawPoint(dst_outer_points[0]);
                    }

                    foreach (Ring inner in polygon.Inners)
                    {
                        PointF[] dst_inner_points = cs.Convert(inner);
                        if (dst_inner_points != null)
                        {
                            gp.AddPolygon(dst_inner_points);

                            if (settings.showDir)
                            {
                                drawer.DrawDirs(dst_inner_points, true);
                                drawer.DrawPoint(dst_inner_points[0]);
                            }
                        }
                    }

                    drawer.FillPath(gp);
                    drawer.DrawPath(gp);
                }
            }
            else
            {
                Drawer.PeriodicDrawablePolygon pd = new Drawer.PeriodicDrawablePolygon(cs, polygon.Outer, polygon.Inners, traits.Unit, settings.densify);
                Geometry.Interval interval        = RelativeEnvelopeLon(polygon.Outer, polygon.Inners, traits.Unit);
                drawer.DrawPeriodic(cs, box, interval, traits.Unit, pd, true, settings.showDir, settings.showDots);

                if (settings.showDir)
                {
                    if (settings.showDir && polygon.Outer.Count > 0)
                    {
                        drawer.DrawPeriodicPoint(cs, polygon.Outer[0], box, traits.Unit, settings.showDots);
                    }

                    foreach (Ring inner in polygon.Inners)
                    {
                        if (inner.Count > 0)
                        {
                            drawer.DrawPeriodicPoint(cs, inner[0], box, traits.Unit, settings.showDots);
                        }
                    }
                }
            }
        }
Example #6
0
        private void UpdateItems(bool load, int modified_index = -1)
        {
            m_currentBox = null;

            bool imageEmpty = true;

            if (ExpressionLoader.Debugger.CurrentMode == dbgDebugMode.dbgBreakMode)
            {
                if (load)
                {
                    ExpressionLoader.ReloadUserTypes(Util.GetDialogPage <GeneralOptionPage>());
                }

                ExpressionDrawer.Settings referenceSettings = new ExpressionDrawer.Settings();
                PlotWatchOptionPage       optionPage        = Util.GetDialogPage <PlotWatchOptionPage>();
                if (optionPage != null)
                {
                    if (optionPage.ValuePlot_EnableBars || optionPage.ValuePlot_EnableLines || optionPage.ValuePlot_EnablePoints)
                    {
                        referenceSettings.valuePlot_enableBars   = optionPage.ValuePlot_EnableBars;
                        referenceSettings.valuePlot_enableLines  = optionPage.ValuePlot_EnableLines;
                        referenceSettings.valuePlot_enablePoints = optionPage.ValuePlot_EnablePoints;
                    }
                    if (optionPage.PointPlot_EnableLines || optionPage.PointPlot_EnablePoints)
                    {
                        referenceSettings.pointPlot_enableLines  = optionPage.PointPlot_EnableLines;
                        referenceSettings.pointPlot_enablePoints = optionPage.PointPlot_EnablePoints;
                    }
                }

                // TODO: Names are redundant
                string[] names = new string[Plots.Count];
                ExpressionDrawer.Settings[] settings = new ExpressionDrawer.Settings[Plots.Count];
                bool tryDrawing = false;

                // update the list, gather names and settings
                for (int index = 0; index < Plots.Count; ++index)
                {
                    PlotItem geometry = Plots[index];

                    System.Windows.Media.Color color = geometry.Color;
                    int    colorId = geometry.ColorId;
                    string type    = null;

                    bool updateRequred = modified_index < 0 || modified_index == index;

                    if (updateRequred && load)
                    {
                        geometry.Drawable = null;
                        geometry.Traits   = null;
                    }

                    if (geometry.Name != null && geometry.Name != "")
                    {
                        var expressions = updateRequred
                                        ? ExpressionLoader.GetExpressions(geometry.Name)
                                        : null;

                        if (expressions == null || ExpressionLoader.AllValidValues(expressions))
                        {
                            if (expressions != null)
                            {
                                type = ExpressionLoader.TypeFromExpressions(expressions);
                            }

                            names[index] = geometry.Name;

                            if (updateRequred && geometry.ColorId < 0)
                            {
                                colorId = m_intsPool.Pull();
                                color   = Util.ConvertColor(m_colors[colorId]);
                            }

                            settings[index] = referenceSettings.CopyColored(color);

                            tryDrawing = true;
                        }
                    }

                    // set new row
                    if (updateRequred)
                    {
                        ResetAt(new PlotItem(geometry.Drawable, geometry.Traits,
                                             geometry.Name, type, colorId, m_colors),
                                index);
                    }
                }

                // draw variables
                if (tryDrawing)
                {
                    int width  = (int)System.Math.Round(image.ActualWidth);
                    int height = (int)System.Math.Round(image.ActualHeight);
                    if (width > 0 && height > 0)
                    {
                        Bitmap bmp = new Bitmap(width, height);

                        Graphics graphics = Graphics.FromImage(bmp);
                        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        graphics.Clear(m_colors.ClearColor);

                        try
                        {
                            ExpressionDrawer.IDrawable[] drawables = new ExpressionDrawer.IDrawable[names.Length];
                            Geometry.Traits[]            traits    = new Geometry.Traits[names.Length];
                            for (int i = 0; i < names.Length; ++i)
                            {
                                if (Plots[i].Drawable == null && names[i] != null && names[i] != "")
                                {
                                    ExpressionDrawer.IDrawable d = null;
                                    Geometry.Traits            t = null;
                                    ExpressionLoader.Load(names[i], ExpressionLoader.OnlyMultiPoints, out t, out d);
                                    if (d != null)
                                    {
                                        if (t != null)
                                        {
                                            t = new Geometry.Traits(t.Dimension); // force cartesian
                                        }
                                        d = new ExpressionDrawer.PointsContainer(d as ExpressionDrawer.MultiPoint);
                                    }
                                    else
                                    {
                                        ExpressionLoader.Load(names[i], ExpressionLoader.OnlyContainers, out t, out d);
                                    }
                                    Plots[i].Drawable = d;
                                    Plots[i].Traits   = t;
                                }
                                drawables[i] = Plots[i].Drawable;
                                traits[i]    = Plots[i].Traits;
                            }

                            m_currentBox = ExpressionDrawer.DrawPlots(graphics, drawables, traits, settings, m_colors, m_zoomBox);
                        }
                        catch (Exception e)
                        {
                            ExpressionDrawer.DrawErrorMessage(graphics, e.Message);
                        }

                        image.Source = Util.BitmapToBitmapImage(bmp);
                        imageEmpty   = false;
                    }
                }
            }

            if (imageEmpty)
            {
                image.Source = Util.BitmapToBitmapImage(m_emptyBitmap);
            }

            imageGrid.ContextMenu = new ContextMenu();
            MenuItem mi = new MenuItem();

            mi.Header = "Copy";
            mi.Click += MenuItem_Copy;
            if (imageEmpty)
            {
                mi.IsEnabled = false;
            }
            imageGrid.ContextMenu.Items.Add(mi);
            imageGrid.ContextMenu.Items.Add(new Separator());
            MenuItem mi2 = new MenuItem();

            mi2.Header = "Reset View";
            mi2.Click += MenuItem_ResetZoom;
            if (imageEmpty)
            {
                mi2.IsEnabled = false;
            }
            imageGrid.ContextMenu.Items.Add(mi2);
        }
        private void UpdateItem(bool load, int index)
        {
            GraphicalItem variable = Variables[index];

            if (ExpressionLoader.IsBreakMode)
            {
                if (load)
                {
                    ExpressionLoader.ReloadUserTypes(Util.GetDialogPage <GeneralOptionPage>());
                }

                // Load settings from option page
                ExpressionDrawer.Settings settings = GetOptions();

                (dataGrid.Columns[1] as DataGridTemplateColumn).Width = settings.imageWidth + 1;
                dataGrid.RowHeight = settings.imageHeight + 1;

                if (load)
                {
                    variable.Drawable = null;
                    variable.Traits   = null;
                    variable.Bmp      = null;
                    variable.Type     = null;
                    variable.Error    = null;
                }

                if (variable.Name != null && variable.Name != "")
                {
                    var expressions = ExpressionLoader.GetExpressions(variable.Name);
                    if (ExpressionLoader.AllValidValues(expressions))
                    {
                        // create bitmap
                        variable.Bmp = new Bitmap(settings.imageWidth, settings.imageHeight);

                        Graphics graphics = Graphics.FromImage(variable.Bmp);
                        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        graphics.Clear(Util.Colors.ClearColor);

                        try
                        {
                            if (variable.Drawable == null)
                            {
                                Geometry.Traits            traits   = null;
                                ExpressionDrawer.IDrawable drawable = null;
                                ExpressionLoader.Load(variable.Name, out traits, out drawable);

                                if (drawable != null &&
                                    settings.displayMultiPointsAsPlots &&
                                    drawable is ExpressionDrawer.MultiPoint)
                                {
                                    drawable = new ExpressionDrawer.PointsContainer(drawable as ExpressionDrawer.MultiPoint);
                                }

                                variable.Drawable = drawable;
                                variable.Traits   = traits;
                            }
                            else
                            {
                                if (settings.displayMultiPointsAsPlots &&
                                    variable.Drawable is ExpressionDrawer.MultiPoint)
                                {
                                    variable.Drawable = new ExpressionDrawer.PointsContainer(variable.Drawable as ExpressionDrawer.MultiPoint);
                                }
                                else if (!settings.displayMultiPointsAsPlots &&
                                         variable.Drawable is ExpressionDrawer.PointsContainer)
                                {
                                    variable.Drawable = (variable.Drawable as ExpressionDrawer.PointsContainer).MultiPoint;
                                }
                            }

                            if (!ExpressionDrawer.Draw(graphics, variable.Drawable, variable.Traits, settings, Util.Colors))
                            {
                                variable.Bmp = null;
                            }

                            variable.Error = null;
                        }
                        catch (Exception e)
                        {
                            variable.Bmp = null;

                            variable.Error = e.Message;
                        }

                        variable.Type = ExpressionLoader.TypeFromExpressions(expressions);
                    }
                }
            }

            // set new row
            ResetAt(variable.ShallowCopy(), index);
        }
Example #8
0
            public void Draw(Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits)
            {
                LocalCS cs     = new LocalCS(box, graphics);
                Drawer  drawer = new Drawer(graphics, settings.color);

                double width  = Dim(0);
                double height = Dim(1);
                float  rw     = cs.ConvertDimensionX(Math.Abs(width));
                float  rh     = cs.ConvertDimensionY(Math.Abs(height));

                if (traits.Unit == Geometry.Unit.None)
                {
                    float rx = cs.ConvertX(Math.Min(Min[0], Max[0]));
                    float ry = cs.ConvertY(Math.Max(Min[1], Max[1]));

                    if (rw == 0 && rh == 0)
                    {
                        drawer.DrawPoint(rx, ry);
                    }
                    else if (rw == 0 || rh == 0)
                    {
                        drawer.DrawLine(rx, ry, rx + rw, ry + rh);
                    }
                    else
                    {
                        drawer.DrawRectangle(rx, ry, rw, rh);

                        bool isInvalid = width < 0 || height < 0;
                        if (!isInvalid)
                        {
                            drawer.FillRectangle(rx, ry, rw, rh);
                        }
                        else
                        {
                            drawer.DrawLine(rx, ry, rx + rw, ry + rh);
                            drawer.DrawLine(rx + rw, ry, rx, ry + rh);
                        }
                    }
                }
                else // Radian, Degree
                {
                    if (rw == 0 && rh == 0)
                    {
                        drawer.DrawPeriodicPoint(cs, Min, box, traits.Unit, settings.showDots);
                    }
                    else if (rw == 0 || rh == 0)
                    {
                        Geometry.Segment           seg      = new Geometry.Segment(Min, Max);
                        Drawer.PeriodicDrawableBox pd       = new Drawer.PeriodicDrawableBox(cs, seg, traits.Unit);
                        Geometry.Interval          interval = RelativeEnvelopeLon(seg, false, traits.Unit);
                        drawer.DrawPeriodic(cs, box, interval, traits.Unit, pd, false, false, settings.showDots);
                    }
                    else
                    {
                        Geometry.Ring ring = new Geometry.Ring();
                        ring.Add(new Geometry.Point(Min[0], Min[1]));
                        ring.Add(new Geometry.Point(Max[0], Min[1]));
                        ring.Add(new Geometry.Point(Max[0], Max[1]));
                        ring.Add(new Geometry.Point(Min[0], Max[1]));
                        Drawer.PeriodicDrawableBox pd       = new Drawer.PeriodicDrawableBox(cs, ring, traits.Unit);
                        Geometry.Interval          interval = RelativeEnvelopeLon(ring, true, traits.Unit);
                        drawer.DrawPeriodic(cs, box, interval, traits.Unit, pd, true, false, settings.showDots);
                    }
                }
            }
Example #9
0
 public Geometry.Box Aabb(Geometry.Traits traits, bool calculateEnvelope)
 {
     return(calculateEnvelope
          ? Geometry.Envelope(this, traits)
          : Geometry.Aabb(this, traits));
 }
Example #10
0
        private static void DrawPoint(Geometry.Point point, Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits)
        {
            LocalCS cs     = new LocalCS(box, graphics);
            Drawer  drawer = new Drawer(graphics, settings.color);

            if (traits.Unit == Geometry.Unit.None)
            {
                PointF p = cs.Convert(point);
                drawer.DrawPoint(p);
            }
            else // Radian, Degree
            {
                drawer.DrawPeriodicPoint(cs, point, box, traits.Unit, settings.showDots);
            }
        }
Example #11
0
 public Geometry.Box Aabb(Geometry.Traits traits, bool calculateEnvelope)
 {
     return(new Geometry.Box(this, this));
 }
Example #12
0
        // For GeometryWatch and PlotWatch
        static Geometry.Box Draw(Graphics graphics, bool ignoreTraits,
                                 IDrawable[] drawables, Geometry.Traits[] traits,
                                 Settings[] settings, Colors colors, ZoomBox zoomBox)
        {
            if (drawables.Length != traits.Length || drawables.Length != settings.Length)
            {
                throw new ArgumentOutOfRangeException("drawables.Length, traits.Length, settings.Length");
            }

            Geometry.Box box = new Geometry.Box();
            Geometry.AssignInverse(box);

            int drawnCount = 0;
            int count      = drawables.Length;

            bool[] drawnFlags = new bool[count];

            HashSet <int> dimensions = new HashSet <int>();
            HashSet <Geometry.CoordinateSystem> csystems = new HashSet <Geometry.CoordinateSystem>();
            HashSet <Geometry.Unit>             units    = new HashSet <Geometry.Unit>();

            for (int i = 0; i < count; ++i)
            {
                if (ignoreTraits)
                {
                    traits[i] = null;
                }

                if (drawables[i] != null)
                {
                    if (traits[i] != null)
                    {
                        dimensions.Add(traits[i].Dimension);
                        csystems.Add(traits[i].CoordinateSystem);
                        units.Add(traits[i].Unit);
                    }

                    Geometry.Box aabb = drawables[i].Aabb(traits[i], false);
                    Geometry.Expand(box, aabb);

                    ++drawnCount;
                    drawnFlags[i] = aabb.IsValid();
                }
            }

            if (drawnCount > 0)
            {
                if (csystems.Count > 1)
                {
                    throw new Exception("Multiple coordinate systems detected.");
                }
                if (csystems.Count > 0 && csystems.First() == Geometry.CoordinateSystem.SphericalPolar)
                {
                    throw new Exception("This coordinate system is not yet supported.");
                }
                if (units.Count > 1)
                {
                    throw new Exception("Multiple units detected.");
                }

                Geometry.Traits commonTraits = (dimensions.Count > 0 && csystems.Count > 0 && units.Count > 0)
                                                ? new Geometry.Traits(dimensions.Max(), csystems.First(), units.First())
                                                : null;

                bool fill = (commonTraits == null);

                // Fragment of the box
                if (box.IsValid() && zoomBox.IsZoomed())
                {
                    // window coordinates of the box
                    LocalCS cs = new LocalCS(box, graphics, fill);
                    box = cs.BoxFromZoomBox(zoomBox);

                    // TODO: With current approach changing the original box (resize, enlarge, etc.)
                    // may produce wierd results because zoomBox is relative to the original box.
                }

                // Axes
                if (box.IsValid())
                {
                    Geometry.Unit unit = commonTraits != null ? commonTraits.Unit : Geometry.Unit.None;
                    Drawer.DrawAxes(graphics, box, unit, colors, fill);
                }

                // Drawables
                for (int i = 0; i < count; ++i)
                {
                    if (drawables[i] != null && drawnFlags[i] == true)
                    {
                        drawables[i].Draw(box, graphics, settings[i], commonTraits);
                    }
                }

                // Scales
                if (box.IsValid())
                {
                    Drawer.DrawScales(graphics, box, colors, fill);
                }

                // CS info
                if (commonTraits != null)
                {
                    SolidBrush brush = new SolidBrush(colors.TextColor);
                    Font       font  = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif), 10);
                    string     str   = Geometry.Name(csystems.First());
                    if (units.First() != Geometry.Unit.None)
                    {
                        str += '[' + Geometry.Name(units.First()) + ']';
                    }
                    graphics.DrawString(str, font, brush, 0, 0);
                }

                return(box);
            }

            return(null);
        }
Example #13
0
 public Geometry.Box Aabb(Geometry.Traits traits, bool calculateEnvelope)
 {
     return(new Geometry.Box(point, point));
 }
Example #14
0
        public static bool DrawAabb(Graphics graphics, Geometry.Box box, Geometry.Traits traits, Colors colors)
        {
            if (!box.IsValid())
            {
                return(false);
            }

            LocalCS cs = new LocalCS(box, graphics);

            // Axes
            float h         = graphics.VisibleClipBounds.Height;
            float w         = graphics.VisibleClipBounds.Width;
            Pen   prime_pen = new Pen(colors.AxisColor, 1);

            if (traits.Unit == Geometry.Unit.None)
            {
                // Y axis
                float x0 = cs.ConvertX(0.0);
                graphics.DrawLine(prime_pen, x0, 0, x0, h);
                // X axis
                float y0 = cs.ConvertY(0.0);
                graphics.DrawLine(prime_pen, 0, y0, w, y0);
            }
            else
            {
                Pen anti_pen = new Pen(colors.AxisColor, 1);
                anti_pen.DashStyle   = DashStyle.Custom;
                anti_pen.DashPattern = new float[] { 5, 5 };
                double pi             = Geometry.HalfAngle(traits.Unit);
                double anti_mer       = Geometry.NearestAntimeridian(box.Min[0], -1, traits.Unit);
                double prime_mer      = anti_mer + pi;
                double next_anti_mer  = anti_mer + 2 * pi;
                double next_prime_mer = prime_mer + 2 * pi;

                float anti_mer_f     = cs.ConvertX(anti_mer);
                float anti_mer_step  = cs.ConvertX(next_anti_mer) - anti_mer_f;
                float prime_mer_f    = cs.ConvertX(prime_mer);
                float prime_mer_step = cs.ConvertX(next_prime_mer) - prime_mer_f;

                // Antimeridians
                for (; anti_mer_f <= w; anti_mer_f += anti_mer_step)
                {
                    if (anti_mer_f >= 0)
                    {
                        graphics.DrawLine(anti_pen, anti_mer_f, 0, anti_mer_f, h);
                    }
                }
                // Prime meridians
                for (; prime_mer_f <= w; prime_mer_f += prime_mer_step)
                {
                    if (prime_mer_f >= 0)
                    {
                        graphics.DrawLine(prime_pen, prime_mer_f, 0, prime_mer_f, h);
                    }
                }
                // Equator
                float e = cs.ConvertY(0.0);
                if (0 <= e && e <= h)
                {
                    graphics.DrawLine(prime_pen, 0, e, w, e);
                }
                // North pole
                float n = cs.ConvertY(pi / 2);
                if (0 <= n && n <= h)
                {
                    graphics.DrawLine(anti_pen, 0, n, w, n);
                }
                // South pole
                float s = cs.ConvertY(-pi / 2);
                if (0 <= s && s <= h)
                {
                    graphics.DrawLine(anti_pen, 0, s, w, s);
                }
            }

            // Aabb
            float min_x = cs.ConvertX(box.Min[0]);
            float min_y = cs.ConvertY(box.Min[1]);
            float max_x = cs.ConvertX(box.Max[0]);
            float max_y = cs.ConvertY(box.Max[1]);

            Pen penAabb = new Pen(colors.AabbColor, 1);

            graphics.DrawLine(penAabb, min_x - 1, min_y, min_x + 5, min_y);
            graphics.DrawLine(penAabb, min_x, min_y - 5, min_x, min_y + 1);
            graphics.DrawLine(penAabb, max_x - 5, max_y, max_x + 1, max_y);
            graphics.DrawLine(penAabb, max_x, max_y - 1, max_x, max_y + 5);

            // Aabb's coordinates
            float maxHeight = 20.0f;// Math.Min(Math.Max(graphics.VisibleClipBounds.Height - min_y, 0.0f), 20.0f);

            if (maxHeight > 1)
            {
                string       min_x_str  = box.Min[0].ToString("0.00", System.Globalization.CultureInfo.InvariantCulture);
                string       min_y_str  = box.Min[1].ToString("0.00", System.Globalization.CultureInfo.InvariantCulture);
                string       max_x_str  = box.Max[0].ToString("0.00", System.Globalization.CultureInfo.InvariantCulture);
                string       max_y_str  = box.Max[1].ToString("0.00", System.Globalization.CultureInfo.InvariantCulture);
                Font         font       = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif), maxHeight / 2.0f);
                StringFormat drawFormat = new StringFormat();
                drawFormat.Alignment = StringAlignment.Center;
                string     minStr      = "(" + min_x_str + " " + min_y_str + ")";
                string     maxStr      = "(" + max_x_str + " " + max_y_str + ")";
                SizeF      minSize     = graphics.MeasureString(minStr, font);
                SizeF      maxSize     = graphics.MeasureString(maxStr, font);
                RectangleF drawRectMin = new RectangleF(Math.Max(min_x - minSize.Width, 0.0f),
                                                        Math.Min(min_y + 2, graphics.VisibleClipBounds.Height - maxSize.Height),
                                                        minSize.Width,
                                                        minSize.Height);
                RectangleF drawRectMax = new RectangleF(Math.Min(max_x, graphics.VisibleClipBounds.Width - maxSize.Width),
                                                        Math.Max(max_y - maxHeight, 0.0f),
                                                        maxSize.Width,
                                                        maxSize.Height);
                SolidBrush brushText = new SolidBrush(colors.TextColor);
                graphics.DrawString(minStr, font, brushText, drawRectMin, drawFormat);
                graphics.DrawString(maxStr, font, brushText, drawRectMax, drawFormat);
            }

            return(true);
        }
Example #15
0
 public void DrawPoint(Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits)
 {
     ExpressionDrawer.DrawPoint(point, box, graphics, settings, traits);
 }
Example #16
0
        private static void DrawLinestring(Geometry.Linestring linestring, Geometry.Box box, Graphics graphics, Settings settings, Geometry.Traits traits)
        {
            LocalCS cs     = new LocalCS(box, graphics);
            Drawer  drawer = new Drawer(graphics, settings.color);

            if (traits.Unit == Geometry.Unit.None)
            {
                for (int i = 1; i < linestring.Count; ++i)
                {
                    PointF p0 = cs.Convert(linestring[i - 1]);
                    PointF p1 = cs.Convert(linestring[i]);
                    drawer.DrawLine(p0, p1);
                    if (settings.showDir)
                    {
                        drawer.DrawDir(p0, p1);
                    }
                }
            }
            else // Radian, Degree
            {
                Drawer.PeriodicDrawableRange pd       = new Drawer.PeriodicDrawableRange(cs, linestring, false, traits.Unit, settings.densify);
                Geometry.Interval            interval = RelativeEnvelopeLon(linestring, false, traits.Unit);
                drawer.DrawPeriodic(cs, box, interval, traits.Unit, pd, false, settings.showDir, settings.showDots);
            }
        }
        private void UpdateItem(bool load, int index)
        {
            GraphicalItem variable = Variables[index];

            Bitmap bmp  = null;
            string type = null;

            if (ExpressionLoader.Debugger.CurrentMode == dbgDebugMode.dbgBreakMode)
            {
                // Empty color - use default
                ExpressionDrawer.Settings settings = new ExpressionDrawer.Settings();
                settings.densify    = true;
                settings.showDir    = false;
                settings.showLabels = false;
                settings.showDots   = false;
                // Other settings
                int  imageWidth  = 100;
                int  imageHeight = 100;
                bool displayMultiPointsAsPlots = false;
                // Load settings from option page
                GraphicalWatchOptionPage optionPage = Util.GetDialogPage <GraphicalWatchOptionPage>();
                if (optionPage != null)
                {
                    if (optionPage.ValuePlot_EnableBars || optionPage.ValuePlot_EnableLines || optionPage.ValuePlot_EnablePoints)
                    {
                        settings.valuePlot_enableBars   = optionPage.ValuePlot_EnableBars;
                        settings.valuePlot_enableLines  = optionPage.ValuePlot_EnableLines;
                        settings.valuePlot_enablePoints = optionPage.ValuePlot_EnablePoints;
                    }
                    if (optionPage.PointPlot_EnableLines || optionPage.PointPlot_EnablePoints)
                    {
                        settings.pointPlot_enableLines  = optionPage.PointPlot_EnableLines;
                        settings.pointPlot_enablePoints = optionPage.PointPlot_EnablePoints;
                    }
                    settings.densify          = optionPage.Densify;
                    settings.showDir          = optionPage.EnableDirections;
                    settings.showLabels       = optionPage.EnableLabels;
                    settings.showDots         = false;
                    imageHeight               = Math.Max(optionPage.ImageHeight, 20);
                    imageWidth                = Math.Max(optionPage.ImageWidth, 20);
                    displayMultiPointsAsPlots = optionPage.MultiPointDisplayMode == GraphicalWatchOptionPage.MultiPointDisplayModeValue.PointPlot;
                }

                (dataGrid.Columns[1] as DataGridTemplateColumn).Width = imageWidth + 1;
                dataGrid.RowHeight = imageHeight + 1;

                if (load)
                {
                    variable.Drawable = null;
                    variable.Traits   = null;
                }

                if (variable.Name != null && variable.Name != "")
                {
                    var expression = ExpressionLoader.Debugger.GetExpression(variable.Name);
                    if (expression.IsValidValue)
                    {
                        // create bitmap
                        bmp = new Bitmap(imageWidth, imageHeight);

                        Graphics graphics = Graphics.FromImage(bmp);
                        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        graphics.Clear(m_colors.ClearColor);

                        try
                        {
                            if (variable.Drawable == null)
                            {
                                Geometry.Traits            traits   = null;
                                ExpressionDrawer.IDrawable drawable = null;
                                ExpressionLoader.Load(variable.Name, out traits, out drawable);

                                if (drawable != null && displayMultiPointsAsPlots && drawable is ExpressionDrawer.MultiPoint)
                                {
                                    drawable = new ExpressionDrawer.PointsContainer(drawable as ExpressionDrawer.MultiPoint);
                                }

                                variable.Drawable = drawable;
                                variable.Traits   = traits;
                            }
                            else
                            {
                                if (displayMultiPointsAsPlots && variable.Drawable is ExpressionDrawer.MultiPoint)
                                {
                                    variable.Drawable = new ExpressionDrawer.PointsContainer(variable.Drawable as ExpressionDrawer.MultiPoint);
                                }
                                else if (!displayMultiPointsAsPlots && variable.Drawable is ExpressionDrawer.PointsContainer)
                                {
                                    variable.Drawable = (variable.Drawable as ExpressionDrawer.PointsContainer).MultiPoint;
                                }
                            }

                            if (!ExpressionDrawer.Draw(graphics, variable.Drawable, variable.Traits, settings, m_colors))
                            {
                                bmp = null;
                            }
                        }
                        catch (Exception)
                        {
                            bmp = null;
                        }

                        type = expression.Type;
                    }
                }
            }

            // set new row
            ResetAt(new GraphicalItem(variable.Drawable, variable.Traits, variable.Name, bmp, type), index);
        }
Example #18
0
 private static Geometry.Box AabbRange(Geometry.IRandomAccessRange <Geometry.Point> rng, bool closed, Geometry.Traits traits, bool calculateEnvelope)
 {
     return(calculateEnvelope
          ? Geometry.Envelope(rng, closed, traits)
          : Geometry.Aabb(rng, closed, traits.Unit));
 }
        private void UpdateItems(bool load, int modified_index = -1)
        {
            m_currentBox = null;

            bool imageEmpty = true;

            if (ExpressionLoader.Debugger.CurrentMode == dbgDebugMode.dbgBreakMode)
            {
                if (load)
                {
                    ExpressionLoader.ReloadUserTypes(Util.GetDialogPage <GeneralOptionPage>());
                }

                ExpressionDrawer.Settings referenceSettings = new ExpressionDrawer.Settings();
                GeometryWatchOptionPage   optionPage        = Util.GetDialogPage <GeometryWatchOptionPage>();
                if (optionPage != null)
                {
                    referenceSettings.densify    = optionPage.Densify;
                    referenceSettings.showDir    = optionPage.EnableDirections;
                    referenceSettings.showLabels = optionPage.EnableLabels;
                    referenceSettings.showDots   = true;
                }

                // TODO: Names are redundant
                string[] names = new string[Geometries.Count];
                ExpressionDrawer.Settings[] settings = new ExpressionDrawer.Settings[Geometries.Count];
                bool tryDrawing = false;

                // update the list, gather names and settings
                for (int index = 0; index < Geometries.Count; ++index)
                {
                    GeometryItem geometry = Geometries[index];

                    System.Windows.Media.Color color = geometry.Color;
                    int    colorId = geometry.ColorId;
                    string type    = null;

                    bool updateRequred = modified_index < 0 || modified_index == index;

                    if (updateRequred && load)
                    {
                        geometry.Drawable = null;
                        geometry.Traits   = null;
                    }

                    if (geometry.Name != null && geometry.Name != "")
                    {
                        var expressions = updateRequred
                                       ? ExpressionLoader.GetExpressions(geometry.Name)
                                       : null;
                        if (expressions == null || ExpressionLoader.AllValidValues(expressions))
                        {
                            if (expressions != null)
                            {
                                type = ExpressionLoader.TypeFromExpressions(expressions);
                            }

                            names[index] = geometry.Name;

                            if (updateRequred && geometry.ColorId < 0)
                            {
                                colorId = m_intsPool.Pull();
                                color   = Util.ConvertColor(m_colors[colorId]);
                            }

                            settings[index] = referenceSettings.CopyColored(color);

                            tryDrawing = true;
                        }
                    }

                    // set new row
                    if (updateRequred)
                    {
                        ResetAt(new GeometryItem(geometry.Drawable, geometry.Traits,
                                                 geometry.Name, type, colorId, m_colors),
                                index);
                    }
                }

                // draw variables
                if (tryDrawing)
                {
                    int width  = (int)System.Math.Round(image.ActualWidth);
                    int height = (int)System.Math.Round(image.ActualHeight);
                    if (width > 0 && height > 0)
                    {
                        Bitmap bmp = new Bitmap(width, height);

                        Graphics graphics = Graphics.FromImage(bmp);
                        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        graphics.Clear(m_colors.ClearColor);

                        try
                        {
                            ExpressionDrawer.IDrawable[] drawables = new ExpressionDrawer.IDrawable[names.Length];
                            Geometry.Traits[]            traits    = new Geometry.Traits[names.Length];
                            for (int i = 0; i < names.Length; ++i)
                            {
                                if (Geometries[i].Drawable == null && names[i] != null && names[i] != "")
                                {
                                    try
                                    {
                                        // TODO: Unify the loading of empty geometries.
                                        //   For empty linestring the coordinate system name is drawn
                                        //   however for empty multilinestring it is not. The reason
                                        //   is that in the latter case null drawable and traits are
                                        //   returned becasue traits are loaded from an element
                                        //   (linestring) but there are no elements since the
                                        //   multi-geometry is empty.
                                        ExpressionDrawer.IDrawable d = null;
                                        Geometry.Traits            t = null;
                                        ExpressionLoader.Load(names[i],
                                                              ExpressionLoader.OnlyGeometriesOrGeometryContainer,
                                                              out t, out d);
                                        if (t == null) // Traits has to be defined for Geometry
                                        {
                                            d = null;
                                        }
                                        Geometries[i].Drawable = d;
                                        Geometries[i].Traits   = t;
                                        Geometries[i].Error    = null;
                                    }
                                    catch (Exception e)
                                    {
                                        Geometries[i].Error = e.Message;
                                    }
                                }
                                drawables[i] = Geometries[i].Drawable;
                                traits[i]    = Geometries[i].Traits;
                            }

                            m_currentBox = ExpressionDrawer.DrawGeometries(graphics, drawables, traits, settings, m_colors, m_zoomBox);
                        }
                        catch (Exception e)
                        {
                            ExpressionDrawer.DrawErrorMessage(graphics, e.Message);
                        }

                        image.Source = Util.BitmapToBitmapImage(bmp);
                        imageEmpty   = false;
                    }
                }
            }

            if (imageEmpty)
            {
                image.Source = Util.BitmapToBitmapImage(m_emptyBitmap);
            }

            imageGrid.ContextMenu = new ContextMenu();
            MenuItem mi = new MenuItem();

            mi.Header = "Copy";
            mi.Click += MenuItem_Copy;
            if (imageEmpty)
            {
                mi.IsEnabled = false;
            }
            imageGrid.ContextMenu.Items.Add(mi);
            imageGrid.ContextMenu.Items.Add(new Separator());
            MenuItem mi2 = new MenuItem();

            mi2.Header = "Reset View";
            mi2.Click += MenuItem_ResetZoom;
            if (imageEmpty)
            {
                mi2.IsEnabled = false;
            }
            imageGrid.ContextMenu.Items.Add(mi2);
        }
            public override void Load(Loaders loaders, MemoryReader mreader, Debugger debugger,
                                      string name, string type,
                                      out Geometry.Traits traits,
                                      out ExpressionDrawer.Image result,
                                      LoadCallback callback)
            {
                traits = null;
                result = null;

                // NOTE: If the image is not created at the point of debugging, so the variable is
                // uninitialized, the size may be out of bounds of int32 range. In this case the
                // exception is thrown here and this is ok. However if there is some garbage in
                // memory random size could be loaded here. Then also the memory probably points
                // to some random place in memory (maybe protected?) so the result will probably
                // be another exception which is fine or an image containing noise from memory.
                int width  = ExpressionParser.LoadSize(debugger, name + "._view._dimensions.x");
                int height = ExpressionParser.LoadSize(debugger, name + "._view._dimensions.y");

                if (width < 1 || height < 1)
                {
                    return;
                }

                string pixelType, isPlanarStr;

                if (!Util.Tparams(type, out pixelType, out isPlanarStr))
                {
                    return;
                }

                string pixelId = Util.BaseType(pixelType);

                if (pixelId != "boost::gil::pixel")
                {
                    return;
                }

                bool isPlanar = (isPlanarStr == "1");

                string channelValueType, layoutType;

                if (!Util.Tparams(pixelType, out channelValueType, out layoutType))
                {
                    return;
                }

                string layoutId = Util.BaseType(layoutType);

                if (layoutId != "boost::gil::layout")
                {
                    return;
                }

                string colorSpaceType, channelMappingType;

                if (!Util.Tparams(layoutType, out colorSpaceType, out channelMappingType))
                {
                    return;
                }

                ChannelValueKind channelValueKind = ChannelValueKind.Unknown;
                int channelValueSize = 0;

                ParseChannelValue(debugger, channelValueType, out channelValueKind, out channelValueSize);
                if (channelValueKind == ChannelValueKind.Unknown || channelValueSize == 0)
                {
                    return;
                }

                string     colorSpaceId   = Util.BaseType(colorSpaceType);
                ColorSpace colorSpace     = ParseColorSpace(colorSpaceType);
                int        colorSpaceSize = ColorSpaceSize(colorSpace);

                if (colorSpace == ColorSpace.Unknown || colorSpaceSize == 0)
                {
                    return;
                }

                Layout layout = ParseChannelMapping(colorSpace, channelMappingType);

                if (layout == Layout.Unknown)
                {
                    return;
                }

                if (channelValueSize != 1 &&
                    channelValueSize != 2 &&
                    channelValueSize != 4 &&
                    channelValueSize != 8)
                {
                    return;
                }

                // TODO: size_t? ulong?
                int bytesCount = width * height * colorSpaceSize * channelValueSize;

                byte[] memory   = new byte[bytesCount];
                bool   isLoaded = false;

                if (mreader != null)
                {
                    ulong address = ExpressionParser.GetValueAddress(debugger, name + "._memory[0]");
                    if (address == 0)
                    {
                        return;
                    }

                    isLoaded = mreader.ReadBytes(address, memory);
                }

                if (!isLoaded)
                {
                    // Parsing the memory byte by byte may take very long time
                    // even for small images. So don't do it.
                    return;
                }

                LayoutMapper layoutMapper = GetLayoutMapper(layout);

                if (layoutMapper == null)
                {
                    return;
                }

                // Use Pixel format native to Gil Image?
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);
                for (int j = 0; j < height; ++j)
                {
                    for (int i = 0; i < width; ++i)
                    {
                        int pixelIndex = (j * width + i);

                        // The raw bytes are converted into channel values pixel by pixel.
                        //  It could be more efficient to convert all channel values at once first
                        //  and only create pixels from array of channels in this loop.
                        // Another thing is that when channels are always converted to byte
                        //  the information is lost. This information could be used during potential
                        //  conversion in GetColor() below (cmyk->rgb). Channels could be returned
                        //  as float[]. In practice the eye will probably not notice the difference.
                        byte[] channels = isPlanar
                                        ? GetChannelsPlanar(memory,
                                                            pixelIndex,
                                                            channelValueKind, channelValueSize, colorSpaceSize)
                                        : GetChannelsInterleaved(memory,
                                                                 pixelIndex,
                                                                 channelValueKind, channelValueSize, colorSpaceSize);
                        if (channels == null)
                        {
                            return;
                        }

                        System.Drawing.Color c = layoutMapper.GetColor(channels);
                        bmp.SetPixel(i, j, c);

                        // TODO: Checked per pixel. Too often?
                        //   But it's the same for geometries (ForEachMemoryBlock).
                        if (!callback())
                        {
                            return;
                        }
                    }
                }

                result = new ExpressionDrawer.Image(bmp);
            }