protected override void OnModelPropertyChanged(string propertyName) { RaisePropertyChanged(propertyName); if (propertyName == "Presentation") { RemoveNodeCommand.RaiseCanExecuteChanged(); RemoveAllButCommand.RaiseCanExecuteChanged(); ShowCyclesCommand.RaiseCanExecuteChanged(); RemoveNodesWithoutSourcesCommand.RaiseCanExecuteChanged(); RemoveNodesWithoutTargetsCommand.RaiseCanExecuteChanged(); RemoveNodesWithoutSiblingsCommand.RaiseCanExecuteChanged(); ShowNodesOutsideClustersCommand.RaiseCanExecuteChanged(); FoldUnfoldAllClustersCommand.RaiseCanExecuteChanged(); AddVisibleNodesOutsideClustersToClusterCommand.RaiseCanExecuteChanged(); ClearSelectionCommand.RaiseCanExecuteChanged(); InvertSelectionCommand.RaiseCanExecuteChanged(); HomeCommand.RaiseCanExecuteChanged(); InvalidateLayoutCommand.RaiseCanExecuteChanged(); PrintGraphCommand.RaiseCanExecuteChanged(); BuildClustersMenu(); BuildSelectedNodesMenu(); if (myTransformationsModuleObserver != null) { mySelectionObserver.ModuleChanged -= OnSelectionChanged; mySelectionObserver.Dispose(); mySelectionObserver = null; myTransformationsModuleObserver.ModuleChanged -= OnTransformationsModuleChanged; myTransformationsModuleObserver.Dispose(); myTransformationsModuleObserver = null; } if (Presentation != null) { var transformations = Presentation.GetModule <ITransformationModule>(); myTransformationsModuleObserver = transformations.CreateObserver(); myTransformationsModuleObserver.ModuleChanged += OnTransformationsModuleChanged; mySelectionObserver = Presentation.GetPropertySetFor <Selection>().CreateObserver(); mySelectionObserver.ModuleChanged += OnSelectionChanged; } } }
//Test if any objects were clicked private void checkSelect() { //Stores the command that needs to be executed EditCommand selectionCommand = null; //If escape is pressed, deselect all if (Input.GetKeyDown(KeyCode.Escape)) { selectionCommand = new DeselectAllCommand(); } //If escape was not pressed, check for shortcut commands else { if (selectAllShortcut.Pressed()) { if (selectedObjects.Count > 0) { selectionCommand = new DeselectAllCommand(); } else { selectionCommand = new SelectAllCommand(); } } if (invertSelectionShortcut.Pressed()) { selectionCommand = new InvertSelectionCommand(); } } //If the mouse was clicked and the cursor is not over the UI, check if any objects were selected if (Input.GetMouseButtonUp(0) && !EventSystem.current.IsPointerOverGameObject(-1)) { RaycastHit hit; Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); bool rayHit = Physics.Raycast(ray, out hit, Mathf.Infinity); //Check if nothing was hit or the hit object isn't selectable if (!rayHit || hit.transform.gameObject.tag != "Selectable") { //If not in additive mode and there is a selection, deselect all if (!Input.GetKey(KeyCode.LeftControl) && Instance.selectedObjects.Count > 0) { selectionCommand = new DeselectAllCommand(); } } //If an object was clicked, select it else { //Select the parent of the object GameObject parentObject = GetParent(hit.transform.gameObject); //If left control is not held, deselect all objects and select the clicked object if (!Input.GetKey(KeyCode.LeftControl)) { //If the clicked object is already the only selected object, skip it if (Instance.selectedObjects.Count == 1 && Instance.selectedObjects.Contains(parentObject)) { return; } selectionCommand = new SelectReplaceCommand(parentObject); } //If left control is held, select or deselect the object based on if its currently selected else { if (!selectedObjects.Contains(parentObject)) { selectionCommand = new SelectAdditiveCommand(parentObject); } else { selectionCommand = new DeselectObjectCommand(parentObject); } } } } //If a selection was made, execute its associated command and add it to the history if (selectionCommand != null) { selectionCommand.ExecuteEdit(); EditHistory.Instance.AddCommand(selectionCommand); } }