예제 #1
0
        private ExpressionDrawer.Settings GetOptions()
        {
            ExpressionDrawer.Settings settings   = new ExpressionDrawer.Settings();
            PlotWatchOptionPage       optionPage = Util.GetDialogPage <PlotWatchOptionPage>();

            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;
                }
            }
            return(settings);
        }
예제 #2
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);
        }