/// <summary> /// Handles Visject CM item click event by spawning the selected item. /// </summary> /// <param name="visjectCmItem">The item.</param> /// <param name="selectedBox">The selected box.</param> protected virtual void OnPrimaryMenuButtonClick(VisjectCMItem visjectCmItem, Box selectedBox) { var node = Context.SpawnNode( visjectCmItem.GroupArchetype, visjectCmItem.NodeArchetype, _rootControl.PointFromParent(ref _cmStartPos), visjectCmItem.Data ); if (node == null) { return; } // If the user entered a comment if (node is SurfaceComment surfaceComment && HasNodesSelection) { // Note how the user input exactly mimics the other comment creation way. This is very much desired. // Select node --> Type // --> Type the comment text --> Hit Enter string title = surfaceComment.Title; Delete(node); CommentSelection(title); return; } // Auto select new node Select(node); if (selectedBox != null) { Box endBox = null; foreach (var box in node.GetBoxes().Where(box => box.IsOutput != selectedBox.IsOutput)) { if ((selectedBox.CurrentType & box.CurrentType) != 0) { endBox = box; break; } if (endBox == null && selectedBox.CanUseType(box.CurrentType)) { endBox = box; } } TryConnect(selectedBox, endBox); } }
private void OnPrimaryMenuButtonClick(VisjectCMItem visjectCmItem) { var node = SpawnNode( visjectCmItem.GroupArchetype, visjectCmItem.NodeArchetype, _surface.PointFromParent(_cmStartPos), visjectCmItem.Data ); // And, if the user is patiently waiting for his box to get connected to the newly created one // fulfill his wish! #MagicLamp? #Genie? if (_startBox != null) { Box alternativeBox = null; foreach (var box in node.GetBoxes().Where(box => box.IsOutput != _startBox.IsOutput)) { if ((_startBox.CurrentType & box.CurrentType) != 0) { ConnectingEnd(box); return; } if (alternativeBox == null && _startBox.CanUseType(box.CurrentType)) { alternativeBox = box; } } if (alternativeBox != null) { ConnectingEnd(alternativeBox); } else { ConnectingEnd(null); } } // Disable intelligent connecting for now /* * var toBeDeselected = new System.Collections.Generic.List<SurfaceNode>(); * * using (var outputBoxes = Selection * .OrderBy(n => n.Top) * .SelectMany(n => n.GetBoxes()) * .Where(b => b.IsOutput && !b.HasAnyConnection) * .GetEnumerator()) * { * // For each input box (I'm assuming that they are sorted properly) * foreach (var inputBox in node.GetBoxes().Where(box => !box.IsOutput)) * { * Box connectWith = null; * * // Find the next decent output box and connect them * while (connectWith == null && outputBoxes.MoveNext()) * { * var outputBox = outputBoxes.Current; * bool connectAnyways = true; * * // Can I rely on the box indices? * // If it's a constant node, it needs some special handling (either connect the first box or the other ones, never both) * if (outputBox.ParentNode.GroupArchetype.Name == "Constants") * { * // Don't always connect this sort of box * connectAnyways = false; * * // If it's the first box, everything is fine? * if (outputBox.ID == 0) * { * // Everything is fine * // If this one doesn't have any alternatives, I can just connect it regardless of the consequences * if (outputBox.ParentNode.Elements.Count(e => e is Box) <= 1) * { * connectAnyways = true; * } * } * // It's an alternative box * else * { * // The first one is already connected => skip this one! * if (outputBox.ParentNode.GetBox(0).HasAnyConnection) * { * continue; * } * else * { * // It's an actual alternative * } * } * } * * // If they can easily be connected, just do it ✔ * if ((inputBox.CurrentType & outputBox.CurrentType) != 0) * { * connectWith = outputBox; * } * else if (connectAnyways && inputBox.CanUseType(outputBox.CurrentType)) * { * connectWith = outputBox; * } * } * if (connectWith != null) * { * // Connect them * connectWith.CreateConnection(inputBox); * toBeDeselected.Add(connectWith.ParentNode); * } * } * } * * foreach (var toDeselect in toBeDeselected) * { * Deselect(toDeselect); * } * * AddToSelection(node); */ }
private void OnPrimaryMenuButtonClick(VisjectCMItem visjectCmItem) { SpawnNode(visjectCmItem.GroupArchetype, visjectCmItem.NodeArchetype, _surface.PointFromParent(_cmStartPos)); }
private void OnPrimaryMenuButtonClick(VisjectCMItem visjectCmItem) { var node = SpawnNode(visjectCmItem.GroupArchetype, visjectCmItem.NodeArchetype, _surface.PointFromParent(_cmStartPos)); var toBeDeselected = new System.Collections.Generic.List <SurfaceNode>(); using (var outputBoxes = Selection .OrderBy(n => n.Top) .SelectMany(n => n.GetBoxes()) .Where(b => b.IsOutput && !b.HasAnyConnection) .GetEnumerator()) { // For each input box (I'm assuming that they are sorted properly) foreach (var inputBox in node.GetBoxes().Where(box => !box.IsOutput)) { Box connectWith = null; // Find the next decent output box and connect them while (connectWith == null && outputBoxes.MoveNext()) { var outputBox = outputBoxes.Current; bool connectAnyways = true; // Can I rely on the box indices? // If it's a constant node, it needs some special handling (either connect the first box or the other ones, never both) if (outputBox.ParentNode.GroupArchetype.Name == "Constants") { // Don't always connect this sort of box connectAnyways = false; // If it's the first box, everything is fine? if (outputBox.ID == 0) { // Everything is fine // If this one doesn't have any alternatives, I can just connect it regardless of the consequences if (outputBox.ParentNode.Elements.Count(e => e is Box) <= 1) { connectAnyways = true; } } // It's an alternative box else { // The first one is already connected => skip this one! if (outputBox.ParentNode.GetBox(0).HasAnyConnection) { continue; } else { // It's an actual alternative } } } // If they can easily be connected, just do it ✔ if ((inputBox.CurrentType & outputBox.CurrentType) != 0) { connectWith = outputBox; } else if (connectAnyways && inputBox.CanUseType(outputBox.CurrentType)) { connectWith = outputBox; } } if (connectWith != null) { // Connect them connectWith.CreateConnection(inputBox); toBeDeselected.Add(connectWith.ParentNode); } } } foreach (var toDeselect in toBeDeselected) { Deselect(toDeselect); } AddToSelection(node); }