Exemple #1
0
        private void AnnotationDrag(double xTranslate, double yTranslate)
        {
            ShapeAnnotation selectedAnnotation = (SelectedAnnotation as ShapeAnnotation);
            var             lineAnnotation     = selectedAnnotation as LineAnnotation;
            bool            isDraggable        = (selectedAnnotation.CanResize && AnnotationResizer != null) ?
                                                 !AnnotationResizer.IsResizing :
                                                 (lineAnnotation != null) ?
                                                 !lineAnnotation.IsResizing :
                                                 true;
            object x1, x2, y1, y2;

            if (selectedAnnotation.CanDrag && isDraggable)
            {
                selectedAnnotation.IsDragging = true;
                bool isXAxis = selectedAnnotation.DraggingMode == AxisMode.Horizontal;
                bool isYAxis = selectedAnnotation.DraggingMode == AxisMode.Vertical;
                bool isAll   = selectedAnnotation.DraggingMode == AxisMode.All;
                if (selectedAnnotation.CoordinateUnit == CoordinateUnit.Pixel)
                {
                    x1 = (isAll || isXAxis) ? Convert.ToDouble(selectedAnnotation.X1) + xTranslate : selectedAnnotation.X1;
                    x2 = (isAll || isXAxis) ? Convert.ToDouble(selectedAnnotation.X2) + xTranslate : selectedAnnotation.X2;
                    y1 = (isAll || isYAxis) ? Convert.ToDouble(selectedAnnotation.Y1) + yTranslate : selectedAnnotation.Y1;
                    y2 = (isAll || isYAxis) ? Convert.ToDouble(selectedAnnotation.Y2) + yTranslate : selectedAnnotation.Y2;
                }
                else
                {
                    xTranslate = selectedAnnotation.XAxis.IsInversed ? -xTranslate : xTranslate;
                    yTranslate = selectedAnnotation.YAxis.IsInversed ? -yTranslate : yTranslate;
                    double xAxisChange = selectedAnnotation.XAxis.PixelToCoefficientValue(xTranslate);
                    double yAxisChange = selectedAnnotation.YAxis.PixelToCoefficientValue(yTranslate);

                    x2 = (isAll || isXAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.X2, xAxisChange, true, false), selectedAnnotation.XAxis) : selectedAnnotation.X2;
                    x1 = (isAll || isXAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.X1, xAxisChange, true, false), selectedAnnotation.XAxis) : selectedAnnotation.X1;
                    y2 = (isAll || isYAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.Y2, yAxisChange, false, false), selectedAnnotation.YAxis) : selectedAnnotation.Y2;
                    y1 = (isAll || isYAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.Y1, yAxisChange, false, false), selectedAnnotation.YAxis) : selectedAnnotation.Y1;
                }

                AnnotationManager.SetPosition(
                    PreviousPoints,
                    selectedAnnotation.X1,
                    selectedAnnotation.X2,
                    selectedAnnotation.Y1,
                    selectedAnnotation.Y2);

                AnnotationManager.SetPosition(CurrentPoints, x1, x2, y1, y2);
                RaiseDragStarted(); // Raise DragStarted event
                RaiseDragDelta();   // Raise the DragDelta event

                if (!DragDeltaArgs.Cancel)
                {
                    if (AnnotationResizer != null && !AnnotationResizer.IsResizing)
                    {
                        selectedAnnotation.X1 = AnnotationResizer.X1 = x1;
                        selectedAnnotation.X2 = AnnotationResizer.X2 = x2;
                        selectedAnnotation.Y1 = AnnotationResizer.Y1 = y1;
                        selectedAnnotation.Y2 = AnnotationResizer.Y2 = y2;
                    }
                    else
                    {
                        selectedAnnotation.X1 = x1;
                        selectedAnnotation.X2 = x2;
                        selectedAnnotation.Y1 = y1;
                        selectedAnnotation.Y2 = y2;
                    }

                    var axisMarker = selectedAnnotation as AxisMarker;
                    if (axisMarker != null)
                    {
                        if (axisMarker.ParentAnnotation is VerticalLineAnnotation)
                        {
                            if (axisMarker.ParentAnnotation.XAxis.Orientation == Orientation.Horizontal)
                            {
                                axisMarker.ParentAnnotation.X1 = selectedAnnotation.X1;
                            }
                            else
                            {
                                axisMarker.ParentAnnotation.Y1 = selectedAnnotation.Y1;
                            }
                        }
                        else
                        {
                            if (axisMarker.ParentAnnotation.XAxis.Orientation == Orientation.Vertical)
                            {
                                axisMarker.ParentAnnotation.X1 = selectedAnnotation.X1;
                            }
                            else
                            {
                                axisMarker.ParentAnnotation.Y1 = selectedAnnotation.Y1;
                            }
                        }
                    }

                    if (AnnotationResizer != null)
                    {
                        AnnotationResizer.MapActualValueToPixels();
                    }
                }

                selectedAnnotation.IsDragging = false;
            }
        }