/// <summary> /// Метод взаимодействия с диалоговым окном открытия файла. Открывается /// файл ".txt" или ".dbsp". /// </summary> /// <param name="fileParser"> /// Экземпляр класса <see cref="FileParser"/>. /// </param> /// <param name="splineCollection"> /// Экземпляр класса <see cref="SplineCollection"/>. /// сплайна. /// </param> public void OpenFile(FileParser fileParser, SplineCollection splineCollection) { pointsListDialogs.splineCollection = splineCollection; openFileDialog = new OpenFileDialog { Filter = "Text files (*.txt)|*.txt|DeBoorsSplines" + " files (*.dbsp)|*.dbsp|All files (*.*)|*.*" }; if (openFileDialog.ShowDialog() == true) { try { Path = openFileDialog.FileName; fileParser.ReadFile(Path, splineCollection); pointsListDialogs.SetPointsList(); OnPointsRenewer = drawingClass.DrawControlLines; } catch (FileException e) { OnPointsRenewer = null; ShowErrorMessage(e.Message); } catch (IOException e) { OnPointsRenewer = null; ShowErrorMessage(e.Message); } catch (Exception e) { OnPointsRenewer = null; ShowErrorMessage(e.Message); } } }
// Обработчик отпускания кнопки муши над рабочей поверхностью. private void DrawingCanvas_MouseUp(object sender, MouseButtonEventArgs e) { double xPosition = e.GetPosition(DrawingCanvas).X, yPosition = e.GetPosition(DrawingCanvas).Y; int xChanges = (int)(OldCoordinateX - xPosition), yChanges = (int)(OldCoordinateY - yPosition); if (mouseClicked && RelocateSplineRadioButton.IsChecked == true) { for (int i = 0; i < DrawingCanvas.Children.Count; i++) { if (DrawingCanvas.Children[i] is Line) { Line line = DrawingCanvas.Children[i] as Line; line.X1 -= xChanges; line.X2 -= xChanges; line.Y1 -= yChanges; line.Y2 -= yChanges; DrawingCanvas.Children[i] = line; } else if (DrawingCanvas.Children[i] is Ellipse) { Ellipse ellipse = DrawingCanvas.Children[i] as Ellipse; Canvas.SetLeft(ellipse, Canvas.GetLeft(ellipse) - xChanges); Canvas.SetTop(ellipse, Canvas.GetTop(ellipse) - yChanges); DrawingCanvas.Children[i] = ellipse; } else { Label label = DrawingCanvas.Children[i] as Label; Canvas.SetLeft(label, Canvas.GetLeft(label) - xChanges); Canvas.SetTop(label, Canvas.GetTop(label) - yChanges); DrawingCanvas.Children[i] = label; } } if (splineCollection.PointsList != null) { for (int i = 0; i < splineCollection.PointsList.Count(); i++) { splineCollection.PointsList[i].PointX -= xChanges; splineCollection.PointsList[i].PointY -= yChanges; } pointsListDialogs.SetPointsList(); } } if (mouseClicked && RelocatePointRadioButton.IsChecked == true && splineCollection.PointsList != null && ShowControlCheckBox.IsChecked == true) { bool pointChecker = false; int relocatedPointIndex = 0; for (int i = 0; i < splineCollection.PointsList.Count(); i++) { if (OldCoordinateX >= splineCollection.PointsList[i].PointX - 5 && OldCoordinateX <= splineCollection.PointsList[i].PointX + 5 && OldCoordinateY >= splineCollection.PointsList[i].PointY - 5 && OldCoordinateY <= splineCollection.PointsList[i].PointY + 5) { pointChecker = true; relocatedPointIndex = i; break; } } if (pointChecker) { splineCollection.PointsList[relocatedPointIndex].PointX -= xChanges; splineCollection.PointsList[relocatedPointIndex].PointY -= yChanges; Visualize(); } } mouseClicked = false; }