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);
        }
        private void UpdateItems(int modified_index = -1)
        {
            bool imageEmpty = true;

            if (m_debugger.CurrentMode == dbgDebugMode.dbgBreakMode)
            {
                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 (geometry.Name != null && geometry.Name != "")
                    {
                        var expression = updateRequred ? m_debugger.GetExpression(geometry.Name) : null;
                        if (expression == null || expression.IsValidValue)
                        {
                            if (expression != null)
                            {
                                type = expression.Type;
                            }

                            names[index] = geometry.Name;

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

                            settings[index] = new ExpressionDrawer.Settings(Util.ConvertColor(color), true, true);

                            tryDrawing = true;
                        }
                    }

                    // set new row
                    if (updateRequred)
                    {
                        ResetAt(new GeometryItem(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);

                        ExpressionDrawer.DrawGeometries(graphics, m_debugger, names, settings, m_colors);

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

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

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

            mi.Header = "Copy";
            mi.Click += MenuItem_Copy;
            if (imageEmpty)
            {
                mi.IsEnabled = false;
            }
            image.ContextMenu.Items.Add(mi);
        }