Esempio n. 1
0
        protected override bool OnMouseUp(List <SeriesEditParameter> parameters, MouseEventArgs e,
                                          Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            var hideLine = SeriesEditParameter.TryGetParamValue(parameters, "HideSegment", true);

            objectToEdit = null;
            var pair = data.FirstOrDefault(p => p.IsBeingCreated);

            if (pair == null)
            {
                return(false);
            }

            // если проекция выродилась - удалить ее
            if (Math.Abs(pair.points[0].b - pair.points[1].b) < 0.00001f)
            {
                data.Remove(pair);
                return(true);
            }

            // завершить создание
            pair.IsBeingCreated = false;
            pair.HideLine       = hideLine;
            objectToEdit        = pair;
            return(true);
        }
Esempio n. 2
0
        protected override bool OnMouseUp(List <SeriesEditParameter> parameters, MouseEventArgs e,
                                          Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;
            var editedComment = data.Find(c => c.IsBeingCreated);

            if (editedComment == null)
            {
                return(false);
            }

            // завершить создание комментария - открыть окно редактирования текста
            editedComment.IsBeingCreated = false;
            var showWindow = SeriesEditParameter.TryGetParamValue(parameters, "ShowWindow", true);

            if (showWindow)
            {
                Chart.toolSkipMouseDown = true;
                if (editedComment.ShowEditDialog() == DialogResult.Cancel)
                {
                    // удалить комментарий
                    data.Remove(editedComment);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        protected override void OnMouseDown(List <SeriesEditParameter> parameters,
                                            MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            var editedComment = data.Find(c => c.IsBeingCreated);

            if (editedComment != null)
            {
                return;
            }

            // получить время и цену
            var clientPoint = Chart.PointToScreen(new Point(e.X, e.Y));

            clientPoint = Chart.StockPane.PointToClient(clientPoint);
            var x = clientPoint.X;
            var y = clientPoint.Y;

            var pointD = Conversion.ScreenToWorld(new PointD(x, y),
                                                  Chart.StockPane.WorldRect, Chart.StockPane.CanvasRect);

            // начинается редактирование - выбрана первая точка
            var text       = SeriesEditParameter.TryGetParamValue(parameters, "Text", "...");
            var lineColor  = SeriesEditParameter.TryGetParamValue(parameters, "Stroke", Color.Black);
            var fillColor  = SeriesEditParameter.TryGetParamValue(parameters, "Filling", Color.White);
            var colorText  = SeriesEditParameter.TryGetParamValue(parameters, "TextColor", Color.Black);
            var alphaColor = SeriesEditParameter.TryGetParamValue(parameters, "Transparency", 192);
            var hideArrow  = SeriesEditParameter.TryGetParamValue(parameters, "HideArrow", false);
            var drawFrame  = SeriesEditParameter.TryGetParamValue(parameters, "DrawFrame", true);

            var comment = new ChartComment
            {
                IsBeingCreated   = true,
                PivotIndex       = pointD.X,
                PivotPrice       = pointD.Y,
                ArrowLength      = 0,
                ArrowAngle       = -45,
                Owner            = this,
                Text             = text,
                Color            = lineColor,
                ColorFill        = fillColor,
                FillTransparency = alphaColor,
                HideArrow        = hideArrow,
                DrawFrame        = drawFrame,
                ColorText        = colorText
            };

            if (Owner.Owner.Owner.AdjustObjectColorsOnCreation)
            {
                comment.AjustColorScheme(Owner.Owner.Owner);
            }
            data.Add(comment);
        }
Esempio n. 4
0
        /// <summary>
        /// закончить создание линии
        /// </summary>
        protected override bool OnMouseUp(List <SeriesEditParameter> parameters,
                                          MouseEventArgs e, Keys modifierKeys,
                                          out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;

            var incompleted = data.Find(s => s.IsBeingCreated);

            if (incompleted == null)
            {
                return(false);
            }

            var pointD = Chart.Owner.MouseToWorldCoords(e.X, e.Y);

            incompleted.AddPoint(pointD.X, pointD.Y);

            // если линия слишком короткая - возможно, создана случайно?
            var screenPtA = Chart.Owner.WorldToChartCoords(incompleted.linePoints[0].X,
                                                           incompleted.linePoints[0].Y);
            var deltaPix = Math.Abs(e.X - screenPtA.X) + Math.Abs(e.Y - screenPtA.Y);

            if (deltaPix < 4)
            {
                data.Remove(incompleted);
                return(true);
            }

            var shouldDeleteOnMouseUp = SeriesEditParameter.TryGetParamValue(parameters, "MeasureOnly", false);

            if (shouldDeleteOnMouseUp)
            {
                data.Remove(incompleted);
                return(true);
            }

            incompleted.IsBeingCreated = false;
            incompleted.ShowTags       = false;

            var showWindow = SeriesEditParameter.TryGetParamValue(parameters, "ShowWindow", false);
            var shouldEdit = SeriesEditParameter.TryGetParamValue(parameters, "Edit", true);

            if (shouldEdit)
            {
                objectToEdit = incompleted;
            }
            else
            if (showWindow)
            {
                Chart.toolSkipMouseDown = true;
                var dlg = new ObjectPropertyWindow(new List <object> {
                    incompleted
                });
                dlg.ShowDialog();
            }
            return(true);
        }
Esempio n. 5
0
        protected override void OnMouseDown(List <SeriesEditParameter> parameters,
                                            MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            // получить время и цену
            var pointD        = Chart.Owner.MouseToWorldCoords(e.X, e.Y);
            var editedEllipse = data.FirstOrDefault(el => el.IsBeingCreated);

            var shiftPressed   = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
            var controlPressed = (Control.ModifierKeys & Keys.Control) == Keys.Control;

            if (editedEllipse == null)
            {// начинается редактирование - выбрана первая точка
                var lineColor    = SeriesEditParameter.TryGetParamValue(parameters, "Stroke", Color.Black);
                var buildAuto    = SeriesEditParameter.TryGetParamValue(parameters, "ByTwoPoints", false) ^ controlPressed;
                var buildTangent = SeriesEditParameter.TryGetParamValue(parameters, "Tangent", false) ^ shiftPressed;
                var tangentType  = SeriesEditParameter.TryGetParamValue(parameters, "TangentView",
                                                                        ChartEllipse.EllipseTangentType.Отрезок);
                data.Add(new ChartEllipse
                {
                    Owner        = this,
                    Color        = lineColor,
                    BuildTangent = buildTangent,
                    TangentType  = tangentType,
                    buildAuto    = buildAuto
                });
                editedEllipse = data[data.Count - 1];
                editedEllipse.IsBeingCreated = true;
                if (Owner.Owner.Owner.AdjustObjectColorsOnCreation)
                {
                    editedEllipse.AjustColorScheme(Owner.Owner.Owner);
                }
            }

            // добавить точку в эллипс
            editedEllipse.points.Add(pointD.ToPointF());
            // ... или сразу две
            if (editedEllipse.points.Count == 1)
            {
                editedEllipse.points.Add(pointD.ToPointF());
            }

            ellipseBeingSized = editedEllipse;
        }
        protected override void OnMouseDown(List <SeriesEditParameter> parameters,
                                            MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            var pointD = Chart.Owner.MouseToWorldCoords(e.X, e.Y);

            var incompleted = data.Find(s => s.IsBeingCreated);

            if (incompleted != null)
            {
                // добавить третью точку
                incompleted.Point3 = new PointD(
                    (incompleted.linePoints[0].X + incompleted.linePoints[1].X) / 2,
                    (incompleted.linePoints[0].Y + incompleted.linePoints[1].Y) / 2);
                channelBeingCreated = incompleted;
                return;
            }

            // ReSharper disable UseObjectOrCollectionInitializer
            var channel = new FiboChannel {
                Owner = this, IsBeingCreated = true
            };

            // ReSharper restore UseObjectOrCollectionInitializer
            channel.DrawText  = SeriesEditParameter.TryGetParamValue(parameters, "DrawLabels", false);
            channel.LineColor = SeriesEditParameter.TryGetParamValue(parameters, "Color", Color.DarkBlue);
            channel.LineStyle = SeriesEditParameter.TryGetParamValue(parameters, "LineType", TrendLine.TrendLineStyle.Отрезок);
            channel.AddPoint(pointD.X, pointD.Y);
            channel.AddPoint(pointD.X, pointD.Y);
            channelBeingCreated = channel;

            if (Owner.Owner.Owner.AdjustObjectColorsOnCreation)
            {
                channel.AjustColorScheme(Owner.Owner.Owner);
            }
            data.Add(channel);
        }
Esempio n. 7
0
        /// <summary>
        /// добавить точку в пару, определяющую проекцию
        /// либо создать новую пару
        /// либо удалить точку (или всю пару)
        /// </summary>
        protected override void OnMouseDown(List <SeriesEditParameter> parameters,
                                            MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            // получить индекс свечки, в которую было попадание
            var point = GetCandlePoint(e);

            if (!point.HasValue)
            {
                return;
            }

            // перебрать все пары
            // при попадании в точку пары удалить ее
            for (var i = 0; i < data.Count; i++)
            {
                var p = data[i];
                if (p.IsInPoint(point.Value.a, point.Value.b))
                {
                    data.RemoveAt(i);
                    return;
                }
            }

            var defaultCorrectionObj = SeriesEditParameter.TryGetParamValue(parameters, "Correction");
            var defaultCorrection    = defaultCorrectionObj == null ? false : (bool)defaultCorrectionObj;

            var defaultHideErrorsObj = SeriesEditParameter.TryGetParamValue(parameters, "HideMisses");
            var defaultHideErrors    = defaultHideErrorsObj == null ? true : (bool)defaultHideErrorsObj;
            var defaultMarkersObj    = SeriesEditParameter.TryGetParamValue(parameters, "Labels");
            var defaultMarkers       = defaultMarkersObj != null ? (ProjectionPair.MarkerPlacement)defaultMarkersObj :
                                       ProjectionPair.MarkerPlacement.Слева;
            var levelsProjStr   = SeriesEditParameter.TryGetParamValue(parameters, "ExpansionLevels", "0.618 1 1.618");
            var levelsCorrStr   = SeriesEditParameter.TryGetParamValue(parameters, "CorrectionLevels", "0.236 0.382 0.618");
            var correctWithProj = SeriesEditParameter.TryGetParamValue(parameters, "CorrectionPlusProjections", false);
            var barsLength      = SeriesEditParameter.TryGetParamValue(parameters, "LengthInBars", 60);

            // добавить новую пару
            var shiftPressed = ((modifierKeys & Keys.Shift) == Keys.Shift);

            var pair = new ProjectionPair(point.Value.a, point.Value.b)
            {
                IsCorrection   = defaultCorrection ^ shiftPressed,
                HideFarParts   = defaultHideErrors ^ shiftPressed,
                IsExtension    = defaultCorrection ^ !shiftPressed,
                Color          = fiboProjectionColors[fiboProjectionColorsIndex++],
                Markers        = defaultMarkers,
                Owner          = this,
                LevelsProj     = levelsProjStr,
                LevelsCorr     = levelsCorrStr,
                HideLine       = false,
                IsBeingCreated = true
            };

            pair.points.Add(new Cortege2 <int, float>(point.Value.a, point.Value.b));
            if (Owner.Owner.Owner.AdjustObjectColorsOnCreation)
            {
                pair.AjustColorScheme(Owner.Owner.Owner);
            }
            if (correctWithProj)
            {
                pair.IsCorrection = true;
                pair.IsExtension  = true;
            }
            if (barsLength > 0)
            {
                pair.ProjectionLength = barsLength;
            }
            data.Add(pair);
            if (fiboProjectionColorsIndex >= fiboProjectionColors.Length)
            {
                fiboProjectionColorsIndex = 0;
            }
        }
Esempio n. 8
0
        protected override void OnMouseDown(List <SeriesEditParameter> parameters,
                                            MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            // по одному клику добавить маркер, по двум - открыть
            // редактор

            // получить время и цену
            var clientPoint = Chart.PointToScreen(new Point(e.X, e.Y));

            clientPoint = Chart.StockPane.PointToClient(clientPoint);
            var x = clientPoint.X;
            var y = clientPoint.Y;

            var markers = data.Where(aster => aster.IsIn(
                                         x - Chart.StockPane.CanvasRect.Left, y)).ToList();

            if (markers.Count > 0)
            {
                var selected = markers[markers.Count - 1];
                // показать текст маркера во всплывающем окне
                var markerDlg = new MarkerWindow {
                    Text = selected.Text
                };
                var result = markerDlg.ShowDialog();

                if (markerDlg.IsDeleteBtnPressed)
                {
                    data.Remove(selected);
                }
                else
                if (result == DialogResult.OK)
                {
                    selected.Text = markerDlg.Text;
                }
                return;
            }

            var pointD = Conversion.ScreenToWorld(new PointD(x, y),
                                                  Chart.StockPane.WorldRect, Chart.StockPane.CanvasRect);

            // поставить маркер и открыть диалог редактирования свойств
            var isShiftPressed = (modifierKeys & Keys.Shift) == Keys.Shift;

            var text           = SeriesEditParameter.TryGetParamValue(parameters, "Text", "e");
            var lineColor      = SeriesEditParameter.TryGetParamValue(parameters, "Stroke", Color.Black);
            var fillColor      = SeriesEditParameter.TryGetParamValue(parameters, "Filling", Color.White);
            var textShift      = SeriesEditParameter.TryGetParamValue(parameters, "Text_Shift", "e");
            var lineColorShift = SeriesEditParameter.TryGetParamValue(parameters, "Stroke_Shift", Color.Black);
            var fillColorShift = SeriesEditParameter.TryGetParamValue(parameters, "Filling_Shift", Color.White);
            var shape          = SeriesEditParameter.TryGetParamValue(parameters, "Type", AsteriskTooltip.ShapeType.СтрелкаВверх);
            var shapeShift     = SeriesEditParameter.TryGetParamValue(parameters, "Type_Shift", AsteriskTooltip.ShapeType.СтрелкаВниз);
            var alphaColor     = SeriesEditParameter.TryGetParamValue(parameters, "Transparency", 192);

            var marker = new AsteriskTooltip
            {
                Price        = (float)pointD.Y,
                CandleIndex  = (int)(Math.Round(pointD.X)),
                Shape        = isShiftPressed ? shapeShift : shape,
                Transparency = alphaColor,
                ColorFill    = isShiftPressed ? fillColorShift : fillColor,
                ColorLine    = isShiftPressed ? lineColorShift : lineColor,
                Sign         = isShiftPressed ? textShift : text,
                Owner        = this
            };

            if (Owner.Owner.Owner.AdjustObjectColorsOnCreation)
            {
                marker.AjustColorScheme(Owner.Owner.Owner);
            }

            marker.DateStart = Chart.StockSeries.GetCandleOpenTimeByIndex(marker.CandleIndex);
            data.Add(marker);
            //var dlg = new ObjectPropertyWindow(new object[] { marker });
            Chart.toolSkipMouseDown = true;
            //dlg.ShowDialog();
        }
Esempio n. 9
0
        protected override void OnMouseDown(List <SeriesEditParameter> parameters,
                                            MouseEventArgs e, Keys modifierKeys, out IChartInteractiveObject objectToEdit)
        {
            objectToEdit = null;
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            var pointD = Chart.Owner.MouseToWorldCoords(e.X, e.Y);

            var incompleted = data.Find(s => s.IsBeingCreated);

            if (incompleted != null)
            {
                return;
            }

            // создать линию, которая будет рисоваться в режиме "резинка"
            var lineType        = SeriesEditParameter.TryGetParamValue(parameters, "Type", TrendLine.TrendLineStyle.Отрезок);
            var lineColor       = SeriesEditParameter.TryGetParamValue(parameters, "Stroke", Color.Black);
            var fillColor       = SeriesEditParameter.TryGetParamValue(parameters, "Filling", Color.White);
            var alphaColor      = SeriesEditParameter.TryGetParamValue(parameters, "Transparency", 192);
            var isHorisont      = SeriesEditParameter.TryGetParamValue(parameters, "Horizontal", false);
            var isHorisontShift = SeriesEditParameter.TryGetParamValue(parameters, "Horizontal_Shift", true);
            var showTags        = SeriesEditParameter.TryGetParamValue(parameters, "Subtitles", true);

            var shiftPressed = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;

            if (!isHorisont)
            {
                isHorisont = shiftPressed && isHorisontShift;
            }

            var span = new TrendLine
            {
                Owner          = this,
                LineStyle      = isHorisont ? TrendLine.TrendLineStyle.Линия : lineType,
                LineColor      = lineColor,
                ShapeFillColor = fillColor,
                ShapeAlpha     = alphaColor,
                IsBeingCreated = true,
                ShowTags       = showTags
            };

            span.AddPoint(pointD.X, pointD.Y);
            if (Owner.Owner.Owner.AdjustObjectColorsOnCreation)
            {
                span.AjustColorScheme(Owner.Owner.Owner);
            }

            // автоматом добавить вторую точку на одной высоте
            if (isHorisont)
            {
                var shouldEdit = SeriesEditParameter.TryGetParamValue(parameters, "Edit", true);
                AddSecondPointAuto(span);
                if (shouldEdit)
                {
                    objectToEdit = span;
                }
            }
            data.Add(span);
        }