//Сделал неочевидную передачу параметра, чтобы не пересчитывать центр масс private bool UpdateSelectedViewInfo(CenterOfMass centerOfMass) { bool selectedItemExist = manipulator.SelectedItem != null; if (selectedItemExist) { int currentAngle = 0; int currentLength = 0; int currentInternalX = 0; int currentInternalY = 0; float currentWeight = manipulator.SelectedItem.Weight; if (manipulator.SelectedItem.ElementType == ManipulatorElement.elementTypes.LINK) { Link selectedLink = (Link)manipulator.SelectedItem; currentAngle = (int)(selectedLink.Angle * 180 / Math.PI); currentLength = (int)selectedLink.Length; currentInternalX = (int)selectedLink.InternalCoordinates.X; currentInternalY = (int)-selectedLink.InternalCoordinates.Y; } textBoxTestAngle.Text = currentAngle.ToString(); textBoxTestLength.Text = currentLength.ToString(); textBoxInternalX.Text = currentInternalX.ToString(); textBoxInternalY.Text = currentInternalY.ToString(); textBoxWeight.Text = currentWeight.ToString(); } return(selectedItemExist); }
//Если не будет привязки придется дергать её1 public void ReRenderCanvas(ref Canvas canvas) { if (manipulator != null) { CenterOfMass centerOfMass = manipulator.GetCenterOfMass(); bool selectedItemExist = UpdateSelectedViewInfo(centerOfMass); int centOfMassXVal = (int)((centerOfMass.BeginPosition.X - manipulator.elements[0].BeginPosition.X)); int centOfMassYVal = (int)((-centerOfMass.BeginPosition.Y + manipulator.elements[0].BeginPosition.Y)); textBoxCenterOfMassX.Text = centOfMassXVal.ToString(); textBoxCenterOfMassY.Text = centOfMassYVal.ToString(); double beginX = canvasMain.ActualWidth / 2 * ManipulatorElement.scaleCoefficient; double beginY = canvasMain.ActualHeight / 2 * ManipulatorElement.scaleCoefficient; if (manipulator.IsThereAnyIntersections()) { foreach (var element in manipulator.elements) { element.Stroke = System.Windows.Media.Brushes.Red; } } else { foreach (var element in manipulator.elements) { element.Stroke = System.Windows.Media.Brushes.Blue; } } manipulator.CenterFirstElement(new Point(beginX, beginY)); if (manipulator.IsShapesOutOfCanvas(canvasMain.ActualHeight * ManipulatorElement.scaleCoefficient, canvasMain.ActualWidth * ManipulatorElement.scaleCoefficient)) { if (selectedItemExist) { manipulator.SelectedItem.Stroke = System.Windows.Media.Brushes.Red; } ManipulatorElement.scaleCoefficient += (float)0.5; } else { if (selectedItemExist) { manipulator.SelectedItem.Stroke = System.Windows.Media.Brushes.Black; } } canvasMain.Children.Clear(); for (int i = 0; i < manipulator.elements.Count; i++) { canvasMain.Children.Add(manipulator.elements[i]); } if (manipulator.SelectedItem != null && manipulator.SelectedItem.ElementType == ManipulatorElement.elementTypes.LINK) { Link selectedLink = (Link)manipulator.SelectedItem; canvasMain.Children.Add(selectedLink.InternalCoordinates); } canvasMain.Children.Add(centerOfMass); } }