-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDiffModels.xaml.cs
230 lines (210 loc) · 9.03 KB
/
DiffModels.xaml.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
//
// BIMRL (BIM Rule Language) Simplified Schema ETL (Extract, Transform, Load) library: this library transforms IFC data into BIMRL Simplified Schema for RDBMS.
// This work is part of the original author's Ph.D. thesis work on the automated rule checking in Georgia Institute of Technology
// Copyright (C) 2013 Wawan Solihin ([email protected])
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; If not, see <http://www.gnu.org/licenses/>.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.IO;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
//using System.Windows.Shapes;
using Microsoft.Win32;
using BIMRL;
using BIMRL.Common;
using Oracle.DataAccess.Client;
namespace DiffModelsUI
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class DiffModels : Window
{
BIMRLCommon BIMRLCommonRef = new BIMRLCommon();
int modelIDNew = -1;
int modelIDRef = -1;
string outputFileName = "";
public DiffModels()
{
InitializeComponent();
DBOperation.refBIMRLCommon = BIMRLCommonRef; // important to ensure DBoperation has reference to this object!!
try
{
DBOperation.ExistingOrDefaultConnection();
}
catch
{
if (DBOperation.UIMode)
{
BIMRLErrorDialog erroDlg = new BIMRLErrorDialog(BIMRLCommonRef);
erroDlg.ShowDialog();
}
else
Console.Write(BIMRLCommonRef.ErrorMessages);
return;
}
BIMRLQueryModel qModel = new BIMRLQueryModel(BIMRLCommonRef);
IList<FederatedModelInfo> fedModels = qModel.getFederatedModels();
dataGrid_ModelList.AutoGenerateColumns = true;
dataGrid_ModelList.IsReadOnly = true;
dataGrid_ModelList.ItemsSource = fedModels;
dataGrid_ModelList.MinRowHeight = 20;
button_1stModel.IsEnabled = false;
button_2ndModel.IsEnabled = false;
button_Run.IsEnabled = false;
}
private void button_1stModel_Click(object sender, RoutedEventArgs e)
{
FederatedModelInfo selFedModelsItem = dataGrid_ModelList.SelectedItem as FederatedModelInfo;
if (selFedModelsItem == null)
return; // do nothing, no selection made
else
{
FederatedModelInfo selModel = selFedModelsItem;
if (modelIDRef >= 0 && modelIDRef == selModel.FederatedID)
return; // Can't select the same model to compare
textBox_1stModel.Text = "(ID: " + selModel.FederatedID.ToString() + ") " + selModel.ModelName + "; " + selModel.ProjectNumber + "; " + selModel.ProjectName;
modelIDNew = selModel.FederatedID;
}
//if (!string.IsNullOrEmpty(textBox_2ndModel.Text))
// button_Run.IsEnabled = true;
}
private void button_2ndModel_Click(object sender, RoutedEventArgs e)
{
FederatedModelInfo selFedModelsItem = dataGrid_ModelList.SelectedItem as FederatedModelInfo;
if (selFedModelsItem == null)
return; // do nothing, no selection made
else
{
FederatedModelInfo selModel = selFedModelsItem;
if (modelIDNew >= 0 && modelIDNew == selModel.FederatedID)
return; // Can't select the same model to compare
textBox_2ndModel.Text = "(ID: " + selModel.FederatedID.ToString() + ") " + selModel.ModelName + "; " + selModel.ProjectNumber + "; " + selModel.ProjectName;
modelIDRef = selModel.FederatedID;
}
//if (!string.IsNullOrEmpty(textBox_2ndModel.Text))
// button_Run.IsEnabled = true;
}
private void button_Run_Click(object sender, RoutedEventArgs e)
{
BIMRLDiffOptions options = new BIMRLDiffOptions();
options.CheckNewAndDeletedObjects = checkBox_NewDelObjects.IsChecked.Value;
options.CheckGeometriesDiffBySignature = checkBox_CheckGeometryBySignature.IsChecked.Value;
double tol;
if (double.TryParse(textBox_Tolerance.Text, out tol))
options.GeometryCompareTolerance = tol;
options.CheckTypeAndTypeAssignments = checkBox_CheckTypeAssignments.IsChecked.Value;
options.CheckContainmentRelationships = checkBox_CheckContainmentRelations.IsChecked.Value;
options.CheckOwnerHistory = checkBox_CheckOwnerHistory.IsChecked.Value;
options.CheckProperties = checkBox_CheckProperties.IsChecked.Value;
options.CheckMaterials = checkBox_CheckMaterials.IsChecked.Value;
options.CheckClassificationAssignments = checkBox_Classifications.IsChecked.Value;
options.CheckGroupMemberships = checkBox_CheckGroupMemberships.IsChecked.Value;
options.CheckAggregations = checkBox_CheckAggregations.IsChecked.Value;
options.CheckConnections = checkBox_CheckConnections.IsChecked.Value;
options.CheckElementDependencies = checkBox_CheckElementDependencies.IsChecked.Value;
options.CheckSpaceBoundaries = checkBox_CheckSpaceBoundaries.IsChecked.Value;
string userName = textBox_Username.Text;
string pwd = textBox_Password.Text;
string dbconnect = textBox_DBConnect.Text;
try
{
DBOperation.ConnectToDB(userName, pwd, dbconnect);
BIMRLDiffModels diffModels = new BIMRLDiffModels(modelIDNew, modelIDRef, BIMRLCommonRef);
diffModels.RunDiff(outputFileName, options: options);
}
catch (Exception ex)
{
textBox_Message.Text = ex.Message + "\n" + BIMRLCommonRef.ErrorMessages;
}
}
private void button_Cancel_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void dataGrid_ModelList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
FederatedModelInfo selFedModelsItem = dataGrid_ModelList.SelectedItem as FederatedModelInfo;
if (selFedModelsItem == null)
return; // do nothing, no selection made
else
{
button_1stModel.IsEnabled = true;
button_2ndModel.IsEnabled = true;
}
}
private void button_Browse_Click(object sender, RoutedEventArgs e)
{
var dlg = new OpenFileDialog
{
Title = "Select output Json file name.",
Filter = "Json output|*.json", // Filter files by extension
CheckFileExists = false,
Multiselect = false
};
var done = dlg.ShowDialog(this);
if (!done.Value)
return;
if (!dlg.FileName.Any())
{
if (string.IsNullOrEmpty(textBox_OutputJson.Text))
{
outputFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "diffOutput.json";
}
else
outputFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + textBox_OutputJson.Text;
}
else
outputFileName = dlg.FileName;
textBox_OutputJson.Text = outputFileName;
if (!string.IsNullOrEmpty(outputFileName))
button_Run.IsEnabled = true;
}
private void textBox_OutputJson_LostFocus(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(textBox_OutputJson.Text))
{
outputFileName = textBox_OutputJson.Text;
try
{
FileStream oFile = File.Create(outputFileName);
oFile.Close();
File.Delete(outputFileName);
textBox_Message.Text = "";
}
catch (Exception excp)
{
textBox_Message.Foreground = Brushes.Red ;
textBox_Message.FontWeight = FontWeights.ExtraBold;
textBox_Message.Text = "ERROR: Output file cannot be created! " + excp.Message;
}
}
}
private void button_Clear_Click(object sender, RoutedEventArgs e)
{
textBox_Message.Text = "";
}
}
}