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; } }