-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathCeiling.cs
More file actions
190 lines (156 loc) · 5.81 KB
/
Ceiling.cs
File metadata and controls
190 lines (156 loc) · 5.81 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using Autodesk.DesignScript.Geometry;
using Autodesk.DesignScript.Runtime;
using Autodesk.Revit.DB;
using Revit.GeometryConversion;
using RevitServices.Persistence;
using RevitServices.Transactions;
using Curve = Autodesk.DesignScript.Geometry.Curve;
namespace Revit.Elements
{
/// <summary>
/// A Revit Ceiling
/// </summary>
public class Ceiling : Element
{
#region Internal properties
/// <summary>
/// An internal handle on the Revit ceiling
/// </summary>
internal Autodesk.Revit.DB.Ceiling InternalCeiling
{
get; private set;
}
/// <summary>
/// Reference to the Element
/// </summary>
[SupressImportIntoVM]
public override Autodesk.Revit.DB.Element InternalElement
{
get { return InternalCeiling; }
}
#endregion
#region Private constructors
/// <summary>
/// Private constructor
/// </summary>
private Ceiling(Autodesk.Revit.DB.Ceiling ceiling)
{
SafeInit(() => InitCeiling(ceiling), true);
}
/// <summary>
/// Private constructor
/// </summary>
private Ceiling(List<CurveLoop> profiles, Autodesk.Revit.DB.CeilingType ceilingType, Autodesk.Revit.DB.Level level)
{
SafeInit(() => InitCeiling(profiles, ceilingType, level));
}
#endregion
#region Helpers for private constructors
/// <summary>
/// Initialize a ceiling element
/// </summary>
private void InitCeiling(Autodesk.Revit.DB.Ceiling ceiling)
{
InternalSetCeiling(ceiling);
}
/// <summary>
/// Initialize a ceiling element
/// </summary>
private void InitCeiling(List<CurveLoop> profiles, Autodesk.Revit.DB.CeilingType ceilingType, Autodesk.Revit.DB.Level level)
{
TransactionManager.Instance.EnsureInTransaction(Document);
// we assume the ceiling is not structural here, this may be a bad assumption
Autodesk.Revit.DB.Ceiling ceiling = Autodesk.Revit.DB.Ceiling.Create(Document, profiles, ceilingType.Id, level.Id);
InternalSetCeiling(ceiling);
TransactionManager.Instance.TransactionTaskDone();
ElementBinder.CleanupAndSetElementForTrace(Document, InternalCeiling);
}
#endregion
#region Private mutators
/// <summary>
/// Set the InternalCeiling property and the associated element id and unique id
/// </summary>
/// <param name="ceiling"></param>
private void InternalSetCeiling(Autodesk.Revit.DB.Ceiling ceiling)
{
InternalCeiling = ceiling;
InternalElementId = ceiling.Id;
InternalUniqueId = ceiling.UniqueId;
}
#endregion
#region Public static constructors
/// <summary>
/// Create a Revit Ceiling given its curve outline and Level
/// </summary>
/// <param name="outlineCurves"></param>
/// <param name="ceilingType"></param>
/// <param name="level"></param>
/// <returns>The ceiling</returns>
public static Ceiling ByOutlineTypeAndLevel(Curve[] outlineCurves, CeilingType ceilingType, Level level)
{
if (outlineCurves == null)
{
throw new ArgumentNullException("outlineCurves");
}
var ceiling = ByOutlineTypeAndLevel(PolyCurve.ByJoinedCurves(outlineCurves), ceilingType, level);
if (!TransactionManager.Instance.DisableTransactions)
DocumentManager.Regenerate();
return ceiling;
}
/// <summary>
/// Create a Revit Ceiling given its curve outline and Level
/// </summary>
/// <param name="outline"></param>
/// <param name="ceilingType"></param>
/// <param name="level"></param>
/// <returns>The ceiling</returns>
public static Ceiling ByOutlineTypeAndLevel(PolyCurve outline, CeilingType ceilingType, Level level)
{
if (outline == null)
{
throw new ArgumentNullException("outline");
}
if (ceilingType == null)
{
throw new ArgumentNullException("ceilingType");
}
if (level == null)
{
throw new ArgumentNullException("level");
}
if (!outline.IsClosed)
{
throw new ArgumentException(Properties.Resources.OpenInputPolyCurveError);
}
CurveLoop loop = new CurveLoop();
outline.Curves().ForEach(x => loop.Append(x.ToRevitType()));
List<CurveLoop> loops = new List<CurveLoop> { loop };
if (!BoundaryValidation.IsValidHorizontalBoundary(loops))
{
throw new ArgumentException(Properties.Resources.NotHorizontalInputPolyCurveError);
}
var ceiling = new Ceiling(loops, ceilingType.InternalCeilingType, level.InternalLevel);
if (!TransactionManager.Instance.DisableTransactions)
DocumentManager.Regenerate();
return ceiling;
}
#endregion
#region Internal static constructors
/// <summary>
/// Create a Ceiling from a user selected Element.
/// </summary>
/// <param name="ceiling"></param>
/// <param name="isRevitOwned"></param>
/// <returns></returns>
internal static Ceiling FromExisting(Autodesk.Revit.DB.Ceiling ceiling, bool isRevitOwned)
{
return new Ceiling(ceiling)
{
IsRevitOwned = isRevitOwned
};
}
#endregion
}
}