private void OnMouseMove(object sender, MouseEventArgs e) { this.snappedPort = null; bool mouseMessageHandled = false; WorkspaceViewModel wvm = (DataContext as WorkspaceViewModel); // If we are currently connecting and there is an active // connector, redraw it to match the new mouse coordinates. if (wvm.IsSnapping) { if (wvm.portViewModel != null) { if (wvm.CheckActiveConnectorCompatibility(wvm.portViewModel)) { mouseMessageHandled = true; wvm.HandleMouseMove(this.WorkBench, wvm.portViewModel.Center); } } else { wvm.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect); } } if (wvm.IsInIdleState) { // Find the dependency object directly under the mouse // cursor, then see if it represents a port. If it does, // then determine its type, we would like to show the // "ArcRemoving" cursor when the mouse is over an out port. Point mouse = e.GetPosition((UIElement)sender); var dependencyObject = ElementUnderMouseCursor(mouse); PortViewModel pvm = PortFromHitTestResult(dependencyObject); if (null != pvm && (pvm.PortType == PortType.Input)) { this.Cursor = CursorLibrary.GetCursor(CursorSet.ArcSelect); } else { this.Cursor = null; } } if (false == mouseMessageHandled) { wvm.HandleMouseMove(this.WorkBench, e); } }
public void Update(PortViewModel portVM) { var Port = new Port { Id = portVM.Id, Name = portVM.Name, CountryId = portVM.CountryId, Country = portVM.Country }; unitOfWork.PortRepository.Update(Port); unitOfWork.Save(); }
// GET: Ports/Create public async Task <IActionResult> Create(int?id) { var port = await _context.Ports.FindAsync(id); if (id == null || port == null) { return(NotFound()); } var model = new PortViewModel { Port_id = port.Id, }; return(View(model)); }
private void OnMouseRelease(object sender, MouseButtonEventArgs e) { if (e == null) { return; // in certain bizarre cases, e can be null } this.snappedPort = null; var wvm = (DataContext as WorkspaceViewModel); if (wvm == null) { return; } wvm.HandleMouseRelease(workBench, e); }
private void ExecuteSearchElement(ListBoxItem listBoxItem) { var searchElement = listBoxItem.DataContext as NodeSearchElementViewModel; if (searchElement != null) { searchElement.Position = ViewModel.InCanvasSearchPosition; PortViewModel port = ViewModel.PortViewModel; if (searchElement.CreateAndConnectCommand.CanExecute(port.PortModel)) { searchElement.CreateAndConnectCommand.Execute(port.PortModel); Analytics.TrackEvent( Dynamo.Logging.Actions.Select, Dynamo.Logging.Categories.NodeAutoCompleteOperations, searchElement.FullName); } } }
/// <summary> /// This method is called when a mouse button up occured on the adorner. /// </summary> /// <param name="pEventArgs">The event arguments</param> protected override void OnMouseUp(MouseButtonEventArgs pEventArgs) { // Release the mouse capture. if (this.IsMouseCaptured) { this.ReleaseMouseCapture(); } // Getting the position. Point lHitPoint = pEventArgs.GetPosition(this); AdornerLayeredCanvas lParentCanvas = this.AdornedElement as AdornerLayeredCanvas; if (lParentCanvas != null) { // Remove the adorner. AdornerLayer lLayer = lParentCanvas.AdornerLayer; if (lLayer != null) { lLayer.Remove(this); } // Hitting the target connector. InputConnector lTargetConnector = lParentCanvas.HitControl <InputConnector>(lHitPoint); if (lTargetConnector != null) { GraphViewModel lGraphViewModel = lParentCanvas.DataContext as GraphViewModel; if (lGraphViewModel != null) { PortViewModel lTargetViewModel = lTargetConnector.ParentPort.Content as PortViewModel; PortViewModel lSourceViewModel = this.mSourceConnector.ParentPort.Content as PortViewModel; if (lTargetViewModel != null && lSourceViewModel.CanBeConnectedTo(lTargetViewModel)) { ConnectionViewModel lConnectionViewModel = new ConnectionViewModel(); lConnectionViewModel.Output = lSourceViewModel; lConnectionViewModel.Input = lTargetViewModel; lGraphViewModel.AddConnection(lConnectionViewModel); } } } } }
/// <summary> /// Called when the control is initialized. /// </summary> /// <param name="pEventArgs">The event arguments.</param> protected override void OnInitialized(EventArgs pEventArgs) { base.OnInitialized(pEventArgs); // Updating the bindings. if (this.ParentPort != null) { PortViewModel lPortViewModel = this.ParentPort.Content as PortViewModel; // Binding the IsConnected property. Binding lIsConnectedBinding = new Binding("IsConnected"); lIsConnectedBinding.Source = lPortViewModel; lIsConnectedBinding.Mode = BindingMode.OneWayToSource; lIsConnectedBinding.Converter = new BooleanToInt32Converter() { ZeroValue = false }; this.SetBinding(AConnector.ConnectionsCountProperty, lIsConnectedBinding); } }
public async Task <IActionResult> Create(PortViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.ImageFile != null) { path = await _imageHelper.UpLoadImageAsync(model.ImageFile); } var port = await _converterHelper.ToPortAsync(model, path, true); _context.Ports.Add(port); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public override JsonResult Get(int id) { try { var Po = _repository.GetSingle(id); var PoVm = PortViewModel.FromEntity(Po); if (PoVm == null) { return(Json(null)); } return(Json(PoVm)); } catch (Exception ex) { _logger.LogError($"Failed to get Port", ex); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Failed to get Port")); } }
private PortViewModel GetSnappedPort(Point mouseCursor) { if (this.FindNearestPorts(mouseCursor).Count <= 0) return null; double curDistance = 1000000; PortViewModel nearestPort = null; for (int i = 0; i < this.hitResultsList.Count; i++) { DependencyObject depObject = this.hitResultsList[i]; Grid grid = depObject as Grid; if (grid == null) continue; try { UserControl uc = grid.Parent as UserControl; if (null == uc) continue; PortViewModel pvm = uc.DataContext as PortViewModel; if (pvm == null) continue; double distance = Distance(mouseCursor, pvm.Center); if (distance < curDistance) { curDistance = distance; nearestPort = pvm; } } catch { continue; } } return nearestPort; }
public JsonResult GetInactivePorts() { var model = new PortViewModel(); var ports = new List <PortViewModel>(); var tempPorts = _portRepository.GetPorts().Where(x => !x.IsActive).ToList(); if (tempPorts != null && tempPorts.Count > 0) { foreach (var tempPort in tempPorts) { PortViewModel convertedModel = new PortConverter().ConvertToView(tempPort); ports.Add(convertedModel); } } model.Ports = ports.OrderBy(x => x.PortName).ToList(); return(Json(model, JsonRequestBehavior.AllowGet)); }
private void OnMouseMove(object sender, MouseEventArgs e) { this.snappedPort = null; bool snapToCursor = false; WorkspaceViewModel wvm = (DataContext as WorkspaceViewModel); //If we are currently connecting and there is an active connector, //redraw it to match the new mouse coordinates. if (wvm.IsConnecting) { Point mouse = e.GetPosition((UIElement)sender); this.snappedPort = GetSnappedPort(mouse); if (this.snappedPort != null) { snapToCursor = true; wvm.HandleMouseMove(this.WorkBench, this.snappedPort.Center); } this.Cursor = CursorsLibrary.ArcAdding; } else if (Mouse.LeftButton == MouseButtonState.Pressed) { this.Cursor = CursorsLibrary.RectangularSelection; } else { Point mouse = e.GetPosition((UIElement)sender); this.snappedPort = GetSnappedPort(mouse); if (this.snappedPort != null && this.snappedPort.PortType != PortType.OUTPUT) this.Cursor = CursorsLibrary.ArcRemoving; else this.Cursor = CursorsLibrary.UsualPointer; } if (false == snapToCursor) wvm.HandleMouseMove(this.WorkBench, e); }
public async Task <IActionResult> Edit(PortViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.ImageFile != null) { path = await _imageHelper.UpLoadImageAsync(model.ImageFile); } var port = await _converterHelper.ToPortAsync(model, path, false); _context.Ports.Update(port); await _context.SaveChangesAsync(); return(RedirectToAction($"Index")); } else { return(View(model)); } }
public override JsonResult Get() { try { var Ports = _repository.GetAll(); var PortsVm = Ports.Select(x => PortViewModel.FromEntity(x)); if (PortsVm == null) { return(Json(null)); } return(Json(PortsVm)); //return new string[] { "value1", "value2" }; } catch (Exception ex) { _logger.LogError($"Failed to get Ports", ex); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Failed to get Ports")); } }
private PortViewModel GetSnappedPort(Point mouseCursor) { if (this.FindNearestPorts(mouseCursor).Count <= 0) { return(null); } double curDistance = 1000000; PortViewModel nearestPort = null; for (int i = 0; i < this.hitResultsList.Count; i++) { try { DependencyObject depObject = this.hitResultsList[i]; PortViewModel pvm = PortFromHitTestResult(depObject); if (pvm == null) { continue; } double distance = Distance(mouseCursor, pvm.Center); if (distance < curDistance) { curDistance = distance; nearestPort = pvm; } } catch { continue; } } return(nearestPort); }
private void OnMouseRelease(object sender, MouseButtonEventArgs e) { if (e == null) { return; // in certain bizarre cases, e can be null } snappedPort = null; if (ViewModel == null) { return; } // check IsInIdleState and IsPanning before finishing an action with HandleMouseRelease var returnToSearch = (ViewModel.IsInIdleState || ViewModel.IsPanning) && e.ChangedButton == MouseButton.Right && Keyboard.Modifiers == ModifierKeys.Control; ViewModel.HandleMouseRelease(workBench, e); if (returnToSearch) { ViewModel.DynamoViewModel.SearchViewModel.OnRequestFocusSearch(); // do not open context menu in this case e.Handled = true; } }
public JsonResult EditPort(PortViewModel model) { var operationResult = new OperationResult(); Port port = new PortConverter().ConvertToDomain(model); operationResult = _portRepository.UpdatePort(port); if (operationResult.Success) { model.Success = true; var ports = new List <PortViewModel>(); var tempPorts = _portRepository.GetPorts().Where(x => x.IsActive).ToList(); if (tempPorts != null && tempPorts.Count > 0) { foreach (var tempPort in tempPorts) { PortViewModel convertedModel = new PortConverter().ConvertToView(tempPort); ports.Add(convertedModel); } } model.Ports = ports.OrderBy(x => x.PortName).ToList(); } else { model.Success = false; model.Message = operationResult.Message; } return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <summary> /// This method creates the node. /// </summary> /// <param name="pId">The identifier.</param> /// <param name="pTitle">The title.</param> /// <param name="pInputPort">The input port.</param> /// <param name="pOutputPort">The output port.</param> /// <returns>The initialized node</returns> public NodeViewModel CreateNode(string pId, string pTitle, int pInputPort, int pOutputPort) { NodeViewModel lNode = new NodeViewModel(); lNode.DisplayString = pTitle; for (int i = 0; i < pInputPort; i++) { PortViewModel lPort = new PortViewModel(); lPort.DisplayString = string.Format("IPort {0}", i); lPort.Direction = PortDirection.Input; lNode.Ports.Add(lPort); } for (int i = 0; i < pOutputPort; i++) { PortViewModel lPort = new PortViewModel(); lPort.DisplayString = string.Format("OPort {0}", i); lPort.Direction = PortDirection.Output; lNode.Ports.Add(lPort); } return(lNode); }
public ActionResult Create(PortViewModel portVM) { portService.Create(portVM); return(RedirectToAction("Index")); }
/// <summary> /// Returns the node view containing the given view model. /// </summary> /// <param name="pItem">The item contained by the view.</param> /// <returns>The found view if any, null otherwise.</returns> public PortView GetContainerForPortViewModel(PortViewModel pItem) { return(this.mInnerPortContainer.ItemContainerGenerator.ContainerFromItem(pItem) as PortView); }
private void ShowHidePortContextMenu(ShowHideFlags flag, PortViewModel portViewModel) { PortContextMenu.DataContext = portViewModel; ShowHidePopup(flag, PortContextMenu); }
public PortView(PortViewModel viewModel) { InitializeComponent(); DataContext = viewModel; }
private void OnMouseMove(object sender, MouseEventArgs e) { this.snappedPort = null; bool mouseMessageHandled = false; WorkspaceViewModel wvm = (DataContext as WorkspaceViewModel); var currentState = wvm.CurrentState; switch (wvm.CurrentState) { // If we are currently connecting and there is an active // connector, redraw it to match the new mouse coordinates. case WorkspaceViewModel.StateMachine.State.Connection: { Point mouse = e.GetPosition((UIElement)sender); this.snappedPort = GetSnappedPort(mouse); // Check for nearby port to snap if (this.snappedPort != null) { // Nearby port must be compatible for connection if (wvm.CheckActiveConnectorCompatibility(this.snappedPort)) { mouseMessageHandled = true; wvm.HandleMouseMove(this.WorkBench, this.snappedPort.Center); } else { this.snappedPort = null; // remove non-compatible port } } else { wvm.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect); } break; } case WorkspaceViewModel.StateMachine.State.None: { // Find the dependency object directly under the mouse // cursor, then see if it represents a port. If it does, // then determine its type, we would like to show the // "ArcRemoving" cursor when the mouse is over an out port. Point mouse = e.GetPosition((UIElement)sender); var dependencyObject = ElementUnderMouseCursor(mouse); PortViewModel pvm = PortFromHitTestResult(dependencyObject); if (null != pvm && (pvm.PortType == PortType.INPUT)) { this.Cursor = CursorLibrary.GetCursor(CursorSet.ArcSelect); } else { this.Cursor = null; } break; } } if (false == mouseMessageHandled) { wvm.HandleMouseMove(this.WorkBench, e); } }
private void OnMouseMove(object sender, MouseEventArgs e) { this.snappedPort = null; bool mouseMessageHandled = false; // If we are currently connecting and there is an active // connector, redraw it to match the new mouse coordinates. if (ViewModel.IsSnapping) { if (ViewModel.portViewModel != null) { if (ViewModel.CheckActiveConnectorCompatibility(ViewModel.portViewModel)) { mouseMessageHandled = true; ViewModel.HandleMouseMove(workBench, ViewModel.portViewModel.Center); } } else { ViewModel.CurrentCursor = CursorLibrary.GetCursor(CursorSet.ArcSelect); } } if (ViewModel.IsInIdleState) { // Find the dependency object directly under the mouse // cursor, then see if it represents a port. If it does, // then determine its type, we would like to show the // "ArcRemoving" cursor when the mouse is over an out port. Point mouse = e.GetPosition((UIElement)sender); var dependencyObject = ElementUnderMouseCursor(mouse); PortViewModel pvm = PortFromHitTestResult(dependencyObject); if (null != pvm && (pvm.PortType == PortType.Input)) { this.Cursor = CursorLibrary.GetCursor(CursorSet.ArcSelect); } else { this.Cursor = null; } } // If selection is going to be dragged and ctrl is pressed. if (ViewModel.IsDragging && Keyboard.Modifiers == ModifierKeys.Control) { var currentMousePosition = e.GetPosition(null); // Set initialMousePosition here, so that we can use it in OnDragOver. initialMousePosition = e.GetPosition(WorkspaceElements); // Check that current mouse position is far enough from start position. var canDrag = (Math.Abs(currentMousePosition.X - startMousePosition.X) > SystemParameters.MinimumHorizontalDragDistance) && (Math.Abs(currentMousePosition.Y - startMousePosition.Y) > SystemParameters.MinimumVerticalDragDistance) && e.OriginalSource is DragCanvas; if (canDrag) { DragAndDrop(e.GetPosition(WorkspaceElements)); mouseMessageHandled = true; } } if (!mouseMessageHandled) { ViewModel.HandleMouseMove(workBench, e); } }
private void OnMouseRelease(object sender, MouseButtonEventArgs e) { this.snappedPort = null; WorkspaceViewModel wvm = (DataContext as WorkspaceViewModel); wvm.HandleMouseRelease(this.WorkBench, e); }