-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaterialBuilder.cs
131 lines (121 loc) · 5.18 KB
/
MaterialBuilder.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
using System.Collections.Generic;
namespace WallSectionWidget
{
public class MaterialBuilder : GH_Component
{
/// <summary>
/// Initializes a new instance of the MaterialBuilder class.
/// </summary>
public MaterialBuilder()
: base("MaterialBuilder", "MB",
"Material builder for wall section widget",
"WallSectionWidget", "Specifications")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "N", "Name for this material", GH_ParamAccess.item);
pManager.AddNumberParameter("Conductivity", "C", "Thermal conductivity (W/mK)", GH_ParamAccess.item);
pManager.AddNumberParameter("Vapour resistance", "VR", "Water vapour diffusion resistance factor over ordinary air", GH_ParamAccess.item);
pManager.AddNumberParameter("Density", "D", "Density (kg/m3)", GH_ParamAccess.item);
pManager.AddNumberParameter("HeatCapacity", "HC", "Specific heat capacity (J/kgK)", GH_ParamAccess.item);
pManager.AddColourParameter("DisplayColour", "DC", "Colour for display in visualisers", GH_ParamAccess.item);
pManager[3].Optional = true;
pManager[4].Optional = true;
pManager[5].Optional = true;
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("WSWMaterial", "Mat", "WSW Material definition", GH_ParamAccess.item);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
string name = default;
double conductivity = Material.Lamination.Conductivity;
double vapourResistivity = Material.Lamination.VapourResistivity;
double density = Material.Lamination.Density;
double heatCapacity = Material.Lamination.HeatCapacity;
System.Drawing.Color color = System.Drawing.Color.DarkGray;
if (!DA.GetData(0, ref name))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Missing input: material name");
return;
}
if (!DA.GetData(1, ref conductivity))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Missing input: material thermal conductivity");
return;
}
if (!DA.GetData(2, ref vapourResistivity))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Missing input: material vapour resistance");
return;
}
DA.GetData(3, ref density);
DA.GetData(4, ref heatCapacity);
DA.GetData(5, ref color);
if (conductivity <= 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: thermal conductivity should be bigger than zero");
return;
}
if (vapourResistivity <= 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: vapour resistance should be bigger than zero");
return;
}
if (density <= 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: density should be bigger than zero");
return;
}
if (heatCapacity <= 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: heat capacity should be bigger than zero");
return;
}
Material material = new Material
{
Name = name,
Conductivity = conductivity,
VapourResistivity = vapourResistivity,
Density = density,
HeatCapacity = heatCapacity,
VisualiserSetting = new MaterialVisualiserSetting() { Color = color },
};
DA.SetData(0, material.GHIOParam);
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return Properties.Resources.MaterialBuilder.ToBitmap();
}
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("21b7cd4a-4d74-49af-b0ca-bbc49ae99b3e"); }
}
}
}