-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathFormRule.cs
177 lines (150 loc) · 5.66 KB
/
FormRule.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
// Name: FormRule.cs
// Description: Dialog box for editing rule
// Author: Tim Chipman
// Origination: Work performed for BuildingSmart by Constructivity.com LLC.
// Copyright: (c) 2012 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 FormRule : Form
{
DocModelRule m_rule;
public FormRule()
{
InitializeComponent();
}
public FormRule(DocModelRule rule)
: this()
{
this.m_rule = rule;
this.Text = this.m_rule.Name;
this.textBoxIdentifier.Text = this.m_rule.Identification;
this.textBoxIdentifier.Enabled = !String.IsNullOrEmpty(this.m_rule.Identification);
if (String.IsNullOrEmpty(this.m_rule.Identification))
{
this.comboBoxUsage.SelectedIndex = 0;
}
else if (this.m_rule.Description != null && this.m_rule.Description.Equals("*"))
{
// convention indicating filter
this.comboBoxUsage.SelectedIndex = 1;
}
else
{
// indicates parameter constraint
this.comboBoxUsage.SelectedIndex = 2;
}
if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 0)
{
this.comboBoxCardinality.SelectedIndex = 0;
}
else if (this.m_rule.CardinalityMin == -1 && this.m_rule.CardinalityMax == -1)
{
this.comboBoxCardinality.SelectedIndex = 1;
}
else if (this.m_rule.CardinalityMin == 0 && this.m_rule.CardinalityMax == 1)
{
this.comboBoxCardinality.SelectedIndex = 2;
}
else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == 1)
{
this.comboBoxCardinality.SelectedIndex = 3;
}
else if (this.m_rule.CardinalityMin == 1 && this.m_rule.CardinalityMax == -1)
{
this.comboBoxCardinality.SelectedIndex = 4;
}
this.UpdateBehavior();
}
private void textBoxIdentifier_TextChanged(object sender, EventArgs e)
{
this.m_rule.Identification = this.textBoxIdentifier.Text;
}
private void comboBoxCardinality_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBoxCardinality.SelectedIndex)
{
case 0:
this.m_rule.CardinalityMin = 0;
this.m_rule.CardinalityMax = 0; // same as unitialized file
break;
case 1:
this.m_rule.CardinalityMin = -1; // means 0:0
this.m_rule.CardinalityMax = -1;
break;
case 2:
this.m_rule.CardinalityMin = 0;
this.m_rule.CardinalityMax = 1;
break;
case 3:
this.m_rule.CardinalityMin = 1;
this.m_rule.CardinalityMax = 1;
break;
case 4:
this.m_rule.CardinalityMin = 1;
this.m_rule.CardinalityMax = -1;
break;
}
this.UpdateBehavior();
}
private void comboBoxUsage_SelectedIndexChanged(object sender, EventArgs e)
{
this.textBoxIdentifier.Enabled = (this.comboBoxUsage.SelectedIndex > 0);
switch(this.comboBoxUsage.SelectedIndex)
{
case 0:
this.textBoxIdentifier.Text = "";
this.m_rule.Identification = null;
this.m_rule.Description = null;
break;
case 1:
this.m_rule.Description = "*";
break;
case 2:
this.m_rule.Description = null;
break;
}
this.UpdateBehavior();
}
private void UpdateBehavior()
{
switch (this.comboBoxUsage.SelectedIndex)
{
case 0:
this.textBoxBehavior.Text = "";
break;
case 1:
this.textBoxBehavior.Text = "Rules only apply if attribute equals specified value.\r\n";
break;
case 2:
this.textBoxBehavior.Text = "Attribute must equal specified value if rule applies.\r\n";
break;
}
switch (this.comboBoxCardinality.SelectedIndex)
{
case 0: // -
break;
case 1: // [0]
this.textBoxBehavior.Text += "No applicable template items may satisfy all constraints.";
break;
case 2: // [0:1]
this.textBoxBehavior.Text += "Zero or one template items must satisfy all constraints.";
break;
case 3: // [1]
this.textBoxBehavior.Text += "Exactly one applicable template item must satisfy all constraints.";
break;
case 4: // [1:?]
this.textBoxBehavior.Text += "Each applicable template item must satisfy all constraints.";
break;
}
}
}
}