-
Notifications
You must be signed in to change notification settings - Fork 2
/
ValidateWindowParameter.cs
174 lines (163 loc) · 5.79 KB
/
ValidateWindowParameter.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
174
//
// (C) Copyright 2003-2017 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
namespace Autodesk.Forge.RevitIO.CreateWindow
{
/// <summary>
/// class is used to validate window parameters
/// </summary>
public class ValidateWindowParameter
{
#region Class Memeber Variables
/// <summary>
/// store the wall's height
/// </summary>
private double m_wallHeight=10;
/// <summary>
/// store the wall's width
/// </summary>
private double m_wallWidth=10;
/// <summary>
/// indicate the template file is metric or not
/// </summary>
public bool IsMetric;
#endregion
/// <summary>
/// constructor of ValidateWindowParameter
/// </summary>
/// <param name="wallHeight">wall height parameter</param>
/// <param name="wallWidth">wall width parameter</param>
public ValidateWindowParameter(double wallHeight, double wallWidth)
{
if (wallHeight >= 0)
{
m_wallHeight = wallHeight;
}
if (wallWidth >= 0)
{
m_wallWidth = wallWidth;
}
}
#region Class Implementation
/// <summary>
/// This method is used to check whether a value string is double type
/// </summary>
/// <param name="value">>the string value</param>
/// <param name="result">the double result</param>
/// <returns>the validation result message</returns>
public string IsDouble(string value, ref double result)
{
if (Double.TryParse("0" + value, out result))
{
return string.Empty;
}
else
{
return "Please input a double value.";
}
}
/// <summary>
/// This method is used to check whether the width value is out of range
/// </summary>
/// <param name="value">the string value</param>
/// <returns>the validation result message</returns>
public string IsWidthInRange(double value)
{
if (IsMetric)
{
value = Utility.MetricToImperial(value);
if (value >= 0.23 && value < m_wallWidth)
return string.Empty;
else
return "The width should be between 69 and " + Convert.ToInt32(Utility.ImperialToMetric(m_wallWidth));
}
else
{
if (value >= 0.4 && value < m_wallWidth)
return string.Empty;
else
return "The width should be between 0.4 and " + m_wallWidth;
}
}
/// <summary>
/// This method is used to check whether the height value is out of range
/// </summary>
/// <param name="value">the string value</param>
/// <returns>the validation result message</returns>
public string IsHeightInRange(double value)
{
if (IsMetric)
{
value = Utility.MetricToImperial(value);
if (value >= 0.23)
return string.Empty;
else
return "The height should > 69";
}
else
{
if (value >= 0.4)
return string.Empty;
else
return "The height should > 0.4";
}
}
/// <summary>
/// This method is used to check whether the inset value is out of range
/// </summary>
/// <param name="value">the string value</param>
/// <returns>the validation result message</returns>
public string IsInsetInRange(double value)
{
if (IsMetric)
value = Utility.MetricToImperial(value);
if (value >= 0)
return string.Empty;
else
return "The Inset should > 0";
}
/// <summary>
/// This method is used to check whether the sillheight value is out of range
/// </summary>
/// <param name="value">the string value</param>
/// <returns>the validation result message</returns>
public string IsSillHeightInRange(double value)
{
if (IsMetric)
{
value = Utility.MetricToImperial(value);
if (value < m_wallHeight)
return string.Empty;
else
return "The sillheight should be < " + Convert.ToInt32(Utility.ImperialToMetric(m_wallHeight));
}
else
{
if (value < m_wallHeight)
return string.Empty;
else
return "The sillheight should be < " + m_wallHeight;
}
}
#endregion
}
}