public void Shape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount == 1) { UndoRedoManager.putInUndoStack((ScrollableCanvas)currentCanvas); UndoRedoManager.clearRedoStack((ScrollableCanvas)currentCanvas); // clear bitmap effect for previous selected entity if (selected != null) { selected.defaultBitmapEffect(); } selected = sender as UIEntity; Mouse.Capture(selected); captured = true; double xCanvas = e.GetPosition(this).X; double yCanvas = e.GetPosition(this).Y; selected.putMovingCoordinate(selected, VisualTreeHelper.GetOffset(selected).X, VisualTreeHelper.GetOffset(selected).Y, xCanvas, yCanvas); if (selected.Label != null) { selected.putMovingCoordinate(selected.Label, VisualTreeHelper.GetOffset(selected.Label).X, VisualTreeHelper.GetOffset(selected.Label).Y, xCanvas, yCanvas); } foreach (Port p in selected.getPorts()) { selected.putMovingCoordinate( p, VisualTreeHelper.GetOffset(p).X, VisualTreeHelper.GetOffset(p).Y, xCanvas, yCanvas); } if (!(selected is ConnectionLine && selected is Port)) { selected.selectedBitmapEffect(); } ParameterProccesor.drawParameters(selected, propertiesPanel, false); } else if (e.ClickCount == 2 && !(sender is Port || sender is ConnectionLine)) { OpenShapeProperties_Click(sender, e); } }
public ParameterDialog(List <UIParam> param, sapr_sim.Figures.UIEntity owner) { InitializeComponent(); this.parameters = param; this.owner = owner; image.Source = new BitmapImage(new Uri(@"pack://application:,,,/" + owner.iconPath(), UriKind.Absolute)); description.Text = owner.description(); ParameterProccesor.drawParameters(owner, sp, true); }
private void btnDialogOk_Click(object sender, RoutedEventArgs e) { bool result; if (ParameterProccesor.newResource == null || ParameterProccesor.newResource.GetType() == owner.GetType()) { result = applyNewParams(parameters); ParameterProccesor.newResource = null; } else { MainWindow mw = (MainWindow)System.Windows.Application.Current.MainWindow; Point p = new Point(VisualTreeHelper.GetOffset(owner).X + MainWindow.X_OFFSET * (-1), VisualTreeHelper.GetOffset(owner).Y + MainWindow.Y_OFFSET * (-1)); result = applyNewParams(ParameterProccesor.newResource.getParams()); mw.currentEntity = ParameterProccesor.newResource; mw.drawOnCanvas(p); mw.selected = ParameterProccesor.newResource; restoreConnectionLines(mw); mw.deleteEntity(owner); ParameterProccesor.drawParameters(ParameterProccesor.newResource, sp, false); ParameterProccesor.newResource = null; mw.currentEntity = null; } if (result) { this.Close(); ((MainWindow)System.Windows.Application.Current.MainWindow).ModelChanged(); } }
static void ParameterProccesor_SelectionChanged(object sender, SelectionChangedEventArgs e) { ResourceType oldRt = (e.RemovedItems[0] as ResourceType); ResourceType newRt = (e.AddedItems[0] as ResourceType); Resource res = entity as Resource; if (ResourceType.WORKER.Equals(newRt)) { newResource = new WorkerResource(res.canvas) { Count = res.Count, IsShared = res.IsShared }; } else if (ResourceType.INSTRUMENT.Equals(newRt)) { newResource = new InstrumentResource(res.canvas) { Count = res.Count, IsShared = res.IsShared }; } else if (ResourceType.MATERIAL.Equals(newRt)) { newResource = new MaterialResource(res.canvas) { Count = res.Count, IsShared = res.IsShared }; } if (!ResourceType.nameList().Contains(res.EntityName)) { newResource.EntityName = res.EntityName; } ParameterProccesor.drawParameters(newResource, panel, true); }
private void LeftSideAlignment_Click(object sender, RoutedEventArgs e) { int i = 0; for (int j = 1; j < 10; j++) { int koef = j * 10; //Чтобы что-то ровнять, нужно получить список элементов и контрол где они расположены foreach (object child in this.currentCanvas.Children) { if (child is UIEntity) { UIElement control = child as UIElement; UIElement container = VisualTreeHelper.GetParent(control) as UIElement; Point relativeLocation = control.TranslatePoint(new Point(0, 0), container); UIEntity curElement = child as UIEntity; if (child is Figures.Procedure || child is Figures.Resource) { double x = Convert.ToInt32(relativeLocation.X / koef) * koef; double y = Convert.ToInt32(relativeLocation.Y / koef) * koef; Canvas.SetLeft(curElement, x); Canvas.SetTop(curElement, y); if (child is Figures.Procedure) { selected = child as Figures.Procedure; } else if (child is Figures.Resource) { selected = child as Figures.Resource; } double xCanvas = relativeLocation.X; //Mouse.GetPosition(this).X; ; double yCanvas = relativeLocation.Y; //Mouse.GetPosition(this).Y; selected.putMovingCoordinate(selected, VisualTreeHelper.GetOffset(selected).X, VisualTreeHelper.GetOffset(selected).Y, xCanvas, yCanvas); if (selected.Label != null) { selected.putMovingCoordinate(selected.Label, VisualTreeHelper.GetOffset(selected.Label).X, VisualTreeHelper.GetOffset(selected.Label).Y, xCanvas, yCanvas); } foreach (Port p in selected.getPorts()) { selected.putMovingCoordinate( p, VisualTreeHelper.GetOffset(p).X, VisualTreeHelper.GetOffset(p).Y, xCanvas, yCanvas); } if (!(selected is ConnectionLine && selected is Port)) { selected.selectedBitmapEffect(); } ParameterProccesor.drawParameters(selected, propertiesPanel, false); processCoordinatesHandler(selected, x, y); if (selected.Label != null) { processCoordinatesHandler(selected.Label, x, y); } foreach (Port p in selected.getPorts()) { processCoordinatesHandler(p, x, y); } ModelChanged(); } } } } }