forked from DongwanCho/IfcDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormReference.cs
326 lines (273 loc) · 13.2 KB
/
FormReference.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// Name: FormReference.cs
// Description: Dialog for building an IfcReference
// Author: Tim Chipman
// Origination: Work performed for BuildingSmart by Constructivity.com LLC.
// Copyright: (c) 2013 BuildingSmart International Ltd.
// License: http://www.buildingsmart-tech.org/legal
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IfcDoc.Schema.DOC;
namespace IfcDoc
{
public partial class FormReference : Form
{
DocProject m_project;
DocDefinition m_base;
Dictionary<string, DocObject> m_map;
public FormReference()
{
InitializeComponent();
}
public FormReference(DocProject docProject, DocDefinition docBase, Dictionary<string, DocObject> map, string value)
: this()
{
this.m_project = docProject;
this.m_base = docBase;
this.m_map = map;
// parse value
CvtValuePath valuepath = CvtValuePath.Parse(value, map);
LoadValuePath(valuepath);
}
public string ValuePath
{
get
{
return this.textBoxReference.Text;
}
}
private void LoadValuePath(CvtValuePath valuepath)
{
this.textBoxReference.Text = String.Empty;
this.listViewReference.Items.Clear();
if (valuepath != null)
{
this.textBoxReference.Text = valuepath.ToString();
}
else
{
this.textBoxReference.Text = String.Empty;
}
while (valuepath != null)
{
ListViewItem lvi = new ListViewItem();
lvi.Tag = valuepath;
if (valuepath.Type != null)
{
lvi.Text = valuepath.Type.Name;
}
if (valuepath.Property != null)
{
lvi.SubItems.Add(valuepath.Property.Name);
if (valuepath.Identifier != null)
{
lvi.SubItems.Add(valuepath.Identifier);
}
}
this.listViewReference.Items.Add(lvi);
valuepath = valuepath.InnerPath;
}
}
private void buttonInsert_Click(object sender, EventArgs e)
{
DocDefinition docBase = this.m_base;
DocDefinition docDefinition = null;
// for now, clear it -- future: allow incremental replacement
CvtValuePath valuepathouter = null;
CvtValuePath valuepathinner = null;
// keep building
while (docBase != null)
{
using (FormSelectEntity formEntity = new FormSelectEntity(docBase, docDefinition, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
{
if (formEntity.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && formEntity.SelectedEntity != null)
{
CvtValuePath valuepath = null;
if (formEntity.SelectedEntity is DocEntity)
{
using (FormSelectAttribute formAttribute = new FormSelectAttribute((DocEntity)formEntity.SelectedEntity, this.m_project, null, false))
{
if (formAttribute.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && formAttribute.SelectedAttribute != null)
{
string item = null;
switch (formAttribute.SelectedAttribute.GetAggregation())
{
case DocAggregationEnum.SET:
// if set collection, then qualify by name
// future: more intelligent UI for picking property sets, properties
using (FormSelectItem formItem = new FormSelectItem())
{
if (formItem.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
item = formItem.Item;
}
}
break;
case DocAggregationEnum.LIST:
// if list collection, then qualify by index
// future: more intelligent UI for picking list indices
using (FormSelectItem formItem = new FormSelectItem())
{
if (formItem.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
item = formItem.Item;
}
}
break;
}
// now add entry to listview
valuepath = new CvtValuePath(formEntity.SelectedEntity, formAttribute.SelectedAttribute, item, null);
if (valuepathinner != null)
{
valuepathinner.InnerPath = valuepath;
}
valuepathinner = valuepath;
if (valuepathouter == null)
{
valuepathouter = valuepath;
}
// drill in
if (this.m_map.ContainsKey(formAttribute.SelectedAttribute.DefinedType))
{
docBase = this.m_map[formAttribute.SelectedAttribute.DefinedType] as DocDefinition;
}
}
else
{
break;
}
}
}
else if (formEntity.SelectedEntity is DocType)
{
valuepath = new CvtValuePath(formEntity.SelectedEntity, null, null, null);
if (valuepathinner != null)
{
valuepathinner.InnerPath = valuepath;
}
valuepathinner = valuepath;
if (valuepathouter == null)
{
valuepathouter = valuepath;
}
docBase = null;
}
}
else
{
break;
}
}
}
this.LoadValuePath(valuepathouter);
}
private void buttonRemove_Click(object sender, EventArgs e)
{
this.LoadValuePath(null);
}
private void listViewReference_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void buttonProperty_Click(object sender, EventArgs e)
{
using(FormSelectProperty form = new FormSelectProperty(this.m_base as DocEntity, this.m_project, false))
{
if(form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
string portprefix = String.Empty;
if (form.SelectedPort != null)
{
portprefix = @".IsNestedBy[]\IfcRelNests.RelatedObjects['" + form.SelectedPort + @"']\IfcDistributionPort";
}
string value = @"\" + this.m_base.Name + portprefix;
if (form.SelectedProperty != null)
{
string valueprop = "NominalValue";
string datatype = form.SelectedProperty.PrimaryDataType;
switch (form.SelectedProperty.PropertyType)
{
case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
if(form.SelectedQualifier != null)
{
valueprop = form.SelectedQualifier;
}
else
{
valueprop = "SetPointValue";
}
break;
case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
valueprop = "EnumerationValues";
break;
case DocPropertyTemplateTypeEnum.P_LISTVALUE:
valueprop = "ListValues";
break;
case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE:
valueprop = "PropertyReference";
datatype = "IfcIrregularTimeSeries.Values[]\\" + form.SelectedProperty.SecondaryDataType;
break;
// other property types are not supported
}
value += @".IsDefinedBy['" + form.SelectedPropertySet +
@"']\IfcRelDefinesByProperties.RelatingPropertyDefinition\IfcPropertySet.HasProperties['" + form.SelectedProperty +
@"']\" + form.SelectedProperty.GetEntityName() + @"." + valueprop + @"\" + datatype;
// special cases
if (this.m_base.Name.Equals("IfcMaterial"))
{
value =
@"\IfcMaterial.HasProperties['" + form.SelectedPropertySet +
@"']\IfcMaterialProperties.Properties['" + form.SelectedProperty +
@"']\" + form.SelectedProperty.GetEntityName() + @"." + valueprop + @"\" + datatype;
}
}
else
{
value += @".GlobalId\IfcGloballyUniqueId";
}
CvtValuePath valuepath = CvtValuePath.Parse(value, this.m_map);
LoadValuePath(valuepath);
}
}
}
private void buttonQuantity_Click(object sender, EventArgs e)
{
using (FormSelectQuantity form = new FormSelectQuantity(this.m_base as DocEntity, this.m_project, false))
{
if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
string suffix = null;
switch (form.SelectedQuantity.QuantityType)
{
case DocQuantityTemplateTypeEnum.Q_AREA:
suffix = @"IfcQuantityArea.AreaValue\IfcAreaMeasure";
break;
case DocQuantityTemplateTypeEnum.Q_COUNT:
suffix = @"IfcQuantityCount.CountValue\IfcInteger";
break;
case DocQuantityTemplateTypeEnum.Q_LENGTH:
suffix = @"IfcQuantityLength.LengthValue\IfcLengthMeasure";
break;
case DocQuantityTemplateTypeEnum.Q_TIME:
suffix = @"IfcQuantityTime.TimeValue\IfcTimeMeasure";
break;
case DocQuantityTemplateTypeEnum.Q_VOLUME:
suffix = @"IfcQuantityVolume.VolumeValue\IfcVolumeMeasure";
break;
case DocQuantityTemplateTypeEnum.Q_WEIGHT:
suffix = @"IfcQuantityWeight.WeightValue\IfcWeightMeasure";
break;
}
string value = @"\" + this.m_base.Name + @".IsDefinedBy['" + form.SelectedQuantitySet +
@"']\IfcRelDefinesByProperties.RelatingPropertyDefinition\IfcElementQuantity.Quantities['" + form.SelectedQuantity +
@"']\" + suffix;
CvtValuePath valuepath = CvtValuePath.Parse(value, this.m_map);
LoadValuePath(valuepath);
}
}
}
}
}