本文整理汇总了C#中Dynamo.Models.WorkspaceModel.AddNode方法的典型用法代码示例。如果您正苦于以下问题:C# WorkspaceModel.AddNode方法的具体用法?C# WorkspaceModel.AddNode怎么用?C# WorkspaceModel.AddNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dynamo.Models.WorkspaceModel
的用法示例。
在下文中一共展示了WorkspaceModel.AddNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Collapse
//.........这里部分代码省略.........
}
//Connect outputs to new node
outConnectors.AddRange(
from output in outputs
let outputSenderNode = output.Item1
let outputSenderData = output.Item2
let outputReceiverData = output.Item3.Item1
let outputReceiverNode = output.Item3.Item2
select
Tuple.Create(
outputReceiverNode,
outportList.FindIndex(
x => x.Item1 == outputSenderNode && x.Item2 == outputSenderData),
outputReceiverData));
}
else
{
foreach (var hanging in
selectedNodeSet.SelectMany(
node =>
Enumerable.Range(0, node.OutPortData.Count)
.Where(port => !node.HasOutput(port))
.Select(port => new { node, port })).Distinct())
{
//Create Symbol Node
var node = new Output
{
Symbol = hanging.node.OutPortData[hanging.port].NickName,
X = rightMost + 75 - leftShift
};
node.Y = i*(50 + node.Height);
node.SetNickNameFromAttribute();
newNodes.Add(node);
ConnectorModel.Make(hanging.node, node, hanging.port, 0);
i++;
}
}
#endregion
var newId = Guid.NewGuid();
newWorkspace = new CustomNodeWorkspaceModel(
nodeFactory,
newNodes,
Enumerable.Empty<NoteModel>(),
newAnnotations,
Enumerable.Empty<PresetModel>(),
new WorkspaceInfo()
{
X = 0,
Y = 0,
Name = args.Name,
Category = args.Category,
Description = args.Description,
ID = newId.ToString(),
FileName = string.Empty
},
currentWorkspace.ElementResolver);
newWorkspace.HasUnsavedChanges = true;
RegisterCustomNodeWorkspace(newWorkspace);
var collapsedNode = CreateCustomNodeInstance(newId, isTestMode: isTestMode);
collapsedNode.X = avgX;
collapsedNode.Y = avgY;
currentWorkspace.AddNode(collapsedNode, centered: false);
undoRecorder.RecordCreationForUndo(collapsedNode);
foreach (var connector in
inConnectors.Select((x, idx) => new { node = x.Item1, from = x.Item2, to = idx })
.Select(
nodeTuple =>
ConnectorModel.Make(
nodeTuple.node,
collapsedNode,
[email protected],
nodeTuple.to))
.Where(connector => connector != null))
{
undoRecorder.RecordCreationForUndo(connector);
}
foreach (var connector in
outConnectors.Select(
nodeTuple =>
ConnectorModel.Make(
collapsedNode,
nodeTuple.Item1,
nodeTuple.Item2,
nodeTuple.Item3)).Where(connector => connector != null))
{
undoRecorder.RecordCreationForUndo(connector);
}
}
return newWorkspace;
}
示例2: Collapse
/// <summary>
/// Collapse a set of nodes in a given workspace.
/// </summary>
/// <param name="dynamoModel">The current DynamoModel</param>
/// <param name="selectedNodes"> The function definition for the user-defined node </param>
/// <param name="currentWorkspace"> The workspace where</param>
/// <param name="args"></param>
public static void Collapse(DynamoModel dynamoModel, IEnumerable<NodeModel> selectedNodes, WorkspaceModel currentWorkspace, FunctionNamePromptEventArgs args = null)
{
var selectedNodeSet = new HashSet<NodeModel>(selectedNodes);
if (args == null || !args.Success)
{
args = new FunctionNamePromptEventArgs();
dynamoModel.OnRequestsFunctionNamePrompt(null, args);
if (!args.Success)
{
return;
}
}
// Note that undoable actions are only recorded for the "currentWorkspace",
// the nodes which get moved into "newNodeWorkspace" are not recorded for undo,
// even in the new workspace. Their creations will simply be treated as part of
// the opening of that new workspace (i.e. when a user opens a file, she will
// not expect the nodes that show up to be undoable).
//
// After local nodes are moved into "newNodeWorkspace" as the result of
// conversion, if user performs an undo, new set of nodes will be created in
// "currentWorkspace" (not moving those nodes in the "newNodeWorkspace" back
// into "currentWorkspace"). In another word, undo recording is on a per-
// workspace basis, it does not work across different workspaces.
//
UndoRedoRecorder undoRecorder = currentWorkspace.UndoRecorder;
using (undoRecorder.BeginActionGroup())
{
var newNodeWorkspace = new CustomNodeWorkspaceModel(
dynamoModel,
args.Name,
args.Category,
args.Description,
0,
0) { WatchChanges = false, HasUnsavedChanges = true };
var newNodeDefinition = new CustomNodeDefinition(Guid.NewGuid())
{
WorkspaceModel = newNodeWorkspace
};
currentWorkspace.DisableReporting();
#region Determine Inputs and Outputs
//Step 1: determine which nodes will be inputs to the new node
var inputs =
new HashSet<Tuple<NodeModel, int, Tuple<int, NodeModel>>>(
selectedNodeSet.SelectMany(
node =>
Enumerable.Range(0, node.InPortData.Count)
.Where(node.HasConnectedInput)
.Select(data => Tuple.Create(node, data, node.Inputs[data]))
.Where(input => !selectedNodeSet.Contains(input.Item3.Item2))));
var outputs =
new HashSet<Tuple<NodeModel, int, Tuple<int, NodeModel>>>(
selectedNodeSet.SelectMany(
node =>
Enumerable.Range(0, node.OutPortData.Count)
.Where(node.HasOutput)
.SelectMany(
data =>
node.Outputs[data].Where(
output => !selectedNodeSet.Contains(output.Item2))
.Select(output => Tuple.Create(node, data, output)))));
#endregion
#region Detect 1-node holes (higher-order function extraction)
var curriedNodeArgs =
new HashSet<NodeModel>(
inputs.Select(x => x.Item3.Item2)
.Intersect(outputs.Select(x => x.Item3.Item2))).Select(
outerNode =>
{
//var node = new Apply1();
var node = newNodeWorkspace.AddNode<Apply1>();
node.SetNickNameFromAttribute();
node.DisableReporting();
node.X = outerNode.X;
node.Y = outerNode.Y;
//Fetch all input ports
// in order
// that have inputs
//.........这里部分代码省略.........