-
Notifications
You must be signed in to change notification settings - Fork 11
/
GeometrySurfaceFrom4Points.cs
57 lines (52 loc) · 2.27 KB
/
GeometrySurfaceFrom4Points.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using Dynamo.Graph.Nodes;
using ProtoCore.AST.AssociativeAST;
using NodeModelsEssentials.Functions;
using Autodesk.DesignScript.Geometry;
using System.Linq;
using Newtonsoft.Json;
namespace NodeModelsEssentials
{
// <summary>
// A simple node to create a surface from four points.
// </summary>
[NodeName("Geometry.SurfaceFrom4Points")]
[NodeDescription("A simple node to create a surface from four points.")]
[NodeCategory("NodeModelsEssentials")]
[InPortNames("point1", "point2", "point3", "point4")]
[InPortTypes(
"Autodesk.DesignScript.Geometry.Point",
"Autodesk.DesignScript.Geometry.Point",
"Autodesk.DesignScript.Geometry.Point",
"Autodesk.DesignScript.Geometry.Point")]
[InPortDescriptions("First point", "Second point", "Third point", "Fourth point")]
[OutPortNames("Surface")]
[OutPortTypes("Autodesk.DesignScript.Geometry.Surface")]
[OutPortDescriptions("A surface defined by four corner points.")]
[IsDesignScriptCompatible]
public class SurfaceFrom4Points : NodeModel
{
[JsonConstructor]
private SurfaceFrom4Points(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
}
public SurfaceFrom4Points()
{
RegisterAllPorts();
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAsNodes)
{
if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any() || !InPorts[2].Connectors.Any() || !InPorts[3].Connectors.Any())
{
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
}
var functionCall =
AstFactory.BuildFunctionCall(
new Func<Point, Point, Point, Point, Surface>(NodeModelsEssentialsFunctions.SurfaceFrom4Points),
new List<AssociativeNode> { inputAsNodes[0], inputAsNodes[1], inputAsNodes[2], inputAsNodes[3] });
// Return an assigment of the generated Ast function call to output node 0
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) };
}
}
}