private void copySubtree() { if (tempNode != null) { foreach (var subtree in tempNode.IterateNodesPostfix()) { var visualNode = GetVisualSymbolicExpressionTreeNode(subtree); visualNode.LineColor = Color.Black; visualNode.TextColor = Color.Black; if (subtree.Parent != null) { var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(subtree.Parent, subtree); visualLine.LineColor = Color.Black; } } } tempNode = currSelected.Content; foreach (var node in tempNode.IterateNodesPostfix()) { var visualNode = GetVisualSymbolicExpressionTreeNode(node); visualNode.LineColor = Color.LightGray; visualNode.TextColor = Color.LightGray; foreach (var subtree in node.Subtrees) { var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree); visualLine.LineColor = Color.LightGray; } } currSelected = null; RepaintNodes(); // no need to redo the layout and repaint everything since this operation does not change the tree }
public PropertiesPouch() : base(PropertiesPouchResource.Title) { // Wait for the toolbox to receive and parse the widget's properties before attempting to show them. ToolboxApp.Bus.Listen <ShowWidgetPropertyEditors>(e => { // should the VisualTreeNodeSelected message come in first, wait. SpinWait.SpinUntil(() => SelectedNode != null, TimeSpan.FromSeconds(2)); Application.Instance.AsyncInvoke(() => { var result = _grid.ShowEditors(SelectedNode); if (result) { _pouchHeader.Text = $"{SelectedNode.DisplayName} properties"; } }); }); // listen and record the visual tree node that was selected. ToolboxApp.Bus.Listen <VisualTreeNodeSelected>(args => { SelectedNode = args.Node; }); }
private void InitTree(Transform go) { VisualTreeNode node = go.GetComponent<VisualTreeNode>(); if(node != null) { node.probs.SetActive(true); foreach(InputField i in node.probs.GetComponentsInChildren<InputField>()) { i.text = ""; } if(go.childCount == 3) { Transform t = go.GetChild(2); node.children = t.gameObject; InitTree(t.GetChild(0)); InitTree(t.GetChild(1)); InitTree(t.GetChild(2)); } if(go.parent.name.Equals("Tree")) { node.probs.SetActive(false); } else { if(node.children) node.children.SetActive(false); } } }
private void HandleKitNumberChanged(object sender, TextChangedEventArgs e) { TextConversions.TryGetKitRoot(kitNumber.Text, schema, null, out var root); SelectedKit = root; acceptButton.IsEnabled = root != null; kitName.Content = root?.KitOnlyDescription.Format(root.Context, data); }
private void HandleTreeViewSelection(object sender, RoutedPropertyChangedEventArgs <object> e) { var item = (TreeViewItem)e.NewValue; CurrentNode = (VisualTreeNode)item?.Tag; LoadDetailsPage(); }
private Control GetHeader(VisualTreeNode node) { var result = new StackPanel { Orientation = Orientation.Horizontal, Gap = 8, Children = new Controls { new TextBlock { FontStyle = node.IsInTemplate ? FontStyle.Italic : FontStyle.Normal, Text = node.Type, }, new TextBlock { [!TextBlock.TextProperty] = node.WhenAnyValue(x => x.Classes), } } }; result.PointerEnter += AddAdorner; result.PointerLeave += RemoveAdorner; return(result); }
public IEnumerable <IPropertyEditorModel> CreateEditors(VisualTreeNode node, IEnumerable <XenProperty> properties) { var editors = new List <IPropertyEditorModel>(); foreach (var property in properties.OrderBy(p => p.PropertyName)) { var model = ToolboxApp.Editors.Create(property); if (model == null) { ToolboxApp.Log.Error($"Error adding {property.XenType.FullName} type editor."); continue; } model.VisualNode = node; editors.Add(model); model.Saving += (_, args) => { var widget = args.Node.Widget; var isAp = args.Property.XenType.Descriptor.HasFlag(XenPropertyDescriptors.AttachedProperty); ToolboxApp.Designer.SetProperty(widget, args.Property, args.ToolboxValue, args.IsBase64, isAp, args.Metadata); }; } return(editors); }
/// <summary> /// 1. Add a visual tree node to a tree item. /// 2. Find the imediate children and add them as a child. /// 3. Repeat. /// </summary> /// <param name="parentNode"></param> /// <param name="parentItem"></param> private void AddNodeToVisualTree(VisualTreeNode parentNode, TreeGridItem parentItem) { // If the parentNode doesn't have any children, no need to continue. if (parentNode.Widget?.Children == null || !parentNode.Widget.Children.Any()) { return; } foreach (var child in parentNode.Widget.Children) { _views++; var childNode = new VisualTreeNode { Widget = child }; var childGridItem = new TreeGridItem { Tag = childNode, Expanded = true }; parentItem.Children.Add(childGridItem); AddNodeToVisualTree(childNode, childGridItem); } }
private void contextMenuStrip_Opened(object sender, EventArgs e) { var menuStrip = (ContextMenuStrip)sender; var point = menuStrip.SourceControl.PointToClient(Cursor.Position); var ea = new MouseEventArgs(MouseButtons.Left, 1, point.X, point.Y, 0); var visualNode = FindVisualSymbolicExpressionTreeNodeAt(ea.X, ea.Y); if (visualNode != null) { OnSymbolicExpressionTreeNodeClicked(visualNode, ea); } else { currSelected = null; } if (currSelected == null) { insertNodeToolStripMenuItem.Visible = false; changeNodeToolStripMenuItem.Visible = false; copyToolStripMenuItem.Visible = false; cutToolStripMenuItem.Visible = false; removeToolStripMenuItem.Visible = false; pasteToolStripMenuItem.Visible = false; } else { var node = currSelected.Content; insertNodeToolStripMenuItem.Visible = true; changeNodeToolStripMenuItem.Visible = true; changeNodeToolStripMenuItem.Enabled = (node is SymbolicExpressionTreeTerminalNode); insertNodeToolStripMenuItem.Enabled = !changeNodeToolStripMenuItem.Enabled; copyToolStripMenuItem.Visible = true; cutToolStripMenuItem.Visible = true; removeToolStripMenuItem.Visible = true; pasteToolStripMenuItem.Visible = true; pasteToolStripMenuItem.Enabled = tempNode != null && insertNodeToolStripMenuItem.Enabled && !(lastOp == EditOp.CutSubtree && tempNode.IterateNodesBreadth().Contains(node)) && node.SubtreeCount < node.Symbol.MaximumArity; } }
private void LoadView() { var boundItems = new List <(TreeViewItem, ModuleAddress)>(); var rootGuiNode = CreateNode(RootNode); treeView.Items.Clear(); treeView.Items.Add(rootGuiNode); CurrentNode = RootNode; LoadDetailsPage(); TreeViewItem CreateNode(VisualTreeNode vnode) { var node = new TreeViewItem { Header = FormatNodeDescription(vnode), Tag = vnode }; foreach (var address in vnode.Description.GetSegmentAddresses(vnode.Context)) { boundItems.Add((node, address)); } foreach (var vchild in vnode.Children) { var childNode = CreateNode(vchild); node.Items.Add(childNode); } return(node); } treeViewItemsToUpdateBySegmentStart = boundItems .ToLookup(pair => pair.Item2, pair => pair.Item1); }
private Kit CreateKit(VisualTreeNode kitRoot) { // We clone the data from kitNode downwards, but relocating it as if it were the first kit. var firstKitNode = Schema.KitRoots[1]; var clonedData = kitRoot.Context.CloneData(Data, firstKitNode.Context.Address); return(new Kit(Schema, clonedData, kitRoot.KitNumber.Value)); }
protected VisualTreeCommand(IMessageBus messaging, ToolboxSocket socket, ToolboxLogging log) { Log = log; Messaging = messaging; Socket = socket; messaging.Listen <VisualTreeNodeSelected>(payload => { Node = payload.Node; }); }
private void removeNodeToolStripMenuItem_Click(object sender, EventArgs e) { var node = currSelected.Content; if (node == tempNode) { tempNode = null; } ModifyTree(Tree, node.Parent, node, null, removeSubtree: false); currSelected = null; // because the currently selected node was just deleted }
public CopyKitTargetDialog(ModuleSchema schema, ModuleData data, VisualTreeNode sourceKitNode) : this() { this.schema = schema; this.data = data; sourceKitName.Content = sourceKitNode.KitOnlyDescription.Format(sourceKitNode.Context, data); // This is done after other control initialization so that everything is set up. // It would probably be more elegant to do everything in a view model and use binding, // admittedly. kitNumber.TextChanged += HandleKitNumberChanged; HandleKitNumberChanged(null, null); kitNumber.PreviewTextInput += TextConversions.CheckDigits; }
private void removeSubtreeToolStripMenuItem_Click(object sender, EventArgs e) { var node = currSelected.Content; if (node.IterateNodesPostfix().Contains(tempNode)) { tempNode = null; } ModifyTree(Tree, node.Parent, node, null, removeSubtree: true); currSelected = null; // because the currently selected node was just deleted contextMenuStrip.Close(); // avoid display of submenus since the action has already been performed }
private void PaintNodeImpacts() { var impacts = nodeImpacts.Values; double max = impacts.Max(); double min = impacts.Min(); foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) { VisualTreeNode <ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) { visualTree.ToolTip = visualTree.Content.ToString(); double impact = nodeImpacts[treeNode]; // impact = 0 if no change // impact < 0 if new solution is better // impact > 0 if new solution is worse if (impact < 0.0) { // min is guaranteed to be < 0 visualTree.FillColor = Color.FromArgb((int)(impact / min * 255), Color.Red); } else if (impact.IsAlmost(0.0)) { visualTree.FillColor = Color.White; } else { // max is guaranteed to be > 0 visualTree.FillColor = Color.FromArgb((int)(impact / max * 255), Color.Green); } visualTree.ToolTip += Environment.NewLine + "Node impact: " + impact; var constantReplacementNode = foldedNodes[treeNode] as ConstantTreeNode; if (constantReplacementNode != null) { visualTree.ToolTip += Environment.NewLine + "Replacement value: " + constantReplacementNode.Value; } } if (visualTree != null) { if (changedNodes.ContainsKey(treeNode)) { visualTree.LineColor = Color.DodgerBlue; } else if (treeNode is ConstantTreeNode && foldedNodes.ContainsKey(treeNode)) { visualTree.LineColor = Color.DarkOrange; } } } treeChart.RepaintNodes(); }
private static Control GetHeader(VisualTreeNode node) { TextBlock result = new TextBlock(); result.Text = node.Type; if (node.IsInTemplate) { result.FontStyle = Media.FontStyle.Italic; } return(result); }
private static JObject ConvertToJson(VisualTreeNode container, ModuleData data) { var ret = new JObject(); foreach (var child in container.Children) { var description = child.KitOnlyDescription ?? child.Description; ret.Add(description.Format(child.Context, data), ConvertToJson(child, data)); } foreach (var detail in container.Details) { ret.Add(detail.Description, ConvertToJson(detail, container.Context, data)); } return(ret); }
public bool ShowEditors(VisualTreeNode node, XenConstructor ctor) { try { Clear(); var editors = new List <IPropertyEditorModel>(); foreach (var p in ctor.Parameters.OrderBy(p => p.ParameterName)) { var model = ToolboxApp.Editors.Create(p); if (model == null) { ToolboxApp.Log.Error($"Error creating {p.ShortTypeName} property editor."); continue; } p.Value = null; model.VisualNode = node; editors.Add(model); var captured = p; model.Saving += (sender, args) => { captured.Value = args.ToolboxValue; }; } foreach (var editor in editors) { Editors.Add(editor); } DataStore = Editors; if (Editors.Any()) { ScrollToRow(0); } } catch (Exception e) { ToolboxApp.Log.Error(e, $"Error while showing property editors for {node.DisplayName}."); return(false); } return(true); }
private void insertNodeToolStripMenuItem_Click(object sender, EventArgs e) { if (currSelected == null || currSelected.Content is SymbolicExpressionTreeTerminalNode) { return; } var parent = currSelected.Content; using (var dialog = new InsertNodeDialog()) { dialog.SetAllowedSymbols(grammar.Symbols.Where(s => !(s is ProgramRootSymbol || s is StartSymbol || s is Defun || s is GroupSymbol))); // allow everything dialog.ShowDialog(this); if (dialog.DialogResult != DialogResult.OK) { return; } var symbol = dialog.SelectedSymbol; var node = symbol.CreateTreeNode(); if (node is ConstantTreeNode) { var constant = node as ConstantTreeNode; constant.Value = double.Parse(dialog.constantValueTextBox.Text); } else if (node is VariableTreeNode) { var variable = node as VariableTreeNode; variable.Weight = double.Parse(dialog.variableWeightTextBox.Text); variable.VariableName = dialog.SelectedVariableName; } else if (node.Symbol.MinimumArity <= parent.SubtreeCount && node.Symbol.MaximumArity >= parent.SubtreeCount) { for (int i = parent.SubtreeCount - 1; i >= 0; --i) { var child = parent.GetSubtree(i); parent.RemoveSubtree(i); node.AddSubtree(child); } } // the if condition will always be true for the final else clause above if (parent.Symbol.MaximumArity > parent.SubtreeCount) { ModifyTree(Tree, parent, null, node); } } currSelected = null; }
void GetStates(Transform go, ref List <JsonStateInput> states, string path) { Transform t = null; VisualTreeNode node = go.GetComponent <VisualTreeNode>(); if (node != null && node.children != null) { t = node.children.transform; } if (t != null && t.gameObject.activeInHierarchy) { GetStates(t.GetChild(0), ref states, "0" + path); GetStates(t.GetChild(1), ref states, "1" + path); GetStates(t.GetChild(2), ref states, "2" + path); } else if (node.probs.activeInHierarchy) { Transform inputs = node.probs.transform; JsonStateInput s = new JsonStateInput(); s.path = path; //get prob0 foreach (var p in inputs.GetChild(0).GetComponentsInChildren <Text>()) { if (p.name.Equals("Text")) { s.probEvent0 = p.text; break; } } //get prob1 foreach (var p in inputs.GetChild(1).GetComponentsInChildren <Text>()) { if (p.name.Equals("Text")) { s.probEvent1 = p.text; break; } } states.Add(s); } }
internal DataExplorer(ILogger logger, ModuleSchema schema, ModuleData data, VisualTreeNode rootNode, RolandMidiClient midiClient, string fileName, string saveFileFilter, string explorerName) : this() { Logger = logger; Schema = schema; Data = data; MidiClient = midiClient; RootNode = rootNode; this.saveFileFilter = saveFileFilter; this.explorerName = explorerName; this.fileName = fileName; if (midiClient == null) { mainPanel.Children.Remove(midiPanel); } Data.DataChanged += HandleModuleDataChanged; LoadView(); UpdateTitle(); }
private static Control GetHeader(VisualTreeNode node) { return(new StackPanel { Orientation = Orientation.Horizontal, Gap = 8, Children = new Controls { new TextBlock { Text = node.Type, FontStyle = node.IsInTemplate ? Media.FontStyle.Italic : Media.FontStyle.Normal, }, new TextBlock { [!TextBlock.TextProperty] = node.WhenAnyValue(x => x.Classes), } } }); }
private void pasteToolStripMenuItem_Clicked(object sender, EventArgs e) { if (!(lastOp == EditOp.CopySubtree || lastOp == EditOp.CutSubtree)) { return; } // check if the copied/cut node (stored in the tempNode) can be inserted as a child of the current selected node var node = currSelected.Content; if (node is ConstantTreeNode || node is VariableTreeNode) { return; } // check if the currently selected node can accept the copied node as a child // no need to check the grammar, an arity check will do just fine here if (node.Symbol.MaximumArity <= node.SubtreeCount) { return; } switch (lastOp) { case EditOp.CutSubtree: { if (tempNode.IterateNodesBreadth().Contains(node)) { throw new ArgumentException(); // cannot cut/paste a node into itself } ModifyTree(Tree, tempNode.Parent, tempNode, null); //remove node from its original parent ModifyTree(Tree, node, null, tempNode); //insert it as a child to the new parent break; } case EditOp.CopySubtree: { var clone = (SymbolicExpressionTreeNode)tempNode.Clone(); ModifyTree(Tree, node, null, clone); break; } } currSelected = null; // because the tree will have changed tempNode = null; // clear the clipboard after one paste }
void SetTree(string depth, double [] probs, VisualTreeNode node) { if (!depth.Equals("")) { int nextNode = Int32.Parse(depth[depth.Length - 1].ToString()); GameObject children = node.children; if (children != null && !children.activeInHierarchy) { node.probs.SetActive(false); children.SetActive(true); } SetTree(depth.Substring(0, depth.Length - 1), probs, node.children.transform.GetChild(nextNode).GetComponent <VisualTreeNode>()); } else { Transform probsT = node.probs.transform; probsT.GetChild(0).GetComponent <InputField>().text = (probs[0]).ToString(); probsT.GetChild(1).GetComponent <InputField>().text = (probs[1]).ToString(); probsT.GetChild(2).GetComponent <InputField>().text = (1 - probs[0] - probs[1]).ToString(); } }
// Note: this used to be in ModuleJson.ToModuleSchema(), but it turns out it's really useful for // a field to have access to the schema it's part of... which is tricky when everything is immutable // and the schema also has to have references to the fields. So this code is ugly - and makes field testing // trickier - but at least it's pleasant to use elsewhere. internal ModuleSchema(ModuleJson json) { // Note: we populate everything other than the fields first, so that field // construction can rely on it. json.Validate(); Identifier = new ModuleIdentifier(json.Name !, json.ModelId !.Value, json.FamilyCode !.Value, json.FamilyNumberCode !.Value); InstrumentGroups = json.BuildInstrumentGroups(); PresetInstruments = InstrumentGroups.SelectMany(ig => ig.Instruments) .OrderBy(i => i.Id) .ToList() .AsReadOnly(); // Just validate that our list is consistent. for (int i = 0; i < PresetInstruments.Count; i++) { if (PresetInstruments[i].Id != i) { throw new InvalidOperationException($"Instrument {PresetInstruments[i]} is in index {i}"); } } UserSampleInstruments = Enumerable.Range(0, json.UserSamples !.Value) .Select(id => Instrument.FromUserSample(id)) .ToList() .AsReadOnly(); // Now do everything with the fields. Root = new FixedContainer(json.BuildRootContainer(this), new ModuleAddress(0)); LogicalRoot = json.BuildLogicalRoot(Root); PhysicalRoot = VisualTreeNode.FromFixedContainer(null, Root); KitRoots = LogicalRoot.DescendantNodesAndSelf() .Where(node => node.KitNumber != null) .ToDictionary(node => node.KitNumber !.Value) .AsReadOnly(); LoadableContainersByAddress = Root .DescendantsAndSelf() .Where(context => context.Container.Loadable) .ToDictionary(context => context.Address, context => context.Container) .AsReadOnly(); }
public bool ShowEditors(VisualTreeNode node, IEnumerable <XenProperty> properties = null, bool editable = true) { try { Clear(); var props = properties ?? node.Widget.Properties; if (properties != null && !editable) { props = properties.Select(p => { var clone = p.ShallowClone(); clone.CanWrite = false; return(clone); }).ToArray(); } var editors = CreateEditors(node, props); foreach (var editor in editors) { Editors.Add(editor); } DataStore = Editors; if (Editors.Any()) { ScrollToRow(0); } } catch (Exception e) { ToolboxApp.Log.Error(e, $"Error while showing property editors for {node.DisplayName}."); return(false); } return(true); }
private void changeNodeToolStripMenuItem_Click(object sender, EventArgs e) { if (currSelected == null) { return; } var node = (ISymbolicExpressionTreeNode)currSelected.Content.Clone(); var originalNode = currSelected.Content; ISymbolicExpressionTreeNode newNode = null; var result = DialogResult.Cancel; if (node is ConstantTreeNode) { using (var dialog = new ConstantNodeEditDialog(node)) { dialog.ShowDialog(this); newNode = dialog.NewNode; result = dialog.DialogResult; } } else if (node is VariableTreeNode) { using (var dialog = new VariableNodeEditDialog(node)) { dialog.ShowDialog(this); newNode = dialog.NewNode; result = dialog.DialogResult; } } if (result != DialogResult.OK) { return; } ModifyTree(Tree, originalNode.Parent, originalNode, newNode); // this will replace the original node with the new node currSelected = null; }
public InteractiveSymbolicExpressionTreeChart() { InitializeComponent(); currSelected = null; tempNode = null; }
protected void DrawLine(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> startNode, VisualTreeNode<ISymbolicExpressionTreeNode> endNode) { var origin = new Point(startNode.X + startNode.Width / 2, startNode.Y + startNode.Height); var target = new Point(endNode.X + endNode.Width / 2, endNode.Y); graphics.Clip = new Region(new Rectangle(Math.Min(origin.X, target.X), origin.Y, Math.Max(origin.X, target.X), target.Y)); var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(startNode.Content, endNode.Content); using (var linePen = new Pen(visualLine.LineColor)) { linePen.DashStyle = visualLine.DashStyle; graphics.DrawLine(linePen, origin, target); } }
protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) { graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1)); graphics.Clear(backgroundColor); var node = visualTreeNode.Content; using (var textBrush = new SolidBrush(visualTreeNode.TextColor)) using (var nodeLinePen = new Pen(visualTreeNode.LineColor)) using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) { //draw terminal node if (node.SubtreeCount == 0) { graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); } else { graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); } //draw name of symbol var text = node.ToString(); graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat); } }
public static Dialog Create(PropertyEditorModel <object> model, VisualTreeNode treeNode) { var id = treeNode.Widget.Id; var editable = false; var dlg = new ConnectedDialog { Title = $"Edit {model.DisplayName}", Padding = AppStyles.WindowPadding, Width = 365, Height = 420 }; var grid = new PropertyEditorGridView(); var constructorDdl = new DropDown { Enabled = false }; // default to show the user, so it doesn't flicker into view. constructorDdl.Items.Add("Not Applicable", "Not Applicable"); constructorDdl.SelectedIndex = 0; var createBtn = new Button { Enabled = false, Text = "Create" }; var showBtn = new Button { Enabled = false, Text = "Show" }; ToolboxApp.AppEvents.Bus.Listen <ConstructorCalled>(args => { Application.Instance.Invoke(() => { dlg.Close(); }); }); ToolboxApp.AppEvents.Bus.Listen <ConstructorsReceived>(args => { Application.Instance.Invoke(() => { showBtn.Enabled = editable; constructorDdl.Enabled = editable; if (editable) { // clear default constructorDdl.Items.Clear(); foreach (var ctor in args.Type.Constructors) { var item = new ListItem { Text = ctor.DisplayName, Tag = ctor }; constructorDdl.Items.Add(item); } } if (constructorDdl.Items.Count > 0) { constructorDdl.SelectedIndex = 0; } }); }); ToolboxApp.AppEvents.Bus.Listen <ObjectPropertiesReceived>(args => { Application.Instance.Invoke(() => { var xt = model.Property.XenType; editable = xt.Descriptor.HasFlag(XenPropertyDescriptors.ValueType) && model.Property.CanWrite; grid.ShowEditors(treeNode, args.Properties, editable); }); }); ToolboxApp.Designer.GetObjectProperties(id, model.Property.Path); ToolboxApp.Designer.GetConstructors(model.FullTypeName); var propLabel = new Label { Text = model.Property.CanWrite ? "Properties" : "Properties are readonly" }; var container = new TableLayout(1, 7) { Spacing = new Size(10, 5) }; var constructors = new TableLayout(2, 1) { Spacing = new Size(5, 5) }; constructors.Add(constructorDdl, 0, 0, true, false); constructors.Add(showBtn, 1, 0, false, false); var predefinedDdl = new DropDown(); var footer = new TableLayout(3, 1) { Padding = new Padding(0, 5, 0, 0), Spacing = new Size(5, 5), }; var escapeBtn = new Button { Text = "Ok" }; footer.Add(null, 0, 0, true, false); footer.Add(createBtn, 1, 0, false, false); footer.Add(escapeBtn, 2, 0, false, false); container.Add("Constructors", 0, 0, true, false); container.Add(constructors, 0, 1, true, false); container.Add($"{model.ShortTypeName} predefined values", 0, 2, true, false); container.Add(predefinedDdl, 0, 3, true, false); container.Add(propLabel, 0, 4, true, false); container.Add(grid, 0, 5, true, true); container.Add(footer, 0, 6, true, false); dlg.Content = container; escapeBtn.Click += (s, e) => { dlg.Close(); }; dlg.AbortButton = escapeBtn; dlg.DefaultButton = escapeBtn; if (!model.Property.CanWrite) { predefinedDdl.Items.Add("Not Applicable", "Disabled"); predefinedDdl.SelectedIndex = 0; predefinedDdl.Enabled = false; } else { // refactor predefinedDdl.Items.Add("Custom", "Custom"); var vals = model.Property?.XenType?.PossibleValues; if (vals != null) { foreach (var v in vals) { predefinedDdl.Items.Add(v, v); } } predefinedDdl.SelectedIndex = 0; } predefinedDdl.SelectedIndexChanged += (sender, args) => { grid.Enabled = predefinedDdl.SelectedIndex == 0; if (predefinedDdl.SelectedIndex != 0) { model.ToolboxValue = predefinedDdl.SelectedValue.ToString(); } }; dlg.Shown += (sender, args) => { ToolboxApp.Log.Trace($"Showing {nameof(ObjectEditDialog)} for {treeNode.DisplayName}."); }; dlg.Closing += (sender, args) => { ToolboxApp.Bus.StopListening <ObjectPropertiesReceived>(); ToolboxApp.Bus.StopListening <ConstructorsReceived>(); ToolboxApp.Bus.StopListening <ConstructorCalled>(); ToolboxApp.Log.Trace($"Closing {nameof(ObjectEditDialog)} for {treeNode.DisplayName}."); }; createBtn.Click += (sender, args) => { var item = constructorDdl.SelectedValue as ListItem; var ctor = item?.Tag as XenConstructor; if (ctor != null) { ToolboxApp.Designer.CallConstructor(treeNode.Widget.Id, model.Property, ctor); } }; showBtn.Click += (sender, args) => { var item = constructorDdl.SelectedValue as ListItem; var tag = item?.Tag as XenConstructor; if (tag != null) { predefinedDdl.Enabled = false; createBtn.Enabled = true; escapeBtn.Text = "Cancel"; grid.ShowEditors(treeNode, tag); } else { ToolboxApp.Log.Error($"The selected constructor for {treeNode.DisplayName} did not contain a valid tag."); } }; return(dlg); }
public void RepaintNode(VisualTreeNode<ISymbolicExpressionTreeNode> visualNode) { if (!suspendRepaint) { using (var graphics = Graphics.FromImage(image)) { graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; DrawTreeNode(graphics, visualNode); } this.Refresh(); } }
private void insertNodeToolStripMenuItem_Click(object sender, EventArgs e) { if (currSelected == null || currSelected.Content is SymbolicExpressionTreeTerminalNode) return; var parent = currSelected.Content; using (var dialog = new InsertNodeDialog()) { dialog.SetAllowedSymbols(grammar.Symbols.Where(s => !(s is ProgramRootSymbol || s is StartSymbol || s is Defun || s is GroupSymbol))); // allow everything dialog.ShowDialog(this); if (dialog.DialogResult != DialogResult.OK) return; var symbol = dialog.SelectedSymbol(); var node = symbol.CreateTreeNode(); if (node is ConstantTreeNode) { var constant = node as ConstantTreeNode; constant.Value = double.Parse(dialog.constantValueTextBox.Text); } else if (node is VariableTreeNode) { var variable = node as VariableTreeNode; variable.Weight = double.Parse(dialog.variableWeightTextBox.Text); variable.VariableName = dialog.variableNamesCombo.Text; } else if (node.Symbol.MinimumArity <= parent.SubtreeCount && node.Symbol.MaximumArity >= parent.SubtreeCount) { for (int i = parent.SubtreeCount - 1; i >= 0; --i) { var child = parent.GetSubtree(i); parent.RemoveSubtree(i); node.AddSubtree(child); } } // the if condition will always be true for the final else clause above if (parent.Symbol.MaximumArity > parent.SubtreeCount) { ModifyTree(Tree, parent, null, node); } } currSelected = null; }
private void changeNodeToolStripMenuItem_Click(object sender, EventArgs e) { if (currSelected == null) return; var node = (ISymbolicExpressionTreeNode)currSelected.Content.Clone(); var originalNode = currSelected.Content; ISymbolicExpressionTreeNode newNode = null; var result = DialogResult.Cancel; if (node is ConstantTreeNode) { using (var dialog = new ConstantNodeEditDialog(node)) { dialog.ShowDialog(this); newNode = dialog.NewNode; result = dialog.DialogResult; } } else if (node is VariableTreeNode) { using (var dialog = new VariableNodeEditDialog(node)) { dialog.ShowDialog(this); newNode = dialog.NewNode; result = dialog.DialogResult; } } if (result != DialogResult.OK) return; ModifyTree(Tree, originalNode.Parent, originalNode, newNode); // this will replace the original node with the new node currSelected = null; }
private void SymbolicExpressionTreeChart_MouseDown(object sender, MouseEventArgs e) { this.dragButtons = e.Button; this.draggedSymbolicExpressionTree = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y); }
protected override void OnSymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) { currSelected = null; base.OnSymbolicExpressionTreeNodeDoubleClicked(sender, e); }
void SetTree(string depth, double [] probs, VisualTreeNode node) { if(!depth.Equals("")) { int nextNode = Int32.Parse(depth[depth.Length - 1].ToString()); GameObject children = node.children; if(children != null && !children.activeInHierarchy) { node.probs.SetActive(false); children.SetActive(true); } SetTree(depth.Substring(0, depth.Length - 1), probs, node.children.transform.GetChild(nextNode).GetComponent<VisualTreeNode>()); } else { Transform probsT = node.probs.transform; probsT.GetChild(0).GetComponent<InputField>().text = (probs[0]).ToString(); probsT.GetChild(1).GetComponent<InputField>().text = (probs[1]).ToString(); probsT.GetChild(2).GetComponent<InputField>().text = (1 - probs[0] - probs[1]).ToString(); } }
private void pasteToolStripMenuItem_Clicked(object sender, EventArgs e) { if (!(lastOp == EditOp.CopySubtree || lastOp == EditOp.CutSubtree)) return; // check if the copied/cut node (stored in the tempNode) can be inserted as a child of the current selected node var node = currSelected.Content; if (node is ConstantTreeNode || node is VariableTreeNode) return; // check if the currently selected node can accept the copied node as a child // no need to check the grammar, an arity check will do just fine here if (node.Symbol.MaximumArity <= node.SubtreeCount) return; switch (lastOp) { case EditOp.CutSubtree: { if (tempNode.IterateNodesBreadth().Contains(node)) throw new ArgumentException();// cannot cut/paste a node into itself ModifyTree(Tree, tempNode.Parent, tempNode, null); //remove node from its original parent ModifyTree(Tree, node, null, tempNode); //insert it as a child to the new parent break; } case EditOp.CopySubtree: { var clone = (SymbolicExpressionTreeNode)tempNode.Clone(); ModifyTree(Tree, node, null, clone); break; } } currSelected = null; // because the tree will have changed tempNode = null; // clear the clipboard after one paste }
private void removeSubtreeToolStripMenuItem_Click(object sender, EventArgs e) { var node = currSelected.Content; if (node.IterateNodesPostfix().Contains(tempNode)) tempNode = null; ModifyTree(Tree, node.Parent, node, null, removeSubtree: true); currSelected = null; // because the currently selected node was just deleted contextMenuStrip.Close(); // avoid display of submenus since the action has already been performed }
private void removeNodeToolStripMenuItem_Click(object sender, EventArgs e) { var node = currSelected.Content; if (node == tempNode) tempNode = null; ModifyTree(Tree, node.Parent, node, null, removeSubtree: false); currSelected = null; // because the currently selected node was just deleted }
protected virtual string FormatNodeDescription(VisualTreeNode node) => node.Description.Format(node.Context, Data);
protected override void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) { currSelected = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender; ; base.OnSymbolicExpressionTreeNodeClicked(sender, e); }
private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e) { VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y); if (draggedSymbolicExpressionTree != null && draggedSymbolicExpressionTree != visualTreeNode) { OnSymbolicExpressionTreeNodeDragDrag(draggedSymbolicExpressionTree, new ItemDragEventArgs(dragButtons, draggedSymbolicExpressionTree)); draggedSymbolicExpressionTree = null; } else if (draggedSymbolicExpressionTree == null && visualTreeNode != null) { string tooltipText = visualTreeNode.ToolTip; if (this.toolTip.GetToolTip(this) != tooltipText) this.toolTip.SetToolTip(this, tooltipText); } else if (visualTreeNode == null) this.toolTip.SetToolTip(this, ""); }
private void SymbolicExpressionTreeChart_MouseUp(object sender, MouseEventArgs e) { this.draggedSymbolicExpressionTree = null; this.dragButtons = MouseButtons.None; }