void viewer_RightClick(object sender, MouseEventArgs e)//+++ { //notice that the context menu is possible only in the root view //i.e. when reduct of the fa in the current context has the empty tree position if (e.Button == MouseButtons.Right && this.finiteAutomatonContext.reductName.treePosition.IsEmpty) { if (viewer.SelectedObject is GraphLayout.Drawing.Node && this.exploredTransitions != null) { GraphLayout.Drawing.Node currentGleeNode = viewer.SelectedObject as GraphLayout.Drawing.Node; //populate the context menu with actions that can be explored Node currentNode = this.nodes[currentGleeNode]; Map <Symbol, Sequence <CompoundTerm> > enabledActions = Map <Symbol, Sequence <CompoundTerm> > .EmptyMap; foreach (Symbol actionSymbol in this.exploredTransitions.GetEnabledActionSymbols(currentNode)) { Sequence <CompoundTerm> actions = new Sequence <CompoundTerm>(this.exploredTransitions.GetEnabledActions(currentNode, actionSymbol)); if (actions.Count > 0) { enabledActions = enabledActions.Add(actionSymbol, actions); } } bool someSymbolIsVisible = false; bool allSymbolsAreFullyVisible = true; //populate and show the expand context menu, one per action symbol List <ToolStripMenuItem> expandItems = new List <ToolStripMenuItem>(enabledActions.Count); foreach (Pair <Symbol, Sequence <CompoundTerm> > entry in enabledActions) { ToolStripMenuItem expandItem = new ToolStripMenuItem(entry.First.FullName); //expandItem.Tag = new Pair<Node, Sequence<CompoundTerm>>(currentNode, entry.Second); //expandItem.Click += new EventHandler(actionSymbol_Click); expandItem.DisplayStyle = ToolStripItemDisplayStyle.Text; //expandItem.CheckOnClick = false; ToolStripMenuItem[] subitems = new ToolStripMenuItem[entry.Second.Count]; bool someActionIsVisible = false; bool allActionsAreVisible = true; for (int i = 0; i < subitems.Length; i++) { subitems[i] = new ToolStripMenuItem(entry.Second[i].ToCompactString()); subitems[i].Tag = new Pair <Node, CompoundTerm>(currentNode, entry.Second[i]); subitems[i].Click += new EventHandler(action_Click); subitems[i].DisplayStyle = ToolStripItemDisplayStyle.Text; subitems[i].CheckOnClick = false; if (this.exploredTransitions.IsActionVisible(currentNode, entry.Second[i])) { subitems[i].Checked = true; subitems[i].ToolTipText = "Uncheck to hide"; someActionIsVisible = true; someSymbolIsVisible = true; } else { subitems[i].Checked = false; subitems[i].ToolTipText = "Check to show"; allActionsAreVisible = false; allSymbolsAreFullyVisible = false; } } if (allActionsAreVisible) { expandItem.CheckState = CheckState.Checked; } else if (someActionIsVisible) { expandItem.CheckState = CheckState.Indeterminate; } else { expandItem.CheckState = CheckState.Unchecked; } //if (expandItem.CheckState == CheckState.Checked) // expandItem.ToolTipText = "Uncheck to hide all " + entry.First.FullName + " transitions from selected state"; //else // expandItem.ToolTipText = "Check to show all " + entry.First.FullName + " transitions from selected state"; //add a menu item to hide all actions #region showAll - menu item to show all actions ToolStripMenuItem showAll = new ToolStripMenuItem("Show All"); showAll.Tag = new Pair <Node, Sequence <CompoundTerm> >(currentNode, entry.Second); showAll.DisplayStyle = ToolStripItemDisplayStyle.Text; showAll.CheckOnClick = false; showAll.Checked = false; showAll.Click += new EventHandler(showAll_Click); #endregion #region hideAll - menu item to hide all actions ToolStripMenuItem hideAll = new ToolStripMenuItem("Hide All"); hideAll.Tag = new Pair <Node, Symbol>(currentNode, entry.First); hideAll.DisplayStyle = ToolStripItemDisplayStyle.Text; hideAll.CheckOnClick = false; hideAll.Checked = false; hideAll.Click += new EventHandler(hideAll_Click); #endregion expandItem.DropDownItems.AddRange(subitems); expandItem.DropDownItems.Add(new ToolStripSeparator()); expandItem.DropDownItems.Add(showAll); expandItem.DropDownItems.Add(hideAll); expandItems.Add(expandItem); } this.expandToolStripMenuItem.DropDownItems.Clear(); this.expandToolStripMenuItem.DropDownItems.AddRange(expandItems.ToArray()); if (allSymbolsAreFullyVisible) { this.expandToolStripMenuItem.CheckState = CheckState.Checked; } else if (someSymbolIsVisible) { this.expandToolStripMenuItem.CheckState = CheckState.Indeterminate; } else { this.expandToolStripMenuItem.CheckState = CheckState.Unchecked; } this.exploreContextMenuStrip.Show(this.viewer, e.Location); } } }
void GraphView_MouseClick(object sender, MouseEventArgs e) { if (viewer.SelectedObject is GraphLayout.Drawing.Node) { if (selectedAglNode != viewer.SelectedObject) { //UnSelectPreviousSelection if (selectedAglNode != null) { SetNodeSelectionColor(selectedAglNode, (GraphLayout.Drawing.Color)selectedNodeOriginalColor); } selectedAglNode = (GraphLayout.Drawing.Node)viewer.SelectedObject; selectedNode = this.nodes[selectedAglNode]; RememberSelectedNodeOriginalColor(selectedAglNode); SetNodeSelectionColor( selectedAglNode,ToAglColor(this.selectionColor)); this.viewer.Invalidate(); UpdateStateViewer(); } if (e.Button == MouseButtons.Right) { this.selectNodeContextMenuStrip.Show(this.viewer,e.Location); } } else { UnSelectPreviousSelection(); } this.viewer.Focus(); }
/// <summary> /// Refreshes the control and recreates the graph if needed. /// </summary> /// <param name="levent">Unused event arguments.</param> protected override void OnLayout(LayoutEventArgs levent) { // If the graph has changed, if (graphChanged) { // Always refresh the property grid since this is quick. propertyGrid.Refresh(); //always unselect any possibly selected or hovered node because the //selection will not be valid after redrawing the graph this.stateViewer1.SetState(null); this.selectedAglNode = null; this.previouslyHoveredObject = null; this.stateViewer1.Title = "No state is selected"; // Reset the status since we're going to recreate it now. graphChanged = false; // If we have a state machine. if (finiteAutomatonContext.fa != null) { // The background thread actually lays out the graph. if (!graphWorker.IsBusy) { // Start using the wait cursor and disable the controls. Application.UseWaitCursor = true; Enabled = false; progressBar.Visible = true; // Begin the calculation. graphWorker.RunWorkerAsync(); } else { // DrawGraph was called in the middle of a layout operation somehow. // We can't cancel graph layout, so for now we will just ignore it. } } else { // Clear the display. viewer.Graph = null; } } base.OnLayout(levent); }
private void UnSelectPreviousSelection() { if (selectedAglNode != null) { SetNodeSelectionColor(selectedAglNode,(GraphLayout.Drawing.Color)selectedNodeOriginalColor); selectedAglNode = null; selectedNode = null; this.viewer.Invalidate(); this.stateViewer1.SetState(null); this.stateViewer1.Title = "No state is selected"; } }
//Dictionary<ReductName, FAContext> reductCache = new Dictionary<ReductName, FAContext>(); private void ShowReduct(ReductName reductName) { FAContext faContext1; //if (!reductCache.TryGetValue(reductName, out faContext1)) //{ Dictionary<Term, IState> reductStateMap; Dictionary<Term, IState> stateMap = new Dictionary<Term, IState>(); foreach (Term t in faInfo.fa.States) { stateMap[t] = faInfo.stateProvider(t); } FSM fa = FSMBuilder.ProjectFromProduct(faInfo.fa, ProjectedActionSymbols(reductName.treePosition), reductName.treePosition, stateMap, out reductStateMap); faContext1 = new FAContext(fa, delegate(Term n) { return reductStateMap[n]; }, reductName, ProjectedModelProgram(reductName.treePosition));//+++ //reductCache[reductName] = faContext1; //} finiteAutomatonContext = faContext1; graphChanged = true; this.selectedAglNode = null; //forget previous selected glee node this.selectedNode = null; //forget previous selected corresponding node PerformLayout(); }
void ReselectNode() { //find the corresponding new AGL node, if it exists this.selectedAglNode = this.FindAglNode(selectedNode); if (this.selectedAglNode != null) { RememberSelectedNodeOriginalColor(selectedAglNode); SetNodeSelectionColor( selectedAglNode,ToAglColor(this.selectionColor)); this.viewer.Invalidate(); UpdateStateViewer(); } else //forget the previous selection that is invalid { this.selectedNode = null; } }