Exemplo n.º 1
0
        public HermiteSpline InteractiveHermiteSpline(double[] knots, double[] controlPoints, double[] derivations)
        {
            var ellipses           = new List <Ellipse>(knots.Length);
            var derivationEllipses = new List <Ellipse>(derivations.Length);

            double pax, pay;
            double auxKnot, auxFunctionValue;

            for (int i = 0; i < knots.Length; i++)
            {
                pax = TransformCoordinates.WorldAreaToPlotAreaX(knots[i], _plotArea, _worldArea);
                pay = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea);
                ellipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, KNOT_COLOR2));
                auxKnot          = knots[i] - DERIVATIVE_AUX_KNOT_DISTANCE;
                auxFunctionValue = MathOperations.LinearFunction(auxKnot, knots[i], controlPoints[i], derivations[i]);
                pax = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay = TransformCoordinates.WorldAreaToPlotAreaY(auxFunctionValue, _plotArea, _worldArea);
                derivationEllipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2));
            }
            // List<Line> linesOfSpline = HermiteSplineLines(knots,controlPoints);
            HermiteSpline spline = HermiteSpline(knots, controlPoints, derivations);

            spline.DragEllipses       = ellipses;
            spline.DerivationEllipses = derivationEllipses;
            return(spline);
        }
Exemplo n.º 2
0
        public BSpline InteractiveBSpline(int degree, double[] knots, double[] controlPoints, bool containsServiceKnots)
        {
            var ellipses     = new List <Ellipse>();
            var serviceKnots = containsServiceKnots ? knots : SilverlightApplication3.BSpline.ServiceKnots(knots, degree, true);

            double PAControlPoint;
            double PAKnot;

            for (int i = 0; i < controlPoints.Length; i++)
            {
                PAKnot         = TransformCoordinates.WorldAreaToPlotAreaX(serviceKnots[i + 1], _plotArea, _worldArea);
                PAControlPoint = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea);

                if (i < degree - 1)
                {
                    ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, AUX_KNOT_COLOR));
                }
                else
                {
                    ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, KNOT_COLOR));
                }
            }
            var bSpline = BSpline(degree, serviceKnots, controlPoints, true);

            bSpline.DragEllipses = ellipses;
            //gbSpline.isInteractive = true;
            return(bSpline);
        }
Exemplo n.º 3
0
        private void DragCSplineRightDerivation(MouseEventArgs e)
        {
            var cursorPositionY = CursorPositionY(e);

            _selectedEllipse.SetValue(Canvas.TopProperty, cursorPositionY);
            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPositionY + H_DIV_2, _plotArea, _worldArea);
            var xCursorPositionInWA = _selectedClampedSpline.Knots.Last() + SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE;

            _selectedClampedSpline.Derivations[_selectedClampedSpline.Derivations.Count - 1] = MathOperations.DirectionOfLinearFunction(_selectedClampedSpline.Knots.Last(), _selectedClampedSpline.ControlPoints.Last(), xCursorPositionInWA, yCursorPositionInWA);
            var xCursorPosition = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea);

            _dragInfoLabel.WriteAndSetCoordinates(_selectedClampedSpline.Derivations[_selectedClampedSpline.Derivations.Count - 1], xCursorPositionInWA, yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, cursorPositionY + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;
            _canvasUtilities.RefreshClampedSplineInCanvas(_selectedClampedSpline, canvas1, _engine);
        }
