-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHumidityProfileDisplay.cs
173 lines (153 loc) · 6.67 KB
/
HumidityProfileDisplay.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
using System.Collections.Generic;
using Rhino.Display;
namespace WallSectionWidget
{
public class HumidityProfileDisplay : GH_Component
{
public List<TextEntity> PreviewTexts = new List<TextEntity>();
public Polyline Profile;
/// <summary>
/// Initializes a new instance of the ProfileDisplay class.
/// </summary>
public HumidityProfileDisplay()
: base("HumidityProfileDisplay", "HPFDis",
"Display for a wall section relative humidity profile",
"WallSectionWidget", "Visualisation")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("WSModel", "SM", "WSW Model definition of a solved wall section model", GH_ParamAccess.item);
//pManager.AddGenericParameter("WSLegend", "L", "WSW Legend definition of a legend parameter", GH_ParamAccess.item);
pManager.AddBooleanParameter("LegendOnLeft", "LoL", "True if legend axis should be placed on the left; otherwise on the right", GH_ParamAccess.item);
pManager.AddPlaneParameter("Plane", "Pl", "Plane", GH_ParamAccess.item);
pManager.AddNumberParameter("Height", "H", "Height", GH_ParamAccess.item);
pManager.AddNumberParameter("Scale", "S", "Custom scale factor", GH_ParamAccess.item);
pManager.AddNumberParameter("OverrideLegendMin", "OLMin", "Value used to override the legend minimum", GH_ParamAccess.item);
pManager.AddNumberParameter("OverrideLegendMax", "OLMax", "Value used to override the legend maximum", GH_ParamAccess.item);
pManager.AddBooleanParameter("BakeText", "BkTxt", "Bake texts", GH_ParamAccess.item);
pManager[1].Optional = true;
pManager[2].Optional = true;
pManager[3].Optional = true;
pManager[4].Optional = true;
pManager[5].Optional = true;
pManager[6].Optional = true;
pManager[7].Optional = true;
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddLineParameter("LegendGeometry", "LGeo", "Legend geometry as a list", GH_ParamAccess.list);
pManager.AddCurveParameter("Profile", "PGeo", "Profile as a curve", 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)
{
GHIOParam<Model> modelGHIO = default;
if (!DA.GetData(0, ref modelGHIO))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Missing input: WSWModel definition");
return;
}
Model model;
if (!modelGHIO.GetContent(out model))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: WSWModel input is of wrong type");
return;
}
bool legendOnLeft = true;
DA.GetData(1, ref legendOnLeft);
Plane plane = Plane.WorldXY;
DA.GetData(2, ref plane);
double height = 1.0;
DA.GetData(3, ref height);
if (height <= 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: height should be bigger than zero");
return;
}
double scale = 1.0;
DA.GetData(4, ref scale);
if (scale <= 0)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: scale should be bigger than zero");
return;
}
double overrideLegendMin = 0.0;
double overrideLegendMax = 30.0;
bool overrideLegendMinMax = false;
if (DA.GetData(5, ref overrideLegendMin) && DA.GetData(6, ref overrideLegendMax))
{
overrideLegendMinMax = true;
}
bool bake = false;
DA.GetData(7, ref bake);
List<double> humidity = new List<double>();
model.RelativeHumidityLevels.ForEach(h => humidity.Add(h <= 100 ? h : 100));
ProfileVisualiser vis = new ProfileVisualiser(model.Depths, humidity);
vis.OverrideLegendMinMax = overrideLegendMinMax;
if (overrideLegendMinMax)
{
vis.OverrideLegendMax = overrideLegendMax;
vis.OverrideLegendMin = overrideLegendMin;
}
vis.Plane = plane;
vis.Height = height;
vis.Scale = scale;
if (legendOnLeft)
{
vis.LegendLeft();
} else
{
vis.LegendRight();
}
List<Line> legendGeoCollector = new List<Line>();
legendGeoCollector.AddRange(vis.Legend.Markers);
legendGeoCollector.Add(vis.Legend.Axis);
DA.SetDataList(0, legendGeoCollector);
DA.SetData(1, vis.PolylineProfile().ToNurbsCurve());
Profile = vis.PolylineProfile();
vis.Legend.Title = @"Relative Humidity %";
PreviewTexts.Clear();
PreviewTexts.Add(vis.Legend.TitleTextEntity);
PreviewTexts.AddRange(vis.Legend.AxisLabelTextEntities);
if (bake)
{
PreviewTexts.ForEach(t => Rhino.RhinoDoc.ActiveDoc.Objects.AddText(t));
}
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
return Properties.Resources.HumidityDisplay.ToBitmap();
}
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
PreviewTexts.ForEach(t => args.Display.DrawText(t, System.Drawing.Color.Black));
args.Display.DrawPolyline(Profile, System.Drawing.Color.Blue, 3);
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("4f20743b-e8cb-4b36-88e8-cd44597cd1b4"); }
}
}
}