-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathFormReference.cs
204 lines (169 loc) · 7.49 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
// 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();
}
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, false))
{
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
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)
{
}
}
}