Exemplo n.º 4
0
        public GlobalBSpline InteractiveGlobalBSpline(int degree, double[] knots, double[] referencePoints, double leftDerivation, double rightDerivation, bool containsServiceKnots)
        {
            var controlPointsAndAuxKnots =
                _globalBSplineEngine.GlobalControlPointsAndAuxiliaryKnots(degree, knots, referencePoints, leftDerivation, rightDerivation, containsServiceKnots);
            var spline = InteractiveGlobalBSpline(degree, controlPointsAndAuxKnots.Item2, controlPointsAndAuxKnots.Item1, referencePoints, true);

            spline.LeftDerivation  = leftDerivation;
            spline.RightDerivation = rightDerivation;

            Ellipse leftDerEll, rightDerEll;
            double  pax, pay;

            if (containsServiceKnots)
            {
                var auxKnot           = knots[degree] - DERIVATIVE_AUX_KNOT_DISTANCE;
                var auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots[degree], referencePoints.First(), leftDerivation);

                pax        = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay        = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);

                auxKnot           = knots[degree + referencePoints.Length - 1] + DERIVATIVE_AUX_KNOT_DISTANCE;
                auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots[degree + referencePoints.Length - 1], referencePoints.Last(), rightDerivation);

                pax         = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay         = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);
            }
            else
            {
                var auxKnot           = knots.First() - DERIVATIVE_AUX_KNOT_DISTANCE;
                var auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots.First(), referencePoints.First(), leftDerivation);

                pax        = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay        = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);

                auxKnot           = knots.Last() + DERIVATIVE_AUX_KNOT_DISTANCE;
                auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots.Last(), referencePoints.Last(), rightDerivation);

                pax         = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay         = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);
            }
            spline.LeftDerivationEllipse  = leftDerEll;
            spline.RightDerivationEllipse = rightDerEll;
            return(spline);
        }
Exemplo n.º 5
0
        private void DragGBSplineLeftDerivation(MouseEventArgs e)
        {
            var yCursorPosition = CursorPositionY(e);

            _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition);

            var degree = _selectedGlobalBSpline.Degree;
            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea);
            var xCursorPositionInWA = _selectedGlobalBSpline.Knots[degree] - SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE;
            var xCursorPosition     = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea);

            _selectedGlobalBSpline.LeftDerivation = MathOperations.DirectionOfLinearFunction(xCursorPositionInWA, yCursorPositionInWA, _selectedGlobalBSpline.Knots[degree], _selectedGlobalBSpline.FunctionValues[0]);
            _dragInfoLabel.WriteAndSetCoordinates(_selectedGlobalBSpline.LeftDerivation, xCursorPositionInWA, yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, yCursorPosition + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;

            _canvasUtilities.RefreshGlobalBSplineInCanvas(_selectedGlobalBSpline, canvas1, _engine);
        }
Exemplo n.º 6
0
        private void DragHSplineDerivation(MouseEventArgs e)
        {
            var yCursorPosition = CursorPositionY(e);

            _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition);
            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition, _plotArea, _worldArea);
            var xCursorPositionInWA = _selectedHermiteSpline.Knots[_changedPointIndex] - SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE;

            _selectedHermiteSpline.Derivations[_changedPointIndex] =
                MathOperations.DirectionOfLinearFunction(xCursorPositionInWA, yCursorPositionInWA, _selectedHermiteSpline.Knots[_changedPointIndex], _selectedHermiteSpline.ControlPoints[_changedPointIndex]);

            var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedHermiteSpline.Knots[_changedPointIndex], _plotArea, _worldArea);

            _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedHermiteSpline.Derivations[_changedPointIndex], xCursorPositionInWA, yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;

            _canvasUtilities.RefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine);
        }
Exemplo n.º 7
0
        internal GlobalBSpline InteractiveGlobalBSpline(int degree, double[] knots, double[] controlPoints, double[] referencePoints, bool containsServiceKnots)
        {
            var ellipses     = new List <Ellipse>();
            var cpEllipses   = new List <Ellipse>();
            var serviceKnots = containsServiceKnots ? knots : SilverlightApplication3.BSpline.ServiceKnots(knots, degree, true);

            double PAReferencePoint;
            double PAKnot;


            for (int i = 0; i < referencePoints.Length; i++)
            {
                PAKnot           = TransformCoordinates.WorldAreaToPlotAreaX(serviceKnots[degree + i], _plotArea, _worldArea);
                PAReferencePoint = TransformCoordinates.WorldAreaToPlotAreaY(referencePoints[i], _plotArea, _worldArea);
                ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAReferencePoint - H_DIV_2, KNOT_COLOR2));
            }
            double PAControlPoint;


            for (int i = 0; i < controlPoints.Length; i++)
            {
                PAKnot         = TransformCoordinates.WorldAreaToPlotAreaX(serviceKnots[i + 1], _plotArea, _worldArea);
                PAControlPoint = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea);

                if (i < degree - 1)
                {
                    ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, AUX_KNOT_COLOR3));
                }
                else
                {
                    ellipses.Add(_auxiliaryEngine.DrawEllipse(PAKnot - W_DIV_2, PAControlPoint - H_DIV_2, KNOT_COLOR3));
                }
            }

            var gbSpline = GlobalBSpline(degree, serviceKnots, controlPoints, true);

            gbSpline.DragEllipses          = ellipses;
            gbSpline.ControlPointsEllipses = cpEllipses;
            // gbSpline.isInteractive = true;
            gbSpline.FunctionValues = referencePoints.ToList();
            return(gbSpline);
        }
