Exemplo n.º 1
0
 /// <summary>
 /// Fires the SliderSelected event
 /// </summary>
 /// <param name="slider"></param>
 protected virtual void OnSliderSelected(BreakSlider slider)
 {
     if (SliderSelected != null)
     {
         SliderSelected(this, new BreakSliderEventArgs(slider));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Selects one of the specific breaks.
        /// </summary>
        /// <param name="slider"></param>
        public void SelectBreak(BreakSlider slider)
        {
            if (_selectedSlider != null)
            {
                _selectedSlider.Selected = false;
            }
            _selectedSlider = slider;

            if (_selectedSlider != null)
            {
                _selectedSlider.Selected = true;
                _graph.SelectedRange     = _selectedSlider.Range;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Given a break slider's new position, this will update the category related to that
        /// break.
        /// </summary>
        /// <param name="slider"></param>
        public void UpdateCategory(BreakSlider slider)
        {
            slider.Category.Maximum = slider.Value;
            slider.Category.ApplyMinMax(_scheme.EditorSettings);
            int index = _breaks.IndexOf(slider);

            if (index < 0)
            {
                return;
            }
            if (index < _breaks.Count - 1)
            {
                _breaks[index + 1].Category.Minimum = slider.Value;
                _breaks[index + 1].Category.ApplyMinMax(_scheme.EditorSettings);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the mouse up event.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (_isDragging)
            {
                _isDragging = false;

                _selectedSlider.Category.Maximum = _selectedSlider.Value;
                if (_isRaster)
                {
                    _rasterSymbolizer.Scheme.ApplySnapping(_selectedSlider.Category);
                    _selectedSlider.Category.ApplyMinMax(_rasterSymbolizer.Scheme.EditorSettings);
                }
                else
                {
                    _scheme.ApplySnapping(_selectedSlider.Category);
                    _selectedSlider.Category.ApplyMinMax(_scheme.EditorSettings);
                }

                if (_selectedSlider.NextCategory != null)
                {
                    _selectedSlider.NextCategory.Minimum = _selectedSlider.Value;
                    if (_isRaster)
                    {
                        _rasterSymbolizer.Scheme.ApplySnapping(_selectedSlider.NextCategory);
                        _selectedSlider.Category.ApplyMinMax(_rasterSymbolizer.Scheme.EditorSettings);
                    }
                    else
                    {
                        _scheme.ApplySnapping(_selectedSlider.NextCategory);
                        _selectedSlider.NextCategory.ApplyMinMax(_scheme.EditorSettings);
                    }
                }

                OnSliderMoved();
                Invalidate();
                return;
            }

            BreakSlider s = GetBreakAt(e.Location);

            SelectBreak(s);
            OnSliderSelected(s);
            Invalidate();

            base.OnMouseUp(e);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Occurs when the mose down occurs.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            Focus();
            if (e.Button == MouseButtons.Right)
            {
                _contextMenu.Show(this, e.Location);
                return;
            }

            foreach (BreakSlider slider in Breaks)
            {
                if (!slider.Bounds.Contains(e.Location) && !slider.HandleBounds.Contains(e.Location))
                {
                    continue;
                }

                // not sure if this works right. Hopefully, just the little rectangles form a double region.
                Region rg = new();
                if (_selectedSlider != null)
                {
                    rg.Union(_selectedSlider.Bounds);
                    _selectedSlider.Selected = false;
                }

                _selectedSlider = slider;
                slider.Selected = true;
                rg.Union(_selectedSlider.Bounds);
                Invalidate(rg);
                _isDragging = true;
                OnSliderMoving();
                return;
            }

            if (_selectedSlider != null)
            {
                _selectedSlider.Selected = false;
            }

            _selectedSlider = null;
            base.OnMouseDown(e);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BreakSliderEventArgs"/> class.
 /// </summary>
 /// <param name="slider">The break slider.</param>
 public BreakSliderEventArgs(BreakSlider slider)
 {
     Slider = slider;
 }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        public void UpdateRasterBreaks()
        {
            if (_rasterLayer == null)
            {
                return;
            }
            IColorCategory selectedBrk = null;

            if (_selectedSlider != null)
            {
                selectedBrk = _selectedSlider.Category as IColorCategory;
            }
            _breaks.Clear();
            Statistics stats = _rasterSymbolizer.Scheme.Statistics;
            Rectangle  gb    = _graph.GetGraphBounds();

            _graph.ColorRanges.Clear();
            foreach (IColorCategory category in _rasterSymbolizer.Scheme.Categories)
            {
                ColorRange cr = new ColorRange(category.LowColor, category.Range);
                _graph.ColorRanges.Add(cr);
                BreakSlider bs = new BreakSlider(gb, _graph.Minimum, _graph.Maximum, cr);
                bs.Color       = _breakColor;
                bs.SelectColor = _selectedBreakColor;
                if (selectedBrk != null && category == selectedBrk)
                {
                    bs.Selected          = true;
                    _selectedSlider      = bs;
                    _graph.SelectedRange = cr;
                }
                if (category.Maximum != null)
                {
                    bs.Value = double.Parse(category.Maximum.ToString());
                }
                else
                {
                    bs.Value = stats.Maximum;
                }
                bs.Category = category;
                _breaks.Add(bs);
            }
            _breaks.Sort();
            // Moving a break generally affects both a maximum and a minimum.
            // Point to the next category to actuate that.
            for (int i = 0; i < _breaks.Count - 1; i++)
            {
                _breaks[i].NextCategory = _breaks[i + 1].Category;
                // We use the maximums to set up breaks.  Minimums should simply
                // be set to work with the maximums of the previous category.
                _breaks[i + 1].Category.Minimum = _breaks[i].Value;
            }

            if (_breaks.Count == 0)
            {
                return;
            }
            int         breakIndex = 0;
            BreakSlider nextSlider = _breaks[breakIndex];
            int         count      = 0;

            if (_graph == null || _graph.Bins == null)
            {
                return;
            }
            foreach (double value in _values)
            {
                if (value < nextSlider.Value)
                {
                    count++;
                    continue;
                }
                nextSlider.Count = count;
                while (value > nextSlider.Value)
                {
                    breakIndex++;
                    if (breakIndex >= _breaks.Count)
                    {
                        break;
                    }
                    nextSlider = _breaks[breakIndex];
                }
                count = 0;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Updates the raster breaks.
        /// </summary>
        public void UpdateRasterBreaks()
        {
            if (_rasterLayer == null)
            {
                return;
            }
            IColorCategory selectedBrk = null;

            if (_selectedSlider != null)
            {
                selectedBrk = _selectedSlider.Category as IColorCategory;
            }
            Breaks.Clear();
            Statistics stats = _rasterSymbolizer.Scheme.Statistics;
            Rectangle  gb    = _graph.GetGraphBounds();

            _graph.ColorRanges.Clear();
            foreach (IColorCategory category in _rasterSymbolizer.Scheme.Categories)
            {
                ColorRange cr = new ColorRange(category.LowColor, category.Range);
                _graph.ColorRanges.Add(cr);
                BreakSlider bs = new BreakSlider(gb, _graph.Minimum, _graph.Maximum, cr)
                {
                    Color       = _breakColor,
                    SelectColor = _selectedBreakColor
                };
                if (selectedBrk != null && category == selectedBrk)
                {
                    bs.Selected          = true;
                    _selectedSlider      = bs;
                    _graph.SelectedRange = cr;
                }

                bs.Value = category.Maximum != null?double.Parse(category.Maximum.ToString()) : stats.Maximum;

                bs.Category = category;
                Breaks.Add(bs);
            }

            Breaks.Sort();

            // Moving a break generally affects both a maximum and a minimum.
            // Point to the next category to actuate that.
            for (int i = 0; i < Breaks.Count - 1; i++)
            {
                Breaks[i].NextCategory = Breaks[i + 1].Category;

                // We use the maximums to set up breaks. Minimums should simply
                // be set to work with the maximums of the previous category.
                // _breaks[i + 1].Category.Minimum = _breaks[i].Value; REMOVED BY jany_ (2015-07-07) Don't set minimum, because that changes the minimum of the rasters category which causes the colors to change when saving in RasterColorControl without making changes or for example only applying opacity without wanting to use statistics.
            }

            if (Breaks.Count == 0)
            {
                return;
            }
            int         breakIndex = 0;
            BreakSlider nextSlider = Breaks[breakIndex];
            int         count      = 0;

            if (_graph?.Bins == null)
            {
                return;
            }
            foreach (double value in _values)
            {
                if (value < nextSlider.Value)
                {
                    count++;
                    continue;
                }

                nextSlider.Count = count;
                while (value > nextSlider.Value)
                {
                    breakIndex++;
                    if (breakIndex >= Breaks.Count)
                    {
                        break;
                    }

                    nextSlider = Breaks[breakIndex];
                }

                count = 0;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Given a scheme, this will build the break list to match approximately. This does not
        /// force the interval method to build a new scheme.
        /// </summary>
        public void UpdateBreaks()
        {
            if (_isRaster)
            {
                UpdateRasterBreaks();
                return;
            }

            if (_scheme == null)
            {
                return;
            }
            IFeatureCategory selectedCat = null;

            if (_selectedSlider != null)
            {
                selectedCat = _selectedSlider.Category as IFeatureCategory;
            }
            Breaks.Clear();
            Statistics stats = _scheme.Statistics;
            Rectangle  gb    = _graph.GetGraphBounds();

            _graph.ColorRanges.Clear();
            foreach (IFeatureCategory category in _scheme.GetCategories())
            {
                ColorRange cr = new ColorRange(category.GetColor(), category.Range);
                _graph.ColorRanges.Add(cr);
                BreakSlider bs = new BreakSlider(gb, _graph.Minimum, _graph.Maximum, cr)
                {
                    Color       = _breakColor,
                    SelectColor = _selectedBreakColor
                };
                if (selectedCat != null && category == selectedCat)
                {
                    bs.Selected          = true;
                    _selectedSlider      = bs;
                    _graph.SelectedRange = cr;
                }

                bs.Value = category.Maximum != null?double.Parse(category.Maximum.ToString()) : stats.Maximum;

                bs.Category = category;
                Breaks.Add(bs);
            }

            Breaks.Sort();

            // Moving a break generally affects both a maximum and a minimum.
            // Point to the next category to actuate that.
            for (int i = 0; i < Breaks.Count - 1; i++)
            {
                Breaks[i].NextCategory = Breaks[i + 1].Category;

                // We use the maximums to set up breaks. Minimums should simply
                // be set to work with the maximums of the previous category.
                Breaks[i + 1].Category.Minimum = Breaks[i].Value;
            }

            if (Breaks.Count == 0)
            {
                return;
            }
            int         breakIndex = 0;
            BreakSlider nextSlider = Breaks[breakIndex];
            int         count      = 0;

            if (_graph?.Bins == null)
            {
                return;
            }
            foreach (double value in _values)
            {
                if (value < nextSlider.Value)
                {
                    count++;
                    continue;
                }

                nextSlider.Count = count;
                while (value > nextSlider.Value)
                {
                    breakIndex++;
                    if (breakIndex >= Breaks.Count)
                    {
                        break;
                    }

                    nextSlider = Breaks[breakIndex];
                }

                count = 0;
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Fires the SliderSelected event.
 /// </summary>
 /// <param name="slider">The break slider.</param>
 protected virtual void OnSliderSelected(BreakSlider slider)
 {
     SliderSelected?.Invoke(this, new BreakSliderEventArgs(slider));
 }