private void treeView_DragOver(object sender, DragEventArgs e) { try { Point currentPosition = e.GetPosition(sceneNodesTreeView); if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 10.0) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 10.0)) { // Verify that this is a valid drop and then store the drop target SceneNodeView item = e.OriginalSource as SceneNodeView; if (CheckDropTarget(draggedItem, item)) { e.Effects = DragDropEffects.Move; } else { e.Effects = DragDropEffects.None; } } e.Handled = true; } catch { } }
//Add Scene node private void addSceneNode_Click(object sender, RoutedEventArgs e) { SceneNode newItem = new SceneNode(); if (currentConfig.selectedSceneNodeView != null) { newItem.parent = currentConfig.selectedSceneNodeView.node; } SceneNodeView newViewItem = new SceneNodeView(newItem); newViewItem.isSelected = true; currentConfig.sceneNodes.Add(newItem); SceneNodeView parentNode = currentConfig.FindParentNode(newViewItem); if (parentNode == null) { currentConfig.sceneNodesView.Add(newViewItem); } else { parentNode.children.Add(newViewItem); parentNode.isExpanded = true; } AppLogger.Add("New scene node added"); AppLogger.Add("WARNING! Change default values"); sceneNodesTreeView.Items.Refresh(); sceneNodeIdTb.Focus(); }
//Return child Scene node View if it equal argument scene node public SceneNodeView FindNodeInChildren(SceneNodeView item) { SceneNodeView output = null; if (this.node == item.node.parent) { output = this; } else { foreach (SceneNodeView child in this.children.ToList()) { if (child.node == item.node.parent) { output = child; } else { if (child.children.Count > 0) { output = child.FindNodeInChildren(item); } } } } return(output); }
private bool CheckDropTarget(SceneNodeView _sourceItem, object _targetItem) { SceneNodeView target = (SceneNodeView)_targetItem; //Check whether the target item is meeting your condition bool _isEqual = false; if (!_sourceItem.node.Equals(target.node)) { _isEqual = true; } return(_isEqual); }
private void treeView_MouseMove(object sender, MouseEventArgs e) { try { if (e.LeftButton == MouseButtonState.Pressed) { if (!(e.OriginalSource is System.Windows.Controls.Primitives.Thumb)) { Point currentPosition = e.GetPosition(sceneNodesTreeView); if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 10.0) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 10.0)) { if (isNode) { draggedItem = (SceneNodeView)sceneNodesTreeView.SelectedItem; } if (draggedItem != null) { DragDropEffects finalDropEffect = DragDrop.DoDragDrop(sceneNodesTreeView, sceneNodesTreeView.SelectedValue, DragDropEffects.Move); //Checking target is not null and item is //dragging(moving) if (finalDropEffect == DragDropEffects.Move) { if (_target == null) { CopyItem(draggedItem, _target); draggedItem = null; } else { // A Move drop was accepted if (!draggedItem.node.Equals(_target.node)) { CopyItem(draggedItem, _target); _target = null; draggedItem = null; } } } } } } } } catch { } }
//Delete Scene Node private void deleteSceneNode_Click(object sender, RoutedEventArgs e) { if (sceneNodesTreeView.SelectedItem != null) { SceneNodeView item = (SceneNodeView)sceneNodesTreeView.SelectedItem; var id = item.node.id; currentConfig.DeleteSceneNode(item); currentConfig.selectedSceneNodeView = currentConfig.sceneNodesView.FirstOrDefault(); AppLogger.Add("Scene Node " + id + " deleted"); } sceneNodesTreeView.Items.Refresh(); parentWallsCb.Items.Refresh(); }
private void CopyItem(SceneNodeView _sourceItem, SceneNodeView _targetItem) { //Alert if node sets as child of it's own child node if (_targetItem != null && _sourceItem.FindNodeInChildren(_targetItem) != null) { InfoDialog alertDialog = new InfoDialog("Scene node can not be a child node of own children!"); alertDialog.Owner = this; alertDialog.Show(); } else { //Asking user wether he want to drop the dragged TreeViewItem here or not YesNoDialog dialogResult = new YesNoDialog("Would you like to drop " + _sourceItem.node.id + " into " + _targetItem.node.id + ""); dialogResult.Owner = this; if ((bool)dialogResult.ShowDialog()) { try { //finding Parent TreeViewItem of dragged TreeViewItem SceneNodeView ParentItem = currentConfig.FindParentNode(_sourceItem); if (ParentItem == null) { ((List <SceneNodeView>)sceneNodesTreeView.ItemsSource).Remove(_sourceItem); } else { ParentItem.children.Remove(_sourceItem); } //adding dragged TreeViewItem in target TreeViewItem if (_targetItem == null) { ((List <SceneNodeView>)sceneNodesTreeView.ItemsSource).Add(_sourceItem); _sourceItem.node.parent = null; } else { _targetItem.children.Add(_sourceItem); _sourceItem.node.parent = _targetItem.node; } //Set SceneNode of _targetItem as parent node for _sourceItem Scene Node } catch { } sceneNodesTreeView.Items.Refresh(); } } }
public SceneNodeView FindParentNode(SceneNodeView item) { SceneNodeView parentNode = sceneNodesView.Find(x => x.node == item.node.parent); if (parentNode == null) { foreach (SceneNodeView node in sceneNodesView) { if (node.FindNodeInChildren(item) != null) { parentNode = node.FindNodeInChildren(item); } } } return(parentNode); }
public Config() { clusterNodes = new List <ClusterNode>(); viewports = new List <Viewport>(); sceneNodes = new List <SceneNode>(); sceneNodes = new List <SceneNode>(); sceneNodesView = ConvertSceneNodeList(sceneNodes); screens = new List <Screen>(); inputs = new List <BaseInput>(); selectedSceneNodeView = new SceneNodeView(new SceneNode { id = string.Empty, locationX = string.Empty, locationY = string.Empty, locationZ = string.Empty, rotationP = string.Empty, rotationY = string.Empty, rotationR = string.Empty, tracker = new TrackerInput(), trackerCh = string.Empty, parent = null }); cameraLocationX = "0"; cameraLocationY = "0"; cameraLocationZ = "0"; cameraTracker = null; cameraTrackerCh = "0"; //Stereo settings eyeDist = "0.064"; eyeSwap = false; //Debug settings lagSimulation = false; lagMaxTime = "0"; drawStats = false; //Master node settings portCs = "00001"; portSs = "00000"; //General settings string defaultSwapSync = "1"; if (swapSyncPolicy.ContainsKey(defaultSwapSync)) { selectedSwapSync = swapSyncPolicy.FirstOrDefault(x => x.Key == defaultSwapSync); } }
private void treeView_Drop(object sender, DragEventArgs e) { try { SceneNodeView TargetItem = null; e.Effects = DragDropEffects.None; e.Handled = true; if (sender is TreeViewItem) { // Verify that this is a valid drop and then store the drop target ContentPresenter presenter = e.Source as ContentPresenter; TargetItem = presenter.Content as SceneNodeView; } if (draggedItem != null) { _target = TargetItem; e.Effects = DragDropEffects.Move; } } catch { } }
public void DeleteSceneNode(SceneNodeView item) { if (item.children != null) { foreach (SceneNodeView child in item.children.ToList()) { DeleteSceneNode(child); } } if (item.node.parent == null) { sceneNodesView.Remove(item); } else { SceneNodeView parentNode = FindParentNode(item); if (parentNode != null) { parentNode.children.Remove(item); } } AppLogger.Add("Scene node " + item.node.id + " deleted"); sceneNodes.Remove(item.node); }