Exemplo n.º 8
0
        private void DragCSpline(MouseEventArgs e)
        {
            var cursorPositionY = CursorPositionY(e);


            _selectedEllipse.SetValue(Canvas.TopProperty, cursorPositionY);
            //_selectedEllipse.SetValue(Canvas.LeftProperty, _lastClickedPositionX);

            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPositionY + H_DIV_2, _plotArea, _worldArea);

            _selectedClampedSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA;
            var xCursorPositionInWA = _selectedClampedSpline.Knots[_changedPointIndex];
            var xCursorPosition     = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea);

            _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedClampedSpline.Knots[_changedPointIndex], yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, cursorPositionY + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;

            _canvasUtilities.RefreshClampedSplineInCanvas(_selectedClampedSpline, canvas1, _engine);
            // }
        }
Exemplo n.º 9
0
        private void DragGBSpline(MouseEventArgs e)
        {
            var yCursorPosition = CursorPositionY(e);

            _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition);
            //try
            //{
            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea);

            _selectedGlobalBSpline.FunctionValues[_changedPointIndex] = yCursorPositionInWA;

            //}
            //catch (Exception) { }
            // _selectedEllipse.SetValue(Canvas.TopProperty, e.GetPosition(LayoutRoot).controlPoints - _point.controlPoints);
            var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedGlobalBSpline.Knots[_changedPointIndex], _plotArea, _worldArea);

            _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedGlobalBSpline.Knots[_changedPointIndex] + _selectedGlobalBSpline.Degree, yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;
            _canvasUtilities.RefreshGlobalBSplineInCanvas(_selectedGlobalBSpline, canvas1, _engine);
            // }
        }
Exemplo n.º 10
0
        public ClampedSpline InteractiveClampedSpline(double[] knots, double[] controlPoints, double leftDerivation, double rightDerivation)
        {
            var     ellipses = new List <Ellipse>(knots.Length);
            Ellipse leftDerEll, rightDerEll;

            double pax, pay;

            var auxKnot         = knots.First() - DERIVATIVE_AUX_KNOT_DISTANCE;
            var auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.First(), controlPoints.First(), leftDerivation);

            pax        = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
            pay        = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea);
            leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2);

            auxKnot         = knots.Last() + DERIVATIVE_AUX_KNOT_DISTANCE;
            auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.Last(), controlPoints.Last(), rightDerivation);

            pax         = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
            pay         = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea);
            rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2);

            for (int i = 0; i < knots.Length; i++)
            {
                pax = TransformCoordinates.WorldAreaToPlotAreaX(knots[i], _plotArea, _worldArea);
                pay = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea);
                ellipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, KNOT_COLOR2));
            }

            // List<Line> linesOfSpline = HermiteSplineLines(knots,controlPoints);
            ClampedSpline spline = ClampedSpline(knots, controlPoints, leftDerivation, rightDerivation);

            spline.DragEllipses           = ellipses;
            spline.LeftDerivationEllipse  = leftDerEll;
            spline.RightDerivationEllipse = rightDerEll;
            return(spline);
        }
