예제 #1
0
 /// <summary>
 /// Callback for the 'add node' context menu option.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event data.</param>
 private void OnAddNode(object sender, EventArgs args)
 {
     try
     {
         // todo: set location to context menu location
         var node = new Node {
             Name = graphView.DirectedGraph.NextNodeID()
         };
         StateNode newNode = new StateNode(node);
         AddNode?.Invoke(this, new AddNodeEventArgs(newNode));
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
예제 #2
0
        /// <summary>
        /// A graph object has been selected. Make the (middle part of) UI relevant to it
        /// </summary>
        /// <param name="objectName">Name of the object to be selected.</param>
        public void Select(string objectName)
        {
            ctxBox.Foreach(c => ctxBox.Remove(c));

            Arc  arc  = graphView.DirectedGraph.Arcs.Find(a => a.Name == objectName);
            Node node = graphView.DirectedGraph.Nodes.Find(n => n.Name == objectName);

            if (node != null)
            {
                //ctxLabel.Text = "State";
                ctxFrame.Label = $"{node.Name} settings";
                // Need to detach the event handlers before changing the entries.
                // Otherwise a changed event will fire which we don't really want.
                nameEntry.Changed -= OnNameChanged;
                // Setting an entry's text to null doesn't seem to have an effect.
                nameEntry.Text     = objectName ?? "";
                nameEntry.Changed += OnNameChanged;
                if (nodeDescriptions.ContainsKey(objectName))
                {
                    descEntry.Changed -= OnDescriptionChanged;
                    descEntry.Text     = nodeDescriptions[objectName] ?? "";
                    descEntry.Changed += OnDescriptionChanged;
                }
                colourChooser.ColorSet -= OnColourChanged;

                colourChooser.Rgba = node.Colour.ToRGBA();

                colourChooser.ColorSet += OnColourChanged;

                ctxBox.PackStart(nodeSelWdgt, true, true, 0);
            }
            else if (arc != null)
            {
                ctxFrame.Label  = "Transition from " + arc.SourceName + " to " + arc.DestinationName;
                RuleList.Text   = String.Join(Environment.NewLine, rules[arc.Name].ToArray());
                ActionList.Text = String.Join(Environment.NewLine, actions[arc.Name].ToArray());
                ctxBox.PackStart(arcSelWdgt, true, true, 0);
            }
            else
            {
                //ctxLabel.Text = "Information";
                //ctxBox.PackStart(infoWdgt, true, true, 0);
                ctxFrame.Label = "";
            }
            ctxBox.ShowAll();
        }