Exemplo n.º 11
0
        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // pri kliknuti si ulozime poziciu bodu
            //Point point = e.GetPosition(null);

            // pri double kliku pridavame objekty
            switch (e.ClickCount)
            {
            case 2:
                var cursorPosition     = CursorPosition(e);
                var cursorPositionInWA = TransformCoordinates.PlotAreaToWorldArea(cursorPosition, _plotArea, _worldArea);
                if (_selectedSpline != null)
                {
                    if (_selectedSpline is BSpline)
                    {
                        //_selectedBSpline = (BSpline) _selectedSpline;
                        //var knots = _selectedBSpline.KnotsWithoutServiceKnots().ToList();
                        //var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X);
                        //if (idx != -1)
                        //{
                        //    knots.Insert(idx, cursorPositionInWA.X);
                        //}
                        //else
                        //{
                        //    knots.Add(cursorPositionInWA.X);
                        //}
                    }
                    else if (_selectedSpline is HermiteSpline)
                    {
                        _selectedHermiteSpline = (HermiteSpline)_selectedSpline;

                        for (int i = 0; i < _selectedHermiteSpline.LinesOfSpline.Count; i++)
                        {
                            var b = canvas1.Children.Remove(_selectedHermiteSpline.LinesOfSpline[i]);
                            if (!b)
                            {
                                haha.Text = "cannot remove line";
                            }
                            else
                            {
                                haha.Text = "line removed";
                            }
                        }

                        var knots         = _selectedHermiteSpline.Knots;
                        var controlPoints = _selectedHermiteSpline.ControlPoints;
                        var derivations   = _selectedHermiteSpline.Derivations;

                        var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X);

                        if (idx != -1)
                        {
                            knots.Insert(idx, cursorPositionInWA.X);
                            controlPoints.Insert(idx, cursorPositionInWA.Y);
                            derivations.Insert(idx, 0);
                        }
                        else
                        {
                            knots.Add(cursorPositionInWA.X);
                            controlPoints.Add(cursorPositionInWA.Y);
                            derivations.Add(0);
                        }

                        //_selectedHermiteSpline.Knots = knots;
                        //_selectedHermiteSpline.ControlPoints = controlPoints;
                        //_selectedHermiteSpline.Derivations = derivations;
                        //_canvasUtilities.TotalRefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine);
                        //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.LinesOfSpline);
                        //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DerivationEllipses);
                        //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DragEllipses);
                        //_hermiteSplineList.Remove(_selectedHermiteSpline);


                        var spline = _engine.InteractiveHermiteSpline(_selectedHermiteSpline.Knots.ToArray(), _selectedHermiteSpline.ControlPoints.ToArray(), _selectedHermiteSpline.Derivations.ToArray());
                        _hermiteSplineList.Add(spline);
                    }
                    else if (_selectedSpline is ClampedSpline)
                    {
                    }
                    else if (_selectedSpline is GlobalBSpline)
                    {
                    }
                }


                break;

            // hybanie s objektami
            case 1:
                var elements = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), (UIElement)sender) as List <UIElement>;
                for (int i = 0; i < elements.Count; i++)
                {
                    if (elements[i] is Ellipse)
                    {
                        _selectedEllipse = elements[i];

                        for (int j = 0; j < _bSplineList.Count; j++)
                        {
                            _selectedBSpline   = _bSplineList[j];
                            _selectedSpline    = _selectedBSpline;
                            _changedPointIndex = 0;
                            //if (_selectedBSpline.FunctionValues == null)
                            //{
                            var controlPointsCount = _selectedBSpline.ControlPoints.Count();
                            while (_changedPointIndex < controlPointsCount)
                            {
                                if (_selectedEllipse.Equals(_selectedBSpline.DragEllipses[_changedPointIndex]))
                                {
                                    haha.Text += " CP: " + _changedPointIndex + "   ";
                                    //_changedKnotPos = _changedPointIndex + 1;
                                    if (_changedPointIndex == 0)
                                    {
                                        _leftEllipseX  = -1;
                                        _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    else if (_changedPointIndex == _selectedBSpline.DragEllipses.Count - 1)
                                    {
                                        _leftEllipseX  = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = TransformCoordinates.WorldAreaToPlotAreaX(_selectedBSpline.Knots[_changedPointIndex + 2] - DEFAULT_REDRAWING_PRECISION, _plotArea, _worldArea);
                                    }
                                    else
                                    {
                                        _leftEllipseX  = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    SELECTED_ITEM_TYPE = SelectedDragItem.BSplineEllipse;
                                    _isMoving          = true;
                                    _changedKnotPos    = _changedPointIndex + 1;

                                    // _selectedSpline = _redrawedBSpline;
                                    haha.Text += " Knot: " + _changedKnotPos + "   ";
                                    //goto DRAG; // preskocime nasledujuci for-cyklus
                                    _engine.DrawPrecision = RedrawingPrecision;
                                    _selectedEllipse.CaptureMouse();
                                    return;
                                }
                                _changedPointIndex++;
                            }
                            //}
                            //else
                            //{
                        }

                        for (int j = 0; j < _globalBSplineList.Count; j++)
                        {
                            _selectedGlobalBSpline = _globalBSplineList[j];
                            _selectedSpline        = _selectedGlobalBSpline;
                            _changedPointIndex     = 0;
                            var redrawedGlobalBSplineCount = _selectedGlobalBSpline.ControlPoints.Count();

                            if (_selectedEllipse.Equals(_selectedGlobalBSpline.LeftDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE    = SelectedDragItem.GBSplineLeftDerEllipse;
                                _isMoving             = true;
                                _changedKnotPos       = _changedPointIndex;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else if (_selectedEllipse.Equals(_selectedGlobalBSpline.RightDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE    = SelectedDragItem.GBSplineRightDerEllipse;
                                _isMoving             = true;
                                _changedKnotPos       = _changedPointIndex;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else
                            {
                                while (_changedPointIndex < _selectedGlobalBSpline.FunctionValues.Count())
                                {
                                    if (_selectedEllipse.Equals(_selectedGlobalBSpline.DragEllipses[_changedPointIndex]))
                                    {
                                        //haha.Text += " CP: " + _changedPointIndex + "   ";
                                        SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineEllipse;

                                        // _selectedSpline = _redrawedBSpline;
                                        // haha.Text += " Knot: " + _changedKnotPos + "   ";
                                        //  goto DRAG; // preskocime nasledujuci for-cyklus

                                        _isMoving             = true;
                                        _changedKnotPos       = _changedPointIndex;
                                        _engine.DrawPrecision = RedrawingPrecision;
                                        _selectedEllipse.CaptureMouse();
                                        return;
                                    }
                                    _changedPointIndex++;
                                }
                            }
                        }

                        for (int j = 0; j < _clampedSplineList.Count; j++)
                        {
                            _selectedClampedSpline = _clampedSplineList[j];
                            _selectedSpline        = _selectedClampedSpline;
                            int redrawedCSplineCount = _selectedClampedSpline.ControlPoints.Count();
                            _changedPointIndex = 0;
                            if (_selectedEllipse.Equals(_selectedClampedSpline.LeftDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE = SelectedDragItem.CSplineLeftDerEllipse;
                                _isMoving          = true;
                                //_selectedSpline = _redrawedHermiteSpline;
                                // goto DRAG;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else if (_selectedEllipse.Equals(_selectedClampedSpline.RightDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE = SelectedDragItem.CSplineRightDerEllipse;
                                _isMoving          = true;
                                //_selectedSpline = _redrawedHermiteSpline;
                                // goto DRAG;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else
                            {
                                while (_changedPointIndex < redrawedCSplineCount)
                                {
                                    if (_selectedEllipse.Equals(_selectedClampedSpline.DragEllipses[_changedPointIndex]))
                                    {
                                        //haha.Text += _changedPointIndex + "   ";

                                        SELECTED_ITEM_TYPE = SelectedDragItem.CSplineEllipse;
                                        _isMoving          = true;
                                        //_selectedSpline = _redrawedHermiteSpline;
                                        // goto DRAG;
                                        _engine.DrawPrecision = RedrawingPrecision;
                                        _selectedEllipse.CaptureMouse();
                                        return;
                                    }
                                    _changedPointIndex++;
                                    //   }
                                }
                            }
                        }

                        for (int j = 0; j < _hermiteSplineList.Count; j++)
                        {
                            _selectedHermiteSpline = _hermiteSplineList[j];
                            _selectedSpline        = _selectedHermiteSpline;
                            int redrawedHSplineControlPointsCount = _selectedHermiteSpline.ControlPoints.Count();
                            _changedPointIndex = 0;
                            while (_changedPointIndex < redrawedHSplineControlPointsCount)
                            {
                                if (_selectedEllipse.Equals(_selectedHermiteSpline.DragEllipses[_changedPointIndex]))
                                {
                                    haha.Text += _changedPointIndex + "   ";
                                    if (_changedPointIndex == 0)
                                    {
                                        _leftEllipseX  = -1;
                                        _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    else if (_changedPointIndex == redrawedHSplineControlPointsCount - 1)
                                    {
                                        _leftEllipseX  = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = -1;
                                    }
                                    else
                                    {
                                        _leftEllipseX  = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    SELECTED_ITEM_TYPE = SelectedDragItem.HSplineEllipse;
                                    _isMoving          = true;
                                    //_selectedSpline = _redrawedHermiteSpline;
                                    // goto DRAG;
                                    _engine.DrawPrecision = RedrawingPrecision;
                                    _selectedEllipse.CaptureMouse();
                                    return;
                                }
                                else if (_selectedEllipse.Equals(_selectedHermiteSpline.DerivationEllipses[_changedPointIndex]))
                                {
                                    SELECTED_ITEM_TYPE    = SelectedDragItem.HSplineDerEllipse;
                                    _isMoving             = true;
                                    _engine.DrawPrecision = RedrawingPrecision;
                                    _selectedEllipse.CaptureMouse();
                                    return;
                                }
                                _changedPointIndex++;
                                //   }
                            }
                        }


                        //DRAG:
                        //_selectedEllipse.CaptureMouse();
                    }
                }

                break;
            }
        }
Exemplo n.º 12
0
        private void DragBSpline(MouseEventArgs e)
        {
            if (!UniformBSpline_CheckBox.IsChecked.Value)
            {
                // _lastClickedPositionX = e.GetPosition(LayoutRoot).X - _point.X;
                // yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y;

                var cursorPosition      = CursorPosition(e);
                var xCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaX(cursorPosition.X + W_DIV_2, _plotArea, _worldArea);
                var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPosition.Y + H_DIV_2, _plotArea, _worldArea);

                if (cursorPosition.X <= _leftEllipseX + DEFAULT_REDRAWING_PRECISION)
                {
                    cursorPosition.X = _leftEllipseX + DEFAULT_REDRAWING_PRECISION;
                    // CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline,_changedCPPos,canvas1,_engine);
                    return;
                }
                // else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION && _rightEllipseX != -1)
                else if (cursorPosition.X >= _rightEllipseX - DEFAULT_REDRAWING_PRECISION)// && _stupidFastHackToResolveBugWithBSplineWhenLastEllipseIsDragged)
                {
                    cursorPosition.X = _rightEllipseX - DEFAULT_REDRAWING_PRECISION;
                    //CanvasMyUtils.RemoveCPFromHermiteSpline(_redrawedHermiteSpline, _changedCPPos, canvas1, _engine);
                    return;
                }

                _selectedEllipse.SetValue(Canvas.LeftProperty, cursorPosition.X);
                _selectedEllipse.SetValue(Canvas.TopProperty, cursorPosition.Y);


                //try
                //{


                _selectedBSpline.Knots[_changedKnotPos] = xCursorPositionInWA;

                _selectedBSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA;
                //if (_selectedBSpline.Knots[_changedKnotPos] >= _selectedBSpline.Knots[_changedKnotPos + 1])
                //{
                //    var swap = _selectedBSpline.Knots[_changedKnotPos + 1];
                //    _selectedBSpline.Knots[_changedKnotPos + 1] = _selectedBSpline.Knots[_changedKnotPos];
                //    _selectedBSpline.Knots[_changedKnotPos] = swap;
                //    var idx= _selectedBSpline.DragEllipses.IndexOf(_selectedEllipse as Ellipse);
                //    var swapEl = _selectedBSpline.DragEllipses[idx + 1];
                //    _selectedBSpline.DragEllipses[idx + 1] = _selectedBSpline.DragEllipses[idx];
                //    _selectedBSpline.DragEllipses[idx] = swapEl;
                //}

                //}
                //catch (Exception) { }

                _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, xCursorPositionInWA, yCursorPositionInWA, cursorPosition.X + AVOID_CURSOR_X, cursorPosition.Y + H_DIV_2);
                _dragInfoLabel.Visibility = Visibility.Visible;
                //CanvasMyUtils.OptimizedRefreshBSplineInCanvas(_selectedBSpline, _changedCPPos, canvas1, _engine, false);
                _canvasUtilities.RefreshBSplineInCanvas(_selectedBSpline, canvas1, _engine);
            }
            else
            {
                // yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea);

                //yCursorPosition = e.GetPosition(LayoutRoot).Y - _point.Y;
                var yCursorPosition = CursorPositionY(e);
                _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition);
                //try
                //{
                var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea);
                _selectedBSpline.ControlPoints[_changedPointIndex] = yCursorPositionInWA;


                //}
                //catch (Exception) { }
                var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedBSpline.Knots[_changedKnotPos], _plotArea, _worldArea);
                _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedBSpline.Knots[_changedKnotPos], yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2);
                _dragInfoLabel.Visibility = Visibility.Visible;
                _canvasUtilities.RefreshBSplineInCanvas(_selectedBSpline, canvas1, _engine);
            }
        }
Exemplo n.º 13
0
        private void DefaultCanvas()
        {
            Line            horizontal      = new Line();
            Line            vertical        = new Line();
            TextBlock       min_X_TextBlock = new TextBlock();
            TextBlock       max_X_TextBlock = new TextBlock();
            TextBlock       max_Y_TextBlock = new TextBlock();
            TextBlock       min_Y_TextBlock = new TextBlock();
            SolidColorBrush color           = new SolidColorBrush();

            color.Color = Color.FromArgb(255, 170, 170, 0);

            horizontal.X1 = TransformCoordinates.WorldAreaToPlotAreaX(_worldArea.XMin, _plotArea, _worldArea);
            horizontal.Y1 = _waZeroPointInPACoordinates.Y;
            horizontal.X2 = TransformCoordinates.WorldAreaToPlotAreaX(_worldArea.XMax, _plotArea, _worldArea);
            horizontal.Y2 = _waZeroPointInPACoordinates.Y;

            vertical.X1 = _waZeroPointInPACoordinates.X;
            vertical.Y1 = TransformCoordinates.WorldAreaToPlotAreaY(_worldArea.YMin, _plotArea, _worldArea);
            vertical.X2 = _waZeroPointInPACoordinates.X;
            vertical.Y2 = TransformCoordinates.WorldAreaToPlotAreaY(_worldArea.YMax, _plotArea, _worldArea);


            horizontal.StrokeThickness = 1;
            vertical.StrokeThickness   = 1;
            horizontal.Stroke          = color;
            vertical.Stroke            = color;
            Canvas.SetZIndex(horizontal, 1);

            min_X_TextBlock.Text       = _worldArea.XMin.ToString();
            max_X_TextBlock.Text       = _worldArea.XMax.ToString();
            max_Y_TextBlock.Text       = _worldArea.YMax.ToString();
            min_Y_TextBlock.Text       = _worldArea.YMin.ToString();
            min_X_TextBlock.Height     = 14;
            max_X_TextBlock.Height     = 14;
            max_Y_TextBlock.Height     = 14;
            min_Y_TextBlock.Height     = 14;
            min_X_TextBlock.Width      = 30;
            max_X_TextBlock.Width      = 30;
            max_Y_TextBlock.Width      = 30;
            min_Y_TextBlock.Width      = 30;
            min_X_TextBlock.Foreground = color;
            max_X_TextBlock.Foreground = color;
            max_Y_TextBlock.Foreground = color;
            min_Y_TextBlock.Foreground = color;
            Canvas.SetLeft(min_X_TextBlock, _plotArea.XMin + 10);
            Canvas.SetLeft(max_X_TextBlock, _plotArea.XMax - 30);
            Canvas.SetLeft(max_Y_TextBlock, _plotArea.XMax / 2 + 12);
            Canvas.SetLeft(min_Y_TextBlock, _plotArea.XMax / 2 + 12);
            Canvas.SetTop(min_X_TextBlock, _plotArea.YMax / 2 - 23);
            Canvas.SetTop(max_X_TextBlock, _plotArea.YMax / 2 - 23);
            Canvas.SetTop(max_Y_TextBlock, _plotArea.YMin + 10);
            Canvas.SetTop(min_Y_TextBlock, _plotArea.YMax - 20);
            Canvas.SetZIndex(horizontal, 1);
            Canvas.SetZIndex(horizontal, 1);
            Canvas.SetZIndex(horizontal, 1);
            Canvas.SetZIndex(horizontal, 1);

            _dragInfoLabel            = new DragInfoLabel(CANVAS_TEXT_COLOR);
            _dragInfoLabel.Visibility = Visibility.Collapsed;

            canvas1.Children.Add(_dragInfoLabel);
            canvas1.Children.Add(horizontal);
            canvas1.Children.Add(vertical);
            canvas1.Children.Add(min_X_TextBlock);
            canvas1.Children.Add(min_Y_TextBlock);
            canvas1.Children.Add(max_X_TextBlock);
            canvas1.Children.Add(max_Y_TextBlock);
        }