hytos / ID2.Manager / ID2.Manager.Compare / Controls / Verification.cs @ 42d7b127
이력 | 보기 | 이력해설 | 다운로드 (55.1 KB)
1 |
using devDept.Eyeshot; |
---|---|
2 |
using devDept.Eyeshot.Entities; |
3 |
using devDept.Eyeshot.Translators; |
4 |
using devDept.Geometry.Entities; |
5 |
using System; |
6 |
using System.Collections.Generic; |
7 |
using System.ComponentModel; |
8 |
using System.ComponentModel.Design; |
9 |
using System.Data; |
10 |
using System.Drawing; |
11 |
using System.IO; |
12 |
using System.Linq; |
13 |
using System.Runtime.InteropServices; |
14 |
using System.Text; |
15 |
using System.Threading.Tasks; |
16 |
using System.Windows.Forms; |
17 |
using Telerik.WinControls; |
18 |
using Telerik.WinControls.UI; |
19 |
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf; |
20 |
using Telerik.Windows.Documents.Fixed.Model; |
21 |
using Telerik.Windows.Documents.Fixed.Model.Editing; |
22 |
using Xtractor.Viewer; |
23 |
|
24 |
namespace ID2.Manager.Controls |
25 |
{ |
26 |
public partial class Verification : UserControl |
27 |
{ |
28 |
public delegate void CompareComplete(List<TextInfo> list); |
29 |
public CompareComplete OnCompareComplete; |
30 |
|
31 |
readonly string IniFilePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), |
32 |
Application.ProductName, $"{Application.ProductName}.ini"); |
33 |
|
34 |
#region 기본값 |
35 |
private static string AutoCADLayer { get; } = "AutoCAD"; |
36 |
private static string AutoCADDiffLayer { get; } = "AutoCAD_Diff"; |
37 |
private static string AutoCADExceptLayer { get; } = "AutoCAD_Except"; |
38 |
private static Color AutoCADColor = Color.FromArgb(44, 44, 44); |
39 |
private static string AVEVALayer { get; } = "AVEVA"; |
40 |
private static string AVEVADiffLayer { get; } = "AVEVA_Diff"; |
41 |
private static string AVEVAExceptLayer { get; } = "AVEVA_Except"; |
42 |
private static Color AVEVAColor = Color.FromArgb(44, 44, 44); |
43 |
private static string RevCloudLayer { get; } = "RevCloud"; |
44 |
private static Color RevCloudColor = Color.Magenta; |
45 |
private static Color DiffColor = Color.Yellow; |
46 |
|
47 |
private static double Tolerance = 0; |
48 |
private static double LengthToleranceRatio { get; set; } = 0.1; |
49 |
private static bool Casesensitive { get; set; } = false; |
50 |
#endregion |
51 |
|
52 |
private RadProgressBarElement _progressBar = null; |
53 |
|
54 |
public Verification(RadProgressBarElement progressBar) |
55 |
{ |
56 |
InitializeComponent(); |
57 |
|
58 |
this.Load += Verification_Load; |
59 |
this.radSpinEditorTolerance.ValueChanged += RadSpinEditorTolerance_ValueChanged; |
60 |
this.radColorBoxAutoCADColor.ValueChanged += RadColorBoxAutoCADColor_ValueChanged; |
61 |
this.radColorBoxAVEVAColor.ValueChanged += RadColorBoxAVEVAColor_ValueChanged; |
62 |
this.radColorBoxDiffColor.ValueChanged += RadColorBoxDiffColor_ValueChanged; |
63 |
this.radColorBoxRevCloudColor.ValueChanged += RadColorBoxRevCloudColor_ValueChanged; |
64 |
|
65 |
this.designAutoCAD.ActionMode = actionType.SelectVisibleByPickDynamic; |
66 |
this.designAutoCAD.ActiveViewport.CoordinateSystemIcon.Visible = false; |
67 |
this.designAutoCAD.Selection.ColorDynamic = Color.FromArgb(80, Color.OrangeRed); |
68 |
this.designAutoCAD.Selection.HaloInnerColor = Color.FromArgb(255, Color.OrangeRed); |
69 |
this.designAutoCAD.Selection.HaloOuterColor = Color.FromArgb(64, Color.OrangeRed); |
70 |
this.designAutoCAD.Selection.HaloWidthPolygons = 4; |
71 |
this.designAutoCAD.Selection.HaloWidthWires = 2; |
72 |
this.designAutoCAD.ActiveViewport.OriginSymbol.Visible = false; |
73 |
this.designAutoCAD.SetView(viewType.Trimetric); |
74 |
|
75 |
this.designAVEVA.ActionMode = actionType.SelectVisibleByPickDynamic; |
76 |
this.designAVEVA.ActiveViewport.CoordinateSystemIcon.Visible = false; |
77 |
this.designAVEVA.ActiveViewport.OriginSymbol.Visible = false; |
78 |
this.designCompare.ActionMode = actionType.SelectVisibleByPickDynamic; |
79 |
this.designCompare.ActiveViewport.CoordinateSystemIcon.Visible = false; |
80 |
this.designCompare.ActiveViewport.OriginSymbol.Visible = false; |
81 |
|
82 |
this.radCheckedDropDownListAutoCAD.ItemCheckedChanged += RadCheckedDropDownListAutoCAD_ItemCheckedChanged; |
83 |
this.radCheckedDropDownListAVEVA.ItemCheckedChanged += RadCheckedDropDownListAVEVA_ItemCheckedChanged; |
84 |
this.radCheckBoxRevCloud.CheckStateChanged += RadCheckBoxRevCloud_CheckStateChanged; |
85 |
this.radToggleSwitchCasesensitive.ValueChanged += RadToggleSwitchCasesensitive_ValueChanged; |
86 |
|
87 |
_progressBar = progressBar; |
88 |
|
89 |
#region Camera Sync |
90 |
this.designAutoCAD.ActiveViewport.Rotate.Enabled = false; |
91 |
this.designAVEVA.ActiveViewport.Rotate.Enabled = false; |
92 |
this.designCompare.ActiveViewport.Rotate.Enabled = false; |
93 |
|
94 |
this.designAutoCAD.ActiveViewport.ViewCubeIcon.Visible = false; |
95 |
this.designAVEVA.ActiveViewport.ViewCubeIcon.Visible = false; |
96 |
this.designCompare.ActiveViewport.ViewCubeIcon.Visible = false; |
97 |
|
98 |
this.designAutoCAD.AnimateCamera = false; |
99 |
this.designAVEVA.AnimateCamera = false; |
100 |
this.designCompare.AnimateCamera = false; |
101 |
|
102 |
this.designAutoCAD.CameraChangedFrequency = 200; |
103 |
this.designAVEVA.CameraChangedFrequency = 200; |
104 |
this.designCompare.CameraChangedFrequency = 200; |
105 |
|
106 |
this.designAutoCAD.CameraChanged += CameraChanged; |
107 |
this.designAVEVA.CameraChanged += CameraChanged; |
108 |
this.designCompare.CameraChanged += CameraChanged; |
109 |
#endregion |
110 |
} |
111 |
|
112 |
private void RadToggleSwitchCasesensitive_ValueChanged(object sender, EventArgs e) |
113 |
{ |
114 |
bool value = this.radToggleSwitchCasesensitive.Value; |
115 |
Verification.Casesensitive = value; |
116 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "Casesensitive", value.ToString()); |
117 |
} |
118 |
|
119 |
private void RadCheckedDropDownListAVEVA_ItemCheckedChanged(object sender, RadCheckedListDataItemEventArgs e) |
120 |
{ |
121 |
var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == e.Item.Text.ToUpper()); |
122 |
if (layer != null) layer.Visible = e.Item.Checked; |
123 |
this.designCompare.Invalidate(); |
124 |
|
125 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", e.Item.Text, e.Item.Checked.ToString()); |
126 |
} |
127 |
|
128 |
private void RadCheckedDropDownListAutoCAD_ItemCheckedChanged(object sender, RadCheckedListDataItemEventArgs e) |
129 |
{ |
130 |
var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == e.Item.Text.ToUpper()); |
131 |
if (layer != null) layer.Visible = e.Item.Checked; |
132 |
this.designCompare.Invalidate(); |
133 |
|
134 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", e.Item.Text, e.Item.Checked.ToString()); |
135 |
} |
136 |
|
137 |
private void RadCheckBoxRevCloud_CheckStateChanged(object sender, EventArgs e) |
138 |
{ |
139 |
var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.RevCloudLayer.ToUpper()); |
140 |
if (layer != null) layer.Visible = (sender as RadCheckBox).Checked; |
141 |
this.designCompare.Invalidate(); |
142 |
} |
143 |
|
144 |
private void RadCheckBoxAVEVA_CheckStateChanged(object sender, EventArgs e) |
145 |
{ |
146 |
var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AVEVALayer.ToUpper()); |
147 |
if (layer != null) layer.Visible = (sender as RadCheckBox).Checked; |
148 |
this.designCompare.Invalidate(); |
149 |
} |
150 |
|
151 |
/// <summary> |
152 |
/// Cloud Mark의 색상을 설정한다. |
153 |
/// </summary> |
154 |
/// <param name="sender"></param> |
155 |
/// <param name="e"></param> |
156 |
private void RadColorBoxRevCloudColor_ValueChanged(object sender, EventArgs e) |
157 |
{ |
158 |
Verification.RevCloudColor = this.radColorBoxRevCloudColor.Value; |
159 |
string color = $"{Verification.RevCloudColor.R},{Verification.RevCloudColor.G},{Verification.RevCloudColor.B}"; |
160 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "RevCloudColor", color); |
161 |
} |
162 |
|
163 |
/// <summary> |
164 |
/// 두 도면을 비교하여 결과를 PDF로 출력한다. |
165 |
/// </summary> |
166 |
/// <param name="sender"></param> |
167 |
/// <param name="e"></param> |
168 |
public void CompareDrawings(IList<Document> docs, bool Save = false) |
169 |
{ |
170 |
string FileFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), |
171 |
Application.ProductName, "Compare"); |
172 |
if (!System.IO.Directory.Exists(FileFolder)) System.IO.Directory.CreateDirectory(FileFolder); |
173 |
|
174 |
try |
175 |
{ |
176 |
Size? size = new Size(); |
177 |
RadFixedDocument FixedDoc = null; |
178 |
if (Save) |
179 |
{ |
180 |
size = new Size(1920 * 2, 1080 * 2); |
181 |
FixedDoc = new RadFixedDocument(); |
182 |
|
183 |
designCompare.ActiveViewport.Background.BottomColor = Color.White; |
184 |
designCompare.ActiveViewport.Background.TopColor = Color.White; |
185 |
} |
186 |
|
187 |
_progressBar.Maximum = docs.Count(); |
188 |
_progressBar.Value1 = 0; |
189 |
foreach (var doc in docs) |
190 |
{ |
191 |
_progressBar.Text = doc.DocumentNo; |
192 |
CompareDrawing(doc, Save); |
193 |
|
194 |
if (Save) |
195 |
{ |
196 |
using (var bmp = this.designCompare.RenderToBitmap(size.Value)) |
197 |
{ |
198 |
string FilePath = System.IO.Path.Combine(FileFolder, $"{doc.DocumentNo}.jpg"); |
199 |
bmp.Save(FilePath, System.Drawing.Imaging.ImageFormat.Jpeg); |
200 |
|
201 |
var page = FixedDoc.Pages.AddPage(); |
202 |
page.Size = new Telerik.Documents.Primitives.Size(size.Value.Width, size.Value.Height); |
203 |
var editor = new FixedContentEditor(page); |
204 |
using (FileStream fs = new FileStream(FilePath, FileMode.Open)) |
205 |
{ |
206 |
editor.DrawImage(fs); |
207 |
} |
208 |
} |
209 |
} |
210 |
|
211 |
_progressBar.Value1 += 1; |
212 |
Application.DoEvents(); |
213 |
} |
214 |
|
215 |
if (Save) |
216 |
{ |
217 |
RadSaveFileDialog saveFileDialog = new RadSaveFileDialog() |
218 |
{ |
219 |
Filter = "PDF files (*.pdf)|*.pdf", |
220 |
RestoreDirectory = true |
221 |
}; |
222 |
if (System.Windows.Forms.DialogResult.OK == saveFileDialog.ShowDialog()) |
223 |
{ |
224 |
string selectedFileName = saveFileDialog.FileName; |
225 |
|
226 |
// If you are working in a .NET Core application, you will need to also provide an image resolver. You can use the default implementation provided in Telerik.Documents.ImageUtils: |
227 |
Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver(); |
228 |
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver; |
229 |
|
230 |
var provider = new PdfFormatProvider(); |
231 |
File.WriteAllBytes(selectedFileName, provider.Export(FixedDoc)); |
232 |
|
233 |
RadMessageBox.Show("Comparing document is done"); |
234 |
} |
235 |
} |
236 |
} |
237 |
catch(Exception ex) |
238 |
{ |
239 |
RadMessageBox.Show(ex.Message); |
240 |
} |
241 |
finally |
242 |
{ |
243 |
designCompare.ActiveViewport.Background.BottomColor = Color.Black; |
244 |
designCompare.ActiveViewport.Background.TopColor = Color.Black; |
245 |
} |
246 |
} |
247 |
|
248 |
/// <summary> |
249 |
/// 서로 다른 엔터티의 색상을 설정한다. |
250 |
/// </summary> |
251 |
/// <param name="sender"></param> |
252 |
/// <param name="e"></param> |
253 |
private void RadColorBoxDiffColor_ValueChanged(object sender, EventArgs e) |
254 |
{ |
255 |
Verification.DiffColor = this.radColorBoxDiffColor.Value; |
256 |
string color = $"{Verification.DiffColor.R},{Verification.DiffColor.G},{Verification.DiffColor.B}"; |
257 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "DiffColor", color); |
258 |
} |
259 |
|
260 |
/// <summary> |
261 |
/// AutoCAD 엔터티의 색상을 설정한다. |
262 |
/// </summary> |
263 |
/// <param name="sender"></param> |
264 |
/// <param name="e"></param> |
265 |
private void RadColorBoxAutoCADColor_ValueChanged(object sender, EventArgs e) |
266 |
{ |
267 |
Verification.AutoCADColor = this.radColorBoxAutoCADColor.Value; |
268 |
string color = $"{Verification.AutoCADColor.R},{Verification.AutoCADColor.G},{Verification.AutoCADColor.B}"; |
269 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "AutoCADColor", color); |
270 |
} |
271 |
|
272 |
/// <summary> |
273 |
/// AVEVA 엔터티의 색상을 설정한다. |
274 |
/// </summary> |
275 |
/// <param name="sender"></param> |
276 |
/// <param name="e"></param> |
277 |
private void RadColorBoxAVEVAColor_ValueChanged(object sender, EventArgs e) |
278 |
{ |
279 |
Verification.AVEVAColor = this.radColorBoxAVEVAColor.Value; |
280 |
string color = $"{Verification.AVEVAColor.R},{Verification.AVEVAColor.G},{Verification.AVEVAColor.B}"; |
281 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "AVEVAColor", color); |
282 |
} |
283 |
|
284 |
/// <summary> |
285 |
/// 수정한 Tolerance를 시스템에 반영한다. |
286 |
/// </summary> |
287 |
/// <param name="sender"></param> |
288 |
/// <param name="e"></param> |
289 |
private void RadSpinEditorTolerance_ValueChanged(object sender, EventArgs e) |
290 |
{ |
291 |
double toler = Convert.ToDouble(this.radSpinEditorTolerance.Value); |
292 |
Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "Tolerance", toler.ToString()); |
293 |
Verification.Tolerance = toler; |
294 |
} |
295 |
|
296 |
private void Verification_Load(object sender, EventArgs e) |
297 |
{ |
298 |
string Toler = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Tolerance"); |
299 |
if (!string.IsNullOrEmpty(Toler)) |
300 |
{ |
301 |
this.radSpinEditorTolerance.Value = Convert.ToDecimal(Toler); |
302 |
Verification.Tolerance = Convert.ToDouble(this.radSpinEditorTolerance.Value); |
303 |
} |
304 |
|
305 |
string _AutoCADLayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AutoCADLayer); |
306 |
if (!string.IsNullOrEmpty(_AutoCADLayer)) |
307 |
{ |
308 |
bool Checked = Convert.ToBoolean(_AutoCADLayer); |
309 |
var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text == Verification.AutoCADLayer); |
310 |
if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked; |
311 |
} |
312 |
|
313 |
string _AutoCADDiffLayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AutoCADDiffLayer); |
314 |
if (!string.IsNullOrEmpty(_AutoCADDiffLayer)) |
315 |
{ |
316 |
bool Checked = Convert.ToBoolean(_AutoCADDiffLayer); |
317 |
var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text == Verification.AutoCADDiffLayer); |
318 |
if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked; |
319 |
} |
320 |
|
321 |
string _AutoCADColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "AutoCADColor"); |
322 |
if (!string.IsNullOrEmpty(_AutoCADColor)) |
323 |
{ |
324 |
var tokens = _AutoCADColor.Split(','); |
325 |
if (tokens.Length == 3) |
326 |
{ |
327 |
this.radColorBoxAutoCADColor.Value = |
328 |
Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2])); |
329 |
} |
330 |
} |
331 |
|
332 |
string _AVEVALayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AVEVALayer); |
333 |
if (!string.IsNullOrEmpty(_AutoCADLayer)) |
334 |
{ |
335 |
bool Checked = Convert.ToBoolean(_AVEVALayer); |
336 |
var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text == Verification.AVEVALayer); |
337 |
if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked; |
338 |
} |
339 |
|
340 |
string _AVEVADiffLayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AVEVADiffLayer); |
341 |
if (!string.IsNullOrEmpty(_AVEVADiffLayer)) |
342 |
{ |
343 |
bool Checked = Convert.ToBoolean(_AVEVADiffLayer); |
344 |
var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text == Verification.AVEVADiffLayer); |
345 |
if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked; |
346 |
} |
347 |
|
348 |
string _AVEVAColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "AVEVAColor"); |
349 |
if (!string.IsNullOrEmpty(_AVEVAColor)) |
350 |
{ |
351 |
var tokens = _AVEVAColor.Split(','); |
352 |
if (tokens.Length == 3) |
353 |
{ |
354 |
this.radColorBoxAVEVAColor.Value = |
355 |
Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2])); |
356 |
} |
357 |
} |
358 |
|
359 |
string _DiffColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "DiffColor"); |
360 |
if (!string.IsNullOrEmpty(_DiffColor)) |
361 |
{ |
362 |
var tokens = _DiffColor.Split(','); |
363 |
if (tokens.Length == 3) |
364 |
{ |
365 |
this.radColorBoxDiffColor.Value = |
366 |
Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2])); |
367 |
} |
368 |
} |
369 |
|
370 |
string _RevCloudColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "RevCloudColor"); |
371 |
if (!string.IsNullOrEmpty(_RevCloudColor)) |
372 |
{ |
373 |
var tokens = _RevCloudColor.Split(','); |
374 |
if (tokens.Length == 3) |
375 |
{ |
376 |
this.radColorBoxRevCloudColor.Value = |
377 |
Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2])); |
378 |
} |
379 |
} |
380 |
|
381 |
string _LengthToleranceRatio = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Length Tolerance Ratio"); |
382 |
if (!string.IsNullOrEmpty(_LengthToleranceRatio)) |
383 |
{ |
384 |
LengthToleranceRatio = Convert.ToDouble(_LengthToleranceRatio); |
385 |
} |
386 |
|
387 |
string _ArrowMaxLength = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Arrow Max Length"); |
388 |
if (!string.IsNullOrEmpty(_ArrowMaxLength)) |
389 |
{ |
390 |
Forms.ExceptLayer.ArrowMaxLength = Convert.ToDouble(_ArrowMaxLength); |
391 |
} |
392 |
|
393 |
string _SpecialCharacters = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "SpecialCharacters"); |
394 |
if (!string.IsNullOrEmpty(_SpecialCharacters)) |
395 |
{ |
396 |
var tokens = _SpecialCharacters.Split(',').ToList(); |
397 |
Forms.ExceptLayer.SpecialCharacters.AddRange(tokens.ConvertAll(x => |
398 |
{ |
399 |
var characters = x.Split('='); |
400 |
return new Forms.ExceptLayer.SpecialCharacter(characters[0], characters[1]); |
401 |
})); |
402 |
} |
403 |
|
404 |
string _Casesensitive = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Casesensitive"); |
405 |
if (!string.IsNullOrEmpty(_Casesensitive)) |
406 |
{ |
407 |
Casesensitive = Convert.ToBoolean(_Casesensitive); |
408 |
} |
409 |
|
410 |
#region Except Layer를 로딩한다. |
411 |
LoadLayerSettings(); |
412 |
#endregion |
413 |
|
414 |
this.designCompare.WorkCompleted += DesignCompare_WorkCompleted; |
415 |
} |
416 |
|
417 |
private void ApplyLayers() |
418 |
{ |
419 |
var others = this.designCompare.Entities.Where(x => |
420 |
{ |
421 |
return (x.LayerName != Verification.AVEVALayer && x.LayerName != Verification.AVEVADiffLayer && |
422 |
x.LayerName != Verification.AutoCADLayer && x.LayerName != Verification.AutoCADDiffLayer && |
423 |
x.LayerName != Verification.RevCloudLayer); |
424 |
}).ToList(); |
425 |
|
426 |
others.ForEach(x => |
427 |
{ |
428 |
if (x.LayerName == Verification.AutoCADExceptLayer) |
429 |
x.LayerName = Verification.AutoCADLayer; |
430 |
else if (x.LayerName == Verification.AVEVAExceptLayer) |
431 |
x.LayerName = Verification.AVEVALayer; |
432 |
}); |
433 |
|
434 |
#region 레이어 설정 적용 |
435 |
var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.RevCloudLayer.ToUpper()); |
436 |
if (layer != null) layer.Visible = this.radCheckBoxRevCloud.Checked; |
437 |
|
438 |
layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AVEVALayer.ToUpper()); |
439 |
if (layer != null) |
440 |
{ |
441 |
var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AVEVALayer.ToUpper()); |
442 |
if (item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked; |
443 |
} |
444 |
|
445 |
layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AVEVADiffLayer.ToUpper()); |
446 |
if (layer != null) |
447 |
{ |
448 |
var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AVEVADiffLayer.ToUpper()); |
449 |
if (item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked; |
450 |
} |
451 |
|
452 |
layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AutoCADLayer.ToUpper()); |
453 |
if (layer != null) |
454 |
{ |
455 |
var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AutoCADLayer.ToUpper()); |
456 |
if (item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked; |
457 |
} |
458 |
|
459 |
layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AutoCADDiffLayer.ToUpper()); |
460 |
if (layer != null) |
461 |
{ |
462 |
var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AutoCADDiffLayer.ToUpper()); |
463 |
if (item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked; |
464 |
} |
465 |
#endregion |
466 |
} |
467 |
|
468 |
private void DesignCompare_WorkCompleted(object sender, devDept.WorkCompletedEventArgs e) |
469 |
{ |
470 |
if(e.WorkUnit is Classes.CompareModelWorkUnit workunit) |
471 |
{ |
472 |
ApplyLayers(); |
473 |
this.designCompare.Invalidate(); |
474 |
|
475 |
if (OnCompareComplete != null) |
476 |
{ |
477 |
var TextInfoColl = new List<TextInfo>(); |
478 |
var TextColl = designAutoCAD.Entities.OfType<devDept.Eyeshot.Entities.Text>().ToList(); |
479 |
foreach (var text in TextColl) |
480 |
{ |
481 |
TextInfoColl.Add(new TextInfo(Math.Round(text.InsertionPoint.X, 5), Math.Round(text.InsertionPoint.Y, 5), text.TextString)); |
482 |
} |
483 |
OnCompareComplete(TextInfoColl); |
484 |
} |
485 |
} |
486 |
} |
487 |
|
488 |
/// <summary> |
489 |
/// 레이어 설정을 읽는다. |
490 |
/// </summary> |
491 |
public void LoadLayerSettings() |
492 |
{ |
493 |
Forms.ExceptLayer.ExceptLayers.Clear(); |
494 |
Forms.ExceptLayer.LineLayers.Clear(); |
495 |
|
496 |
string _ExceptLayers = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Except Layers"); |
497 |
if (!string.IsNullOrEmpty(_ExceptLayers)) |
498 |
{ |
499 |
Forms.ExceptLayer.ExceptLayers.AddRange(_ExceptLayers.Split(',').ToList().ConvertAll(x => new Forms.ExceptLayer.Layer(x))); |
500 |
|
501 |
string _ExceptLayersVisible = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Except Layers Visible"); |
502 |
if (!string.IsNullOrEmpty(_ExceptLayersVisible)) |
503 |
{ |
504 |
var tokens = _ExceptLayersVisible.Split(',').ToList().ConvertAll(x => Convert.ToBoolean(x)); |
505 |
for (int i = 0; i < Forms.ExceptLayer.ExceptLayers.Count; ++i) |
506 |
{ |
507 |
if (i < tokens.Count) |
508 |
{ |
509 |
Forms.ExceptLayer.ExceptLayers[i].Visible = tokens[i]; |
510 |
} |
511 |
} |
512 |
} |
513 |
} |
514 |
|
515 |
string _LineLayers = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Line Layers"); |
516 |
if (!string.IsNullOrEmpty(_LineLayers)) |
517 |
{ |
518 |
Forms.ExceptLayer.LineLayers.AddRange(_LineLayers.Split(',').ToList().ConvertAll(x => new Forms.ExceptLayer.Layer(x))); |
519 |
} |
520 |
} |
521 |
|
522 |
/// <summary> |
523 |
/// 엔터티들의 색상을 바꾼다. |
524 |
/// </summary> |
525 |
/// <param name="design"></param> |
526 |
/// <param name="list"></param> |
527 |
public void ColorEntities(Design design, IList<Entity> list, Color color, colorMethodType colorMethod=colorMethodType.byEntity, bool ChangeBlkColor=true) |
528 |
{ |
529 |
foreach (Entity ent in list) |
530 |
{ |
531 |
ColorEntity(design, ent, color, colorMethod, ChangeBlkColor); |
532 |
} |
533 |
} |
534 |
|
535 |
/// <summary> |
536 |
/// 엔터티의 색상을 변경한다. |
537 |
/// </summary> |
538 |
/// <param name="design"></param> |
539 |
/// <param name="entity"></param> |
540 |
/// <param name="color"></param> |
541 |
private void ColorEntity(Design design, Entity entity, Color color, colorMethodType colorMethod = colorMethodType.byEntity, |
542 |
bool ChangeBlkColor = true) |
543 |
{ |
544 |
if (entity is BlockReference blkref) |
545 |
{ |
546 |
blkref.Color = color; |
547 |
blkref.ColorMethod = colorMethod; |
548 |
|
549 |
if (ChangeBlkColor) |
550 |
{ |
551 |
var blk = design.Blocks.FirstOrDefault(x => x.Name == blkref.BlockName); |
552 |
if (blk != null) |
553 |
{ |
554 |
ColorEntities(design, blk.Entities, color, colorMethodType.byParent); |
555 |
foreach (var attr in blkref.Attributes.Values) |
556 |
{ |
557 |
attr.Color = color; |
558 |
attr.ColorMethod = colorMethodType.byParent; |
559 |
} |
560 |
} |
561 |
} |
562 |
} |
563 |
else |
564 |
{ |
565 |
entity.Color = color; |
566 |
entity.ColorMethod = colorMethod; |
567 |
} |
568 |
} |
569 |
|
570 |
/// <summary> |
571 |
/// 블럭 참조를 깨어 블럭의 구성 요소들을 리트스트 리턴한다. |
572 |
/// </summary> |
573 |
/// <param name="design"></param> |
574 |
/// <param name="blkref"></param> |
575 |
/// <param name="LayerName"></param> |
576 |
/// <param name="color"></param> |
577 |
/// <returns></returns> |
578 |
private List<Entity> ExplodeBlockReference(BlockKeyedCollection Blocks, BlockReference blkref, string LayerName, Color color) |
579 |
{ |
580 |
var res = new List<Entity>(); |
581 |
|
582 |
try |
583 |
{ |
584 |
var entities = blkref.Explode(Blocks); |
585 |
entities.ToList().ForEach(y => |
586 |
{ |
587 |
#region 블럭 이름이 ARROW로 시작되는 경우 Hatch로 화살표를 그려준다. |
588 |
if (y is LinearPath arrow && arrow.Vertices.Length == 2 && blkref.BlockName.StartsWith("ARROW")) |
589 |
{ |
590 |
double weight = arrow.LineWeight * blkref.GetScaleFactorY(); |
591 |
var dir = new devDept.Geometry.Vector3D(arrow.Vertices[0], arrow.Vertices[1]); |
592 |
dir.Normalize(); |
593 |
var cross = devDept.Geometry.Vector3D.Cross(devDept.Geometry.Vector3D.AxisZ, dir); |
594 |
var pts = new devDept.Geometry.Point3D[] |
595 |
{ |
596 |
arrow.Vertices[1] + cross * weight * 0.5, |
597 |
arrow.Vertices[0], |
598 |
arrow.Vertices[1] - cross * weight * 0.5 |
599 |
}; |
600 |
|
601 |
var hatch = new Hatch("SOLID", new List<ICurve>() { new LinearPath(pts) }); |
602 |
res.Add(hatch); |
603 |
} |
604 |
#endregion |
605 |
else if (y is LinearPath lp) |
606 |
{ |
607 |
int count = Convert.ToInt32(lp.Vertices.Length); |
608 |
for (int i = 0; i < count - 1; ++i) |
609 |
{ |
610 |
var line = new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1]) |
611 |
{ |
612 |
LayerName = lp.LayerName, |
613 |
LineWeight = lp.LineWeight, |
614 |
LineTypeMethod = colorMethodType.byEntity, |
615 |
Color = lp.Color, |
616 |
ColorMethod = colorMethodType.byEntity |
617 |
}; |
618 |
res.Add(line); |
619 |
} |
620 |
} |
621 |
/// PORT, ARROW로 시작하는 블럭은 제외 |
622 |
else if (y is BlockReference subblkref && subblkref.BlockName != "PORT") |
623 |
{ |
624 |
res.AddRange(ExplodeBlockReference(Blocks, subblkref, LayerName, color)); |
625 |
} |
626 |
}); |
627 |
|
628 |
var attributes = blkref.Attributes.ToList(); |
629 |
foreach (var ent in entities.Where(y => y is devDept.Eyeshot.Entities.Attribute attr && !attr.Invisible)) |
630 |
{ |
631 |
var txt = ent as devDept.Eyeshot.Entities.Attribute; |
632 |
#region 텍스트가 뒤집어지는 것을 방지하기 위해 평면을 교체 |
633 |
if (txt.Plane.AxisX.Equals(devDept.Geometry.Vector3D.AxisMinusX) && txt.Plane.AxisY.Equals(devDept.Geometry.Vector3D.AxisY)) |
634 |
{ |
635 |
txt.Plane = new devDept.Geometry.Plane(txt.Plane.Origin, devDept.Geometry.Vector3D.AxisX, devDept.Geometry.Vector3D.AxisY); |
636 |
} |
637 |
#endregion |
638 |
txt.LayerName = LayerName; |
639 |
txt.Color = color; |
640 |
txt.ColorMethod = colorMethodType.byEntity; |
641 |
KeyValuePair<string, AttributeReference>? kp = attributes.FirstOrDefault(z => z.Key == txt.Tag); |
642 |
if (kp.HasValue) |
643 |
{ |
644 |
///attributes.RemoveAll(x => x.Key == txt.Tag); |
645 |
txt.TextString = (kp.Value.Value) != null ? kp.Value.Value.Value : string.Empty; |
646 |
/* |
647 |
if (string.IsNullOrEmpty(txt.TextString)) |
648 |
{ |
649 |
var attr = attributes.FirstOrDefault(x => !string.IsNullOrEmpty(x.Value.Value)).Value; |
650 |
if (attr != null) |
651 |
{ |
652 |
txt.TextString = attr.Value; |
653 |
attributes.RemoveAll(x => x.Value.Equals(attr)); |
654 |
} |
655 |
} |
656 |
*/ |
657 |
} |
658 |
} |
659 |
|
660 |
res.AddRange(entities.Where(y => |
661 |
{ |
662 |
if (y is devDept.Eyeshot.Entities.Attribute attr && (string.IsNullOrEmpty(attr.TextString) || attr.Invisible)) return false; |
663 |
if (y is devDept.Eyeshot.Entities.Text text && string.IsNullOrEmpty(text.TextString)) return false; |
664 |
if (y is devDept.Eyeshot.Entities.Point) return false; |
665 |
if (y is BlockReference subblkref) return false; |
666 |
if (y is LinearPath) return false; |
667 |
if (y.LayerName.ToUpper() == "AS_PORT") return false; |
668 |
return true; |
669 |
})); |
670 |
|
671 |
#region 제외 레이어에 속한 항목은 포함하지 않는다. |
672 |
res.RemoveAll(x => |
673 |
{ |
674 |
return Forms.ExceptLayer.ExceptLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper() && !y.Visible); |
675 |
}); |
676 |
#endregion |
677 |
foreach (var ent in res) ent.LayerName = LayerName; |
678 |
|
679 |
blkref.Attributes.Clear(); |
680 |
///blkref.UpdateBoundingBox(new TraversalParams(design)); |
681 |
} |
682 |
catch(Exception ex) |
683 |
{ |
684 |
Console.WriteLine(ex.Message); |
685 |
} |
686 |
|
687 |
return res; |
688 |
} |
689 |
|
690 |
/// <summary> |
691 |
/// 주어진 도면의 원본과 AVEVA를 비교한다. |
692 |
/// </summary> |
693 |
private void CompareDrawing(Document doc, bool ResultOnly = false) |
694 |
{ |
695 |
/// AutoCAD P&ID 파일을 화면에 표시한다. |
696 |
void ShowAutoCADFile(string FilePath, Design design, bool clear = true) |
697 |
{ |
698 |
if (clear) design.Clear(); |
699 |
var AddEntities = new List<Entity>(); |
700 |
|
701 |
if (System.IO.File.Exists(FilePath)) |
702 |
{ |
703 |
try |
704 |
{ |
705 |
#region 다른 프로세스에서 파일을 열고 있는 경우 처리 |
706 |
using (var fs = File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) |
707 |
#endregion |
708 |
|
709 |
{ |
710 |
devDept.Eyeshot.Translators.ReadAutodesk ra = new devDept.Eyeshot.Translators.ReadAutodesk(fs); |
711 |
ra.DoWork(); |
712 |
var min = ra.Min; |
713 |
if (!ra.Layers.Contains(Verification.AutoCADLayer)) ra.Layers.Add(Verification.AutoCADLayer, Verification.AutoCADColor); |
714 |
if (!ra.Layers.Contains(Verification.AutoCADDiffLayer)) ra.Layers.Add(Verification.AutoCADDiffLayer, Verification.DiffColor); |
715 |
if (!ra.Layers.Contains(Verification.AutoCADExceptLayer)) ra.Layers.Add(Verification.AutoCADExceptLayer, Verification.AutoCADColor); |
716 |
foreach (var ent in ra.Entities) |
717 |
{ |
718 |
/// 도면을 원점으로 맞춘다. |
719 |
if (min.X != 0 && min.Y != 0) ent.Translate(-min.X, -min.Y); |
720 |
|
721 |
if (ent is BlockReference blkref) |
722 |
{ |
723 |
AddEntities.AddRange(ExplodeBlockReference(ra.Blocks, blkref, Verification.AutoCADLayer, Verification.AutoCADColor)); |
724 |
} |
725 |
} |
726 |
ra.AddToScene(design); |
727 |
} |
728 |
} |
729 |
catch (Exception ex) |
730 |
{ |
731 |
RadMessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, RadMessageIcon.Error); |
732 |
return; |
733 |
} |
734 |
|
735 |
#region LinearPath를 Line으로 분할한다. |
736 |
design.Entities.ForEach(x => |
737 |
{ |
738 |
if (x is LinearPath lp) |
739 |
{ |
740 |
#region 정점 수가 2이고 LineWeight이 0 초과이고 길이가 ArrowMaxLength보다 작을때 화살표를 그려준다. |
741 |
if (lp.Vertices.Count() == 2 && lp.LineWeight > 0 && lp.Length() < Forms.ExceptLayer.ArrowMaxLength) |
742 |
{ |
743 |
double weight = lp.LineWeight; |
744 |
var dir = new devDept.Geometry.Vector3D(lp.Vertices[0], lp.Vertices[1]); |
745 |
dir.Normalize(); |
746 |
var cross = devDept.Geometry.Vector3D.Cross(devDept.Geometry.Vector3D.AxisZ, dir); |
747 |
var pts = new devDept.Geometry.Point3D[] |
748 |
{ |
749 |
lp.Vertices[1] + cross * weight * 0.5, |
750 |
lp.Vertices[0], |
751 |
lp.Vertices[1] - cross * weight * 0.5 |
752 |
}; |
753 |
|
754 |
var hatch = new Hatch("SOLID", new List<ICurve>() { new LinearPath(pts) }); |
755 |
AddEntities.Add(hatch); |
756 |
} |
757 |
#endregion |
758 |
else |
759 |
{ |
760 |
int count = Convert.ToInt32(lp.Vertices.Length); |
761 |
for (int i = 0; i < count - 1; ++i) |
762 |
{ |
763 |
AddEntities.Add(new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1]) |
764 |
{ |
765 |
LayerName = lp.LayerName, |
766 |
LineWeight = lp.LineWeight, |
767 |
LineTypeMethod = colorMethodType.byEntity |
768 |
}); |
769 |
} |
770 |
} |
771 |
} |
772 |
}); |
773 |
design.Entities.RemoveAll(x => (x is LinearPath)); |
774 |
#endregion |
775 |
|
776 |
design.Entities.AddRange(AddEntities); |
777 |
|
778 |
#region 브랜치가 생성되는 부분에서 파이프 라인을 분할 |
779 |
var queue = design.Entities.Where(x => x is Line && |
780 |
Forms.ExceptLayer.LineLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper())).ToList(); |
781 |
while (queue.Any()) |
782 |
{ |
783 |
var line1 = queue.First() as Line; |
784 |
var dir1 = line1.Direction; |
785 |
dir1.Normalize(); |
786 |
queue.Remove(line1); |
787 |
for (int i = 0; i < queue.Count; ++i) |
788 |
{ |
789 |
var line2 = queue.ElementAt(i) as Line; |
790 |
var dir2 = line2.Direction; |
791 |
dir2.Normalize(); |
792 |
if (devDept.Geometry.Vector3D.AreOrthogonal(dir1, dir2)) |
793 |
{ |
794 |
var intersects = line1.IntersectWith(line2); |
795 |
if (intersects.Count() == 1) |
796 |
{ |
797 |
if (line1.StartPoint.DistanceTo(intersects[0]) > 0.1 && line1.EndPoint.DistanceTo(intersects[0]) > 0.1) |
798 |
{ |
799 |
var split1 = new devDept.Eyeshot.Entities.Line(line1.StartPoint, intersects[0]) |
800 |
{ |
801 |
LayerName = line1.LayerName, |
802 |
LineWeight = line1.LineWeight, |
803 |
LineTypeMethod = colorMethodType.byEntity |
804 |
}; |
805 |
var split2 = new devDept.Eyeshot.Entities.Line(intersects[0], line1.EndPoint) |
806 |
{ |
807 |
LayerName = line1.LayerName, |
808 |
LineWeight = line1.LineWeight, |
809 |
LineTypeMethod = colorMethodType.byEntity |
810 |
}; |
811 |
design.Entities.Add(split1); |
812 |
design.Entities.Add(split2); |
813 |
design.Entities.Remove(line1); |
814 |
|
815 |
queue.Add(split1); |
816 |
queue.Add(split2); |
817 |
|
818 |
break; |
819 |
} |
820 |
|
821 |
if (line2.StartPoint.DistanceTo(intersects[0]) > 0.1 && line2.EndPoint.DistanceTo(intersects[0]) > 0.1) |
822 |
{ |
823 |
var split1 = new devDept.Eyeshot.Entities.Line(line2.StartPoint, intersects[0]) |
824 |
{ |
825 |
LayerName = line2.LayerName, |
826 |
LineWeight = line2.LineWeight, |
827 |
LineTypeMethod = colorMethodType.byEntity |
828 |
}; |
829 |
var split2 = new devDept.Eyeshot.Entities.Line(intersects[0], line2.EndPoint) |
830 |
{ |
831 |
LayerName = line2.LayerName, |
832 |
LineWeight = line2.LineWeight, |
833 |
LineTypeMethod = colorMethodType.byEntity |
834 |
}; |
835 |
design.Entities.Add(split1); |
836 |
design.Entities.Add(split2); |
837 |
design.Entities.Remove(line2); |
838 |
|
839 |
queue.Remove(line2); |
840 |
queue.Add(split1); |
841 |
queue.Add(split2); |
842 |
} |
843 |
} |
844 |
} |
845 |
} |
846 |
} |
847 |
#endregion |
848 |
|
849 |
#region 레이어 변경 |
850 |
foreach (var ent in design.Entities) |
851 |
{ |
852 |
ent.Color = Verification.AutoCADColor; |
853 |
ent.ColorMethod = colorMethodType.byEntity; |
854 |
if (!Forms.ExceptLayer.ExceptLayers.Exists(x => x.Name.ToUpper() == ent.LayerName.ToUpper())) |
855 |
{ |
856 |
ent.LayerName = Verification.AutoCADLayer; |
857 |
} |
858 |
else |
859 |
{ |
860 |
ent.LayerName = Verification.AutoCADExceptLayer; |
861 |
} |
862 |
} |
863 |
#endregion |
864 |
|
865 |
#region 블럭이거나 제외 레이어에 속한 항목은 제거 |
866 |
design.Entities.RemoveAll(x => (x is BlockReference) || Forms.ExceptLayer.ExceptLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper() && !y.Visible)); |
867 |
#endregion |
868 |
|
869 |
#region 눈에 보이지 않는 라인은 제거 |
870 |
design.Entities.RemoveAll(x => x is Line line && line.Length() < 0.001); |
871 |
#endregion |
872 |
|
873 |
ColorEntities(design, design.Entities, Verification.AutoCADColor); |
874 |
|
875 |
// Sets the view as Top |
876 |
design.SetView(viewType.Top); |
877 |
design.ZoomFit(); |
878 |
design.Invalidate(); |
879 |
} |
880 |
} |
881 |
|
882 |
/// AVEVA P&ID 파일을 화면에 표시한다. |
883 |
void ShowAVEVAPIDFile(string FilePath, Design design, bool clear = true) |
884 |
{ |
885 |
if (clear) design.Clear(); |
886 |
if (System.IO.File.Exists(FilePath)) |
887 |
{ |
888 |
var AddEntities = new List<Entity>(); |
889 |
|
890 |
#region 다른 프로세스에서 파일을 열고 있는 경우 처리 |
891 |
using (var fs = File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) |
892 |
#endregion |
893 |
{ |
894 |
devDept.Eyeshot.Translators.ReadAutodesk ra = new devDept.Eyeshot.Translators.ReadAutodesk(fs); |
895 |
ra.DoWork(); |
896 |
|
897 |
if (!ra.Layers.Contains(Verification.AVEVALayer)) ra.Layers.Add(Verification.AVEVALayer, Verification.AVEVAColor); |
898 |
if (!ra.Layers.Contains(Verification.AVEVADiffLayer)) ra.Layers.Add(Verification.AVEVADiffLayer, Verification.DiffColor); |
899 |
if (!ra.Layers.Contains(Verification.AVEVAExceptLayer)) ra.Layers.Add(Verification.AVEVAExceptLayer, Verification.AVEVAColor); |
900 |
var min = ra.Min; |
901 |
foreach (var ent in ra.Entities) |
902 |
{ |
903 |
/// 도면을 원점으로 맞춘다. |
904 |
if (min.X != 0 && min.Y != 0) ent.Translate(-min.X, -min.Y); |
905 |
|
906 |
#region 멀티 라인들을 분할하여 추가한다. |
907 |
if (ent is Mesh mesh && (mesh.LayerName == "AS_PIPE" || mesh.LayerName == "AS_INST")) |
908 |
{ |
909 |
int count = Convert.ToInt32(mesh.Vertices.Length * 0.5); |
910 |
for (int i = 0; i < count - 1; ++i) |
911 |
{ |
912 |
AddEntities.Add(new devDept.Eyeshot.Entities.Line(mesh.Vertices[i], mesh.Vertices[i + 1]) |
913 |
{ |
914 |
LayerName = Verification.AVEVALayer, |
915 |
LineWeight = 3.0f, |
916 |
LineTypeMethod = colorMethodType.byEntity, |
917 |
Color = Verification.AVEVAColor, |
918 |
ColorMethod = colorMethodType.byEntity |
919 |
}); |
920 |
} |
921 |
} |
922 |
else if (ent is TabulatedSurface tf && (tf.LayerName == "AS_PIPE" || tf.LayerName == "AS_INST")) |
923 |
{ |
924 |
int count = Convert.ToInt32(tf.ControlPoints.Length * 0.5); |
925 |
for (int i = 0; i < count - 1; ++i) |
926 |
{ |
927 |
AddEntities.Add( |
928 |
new devDept.Eyeshot.Entities.Line( |
929 |
new devDept.Geometry.Point3D(tf.ControlPoints[i, 0].X, tf.ControlPoints[i, 0].Y, 0), |
930 |
new devDept.Geometry.Point3D(tf.ControlPoints[i + 1, 0].X, tf.ControlPoints[i + 1, 0].Y, 0)) |
931 |
{ |
932 |
LayerName = Verification.AVEVALayer, |
933 |
LineWeight = 3.0f, |
934 |
LineTypeMethod = colorMethodType.byEntity, |
935 |
Color = Verification.AVEVAColor, |
936 |
ColorMethod = colorMethodType.byEntity |
937 |
} |
938 |
); |
939 |
} |
940 |
} |
941 |
else if (ent is LinearPath lp) |
942 |
{ |
943 |
string LayerName = Forms.ExceptLayer.ExceptLayers.Exists(x => x.Name.ToUpper() == lp.LayerName.ToUpper()) ? |
944 |
Verification.AVEVAExceptLayer : Verification.AVEVALayer; |
945 |
int count = Convert.ToInt32(lp.Vertices.Length); |
946 |
for (int i = 0; i < count - 1; ++i) |
947 |
{ |
948 |
AddEntities.Add(new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1]) |
949 |
{ |
950 |
LayerName = LayerName, |
951 |
LineWeight = lp.LineWeight, |
952 |
Color = Verification.AVEVAColor, |
953 |
LineTypeMethod = colorMethodType.byEntity |
954 |
}); |
955 |
} |
956 |
|
957 |
#region 밑에서 제거하기 위해 레이어를 AVEVALayer로 바꿔준다. |
958 |
lp.LayerName = Verification.AVEVALayer; |
959 |
#endregion |
960 |
} |
961 |
#endregion |
962 |
else if (ent is BlockReference blkref) |
963 |
{ |
964 |
if (blkref.BlockName != "LBRK" && blkref.BlockName != "PSNODE" && blkref.BlockName != "PENODE") |
965 |
{ |
966 |
AddEntities.AddRange(ExplodeBlockReference(ra.Blocks, blkref, Verification.AVEVALayer, Verification.AVEVAColor)); |
967 |
} |
968 |
} |
969 |
|
970 |
ent.Color = Verification.AVEVAColor; |
971 |
ent.ColorMethod = colorMethodType.byEntity; |
972 |
if (!Forms.ExceptLayer.ExceptLayers.Exists(x => x.Name.ToUpper() == ent.LayerName.ToUpper())) |
973 |
{ |
974 |
ent.LayerName = Verification.AVEVALayer; |
975 |
} |
976 |
else |
977 |
{ |
978 |
ent.LayerName = Verification.AVEVAExceptLayer; |
979 |
} |
980 |
} |
981 |
ra.AddToScene(design); |
982 |
} |
983 |
|
984 |
#region 불필요한 블럭들은 제거 |
985 |
design.Entities.RemoveAll(x => x is BlockReference); |
986 |
#endregion |
987 |
|
988 |
#region 블럭을 깸 |
989 |
design.Entities.Where(x => x.LayerName == Verification.AVEVALayer).ToList().ForEach(x => |
990 |
{ |
991 |
if(x is BlockReference blkref) |
992 |
{ |
993 |
AddEntities.AddRange(ExplodeBlockReference(design.Blocks, blkref, Verification.AVEVALayer, Verification.AVEVAColor)); |
994 |
} |
995 |
}); |
996 |
design.Entities.RemoveAll(x => |
997 |
((x is Mesh || x is TabulatedSurface) && (x.LayerName == Verification.AVEVALayer)) || |
998 |
(x is LinearPath && x.LayerName == Verification.AVEVALayer) || (x is BlockReference) || |
999 |
Forms.ExceptLayer.ExceptLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper() && !y.Visible)); |
1000 |
design.Entities.AddRange(AddEntities); |
1001 |
#endregion |
1002 |
|
1003 |
#region 눈에 보이지 않는 라인은 제거 |
1004 |
design.Entities.RemoveAll(x => x is Line line && line.Length() < 0.001); |
1005 |
#endregion |
1006 |
|
1007 |
ColorEntities(design, design.Entities.Where(x => x.LayerName == Verification.AVEVALayer).ToList(), Verification.AVEVAColor); |
1008 |
|
1009 |
design.SetView(viewType.Top); |
1010 |
design.ZoomFit(); |
1011 |
design.Invalidate(); |
1012 |
} |
1013 |
} |
1014 |
|
1015 |
string dwgExtension = ".dwg"; |
1016 |
string ID2DrawingFolder = Program.AutoCADFolder; |
1017 |
string dwgFilePath = System.IO.Path.Combine(ID2DrawingFolder, $"{doc.DocumentNo}{dwgExtension}"); |
1018 |
if (!ResultOnly) ShowAutoCADFile(dwgFilePath, this.designAutoCAD); |
1019 |
ShowAutoCADFile(dwgFilePath, this.designCompare); |
1020 |
|
1021 |
string AVEVAPIDFolder = Program.AVEVAPIDFolder; |
1022 |
string AVEVAPIDFilePath = string.Empty; |
1023 |
if (AVEVAPIDFolder != null) |
1024 |
{ |
1025 |
AVEVAPIDFilePath = System.IO.Path.Combine(AVEVAPIDFolder, $"{doc.DocumentNo}{dwgExtension}"); |
1026 |
if (!ResultOnly) ShowAVEVAPIDFile(AVEVAPIDFilePath, this.designAVEVA); |
1027 |
ShowAVEVAPIDFile(AVEVAPIDFilePath, this.designCompare, false); |
1028 |
} |
1029 |
|
1030 |
if (System.IO.File.Exists(dwgFilePath) && System.IO.File.Exists(AVEVAPIDFilePath)) |
1031 |
{ |
1032 |
#region 비교 작업 수행 |
1033 |
var AutoCADEntities = this.designCompare.Entities.Where(x => x.LayerName == Verification.AutoCADLayer).ToList(); |
1034 |
var AVEVAtities = this.designCompare.Entities.Where(x => x.LayerName == Verification.AVEVALayer).ToList(); |
1035 |
|
1036 |
var workunit = new Classes.CompareModelWorkUnit(this.designCompare, AutoCADEntities, AVEVAtities); |
1037 |
workunit.Tolerance = Verification.Tolerance; |
1038 |
workunit.LengthToleranceRatio = Verification.LengthToleranceRatio; |
1039 |
workunit.AutoCADDiffLayer = Verification.AutoCADDiffLayer; |
1040 |
workunit.AVEVADiffLayer = Verification.AVEVADiffLayer; |
1041 |
workunit.DiffColor = Verification.DiffColor; |
1042 |
workunit.RevCloudLayer = Verification.RevCloudLayer; |
1043 |
workunit.RevCloudColor = Verification.RevCloudColor; |
1044 |
workunit.SpecialCharacters.AddRange(Forms.ExceptLayer.SpecialCharacters); |
1045 |
workunit.Casesensitive = Casesensitive; |
1046 |
if (!this.designCompare.IsBusy && !ResultOnly) |
1047 |
{ |
1048 |
this.designCompare.StartWork(workunit); |
1049 |
} |
1050 |
else |
1051 |
{ |
1052 |
workunit.DoWork(); |
1053 |
ApplyLayers(); |
1054 |
} |
1055 |
#endregion |
1056 |
} |
1057 |
} |
1058 |
|
1059 |
/// <summary> |
1060 |
/// AVEVA에서 일치하는 Text를 찾지 못하는 경우 False를 리턴한다. |
1061 |
/// </summary> |
1062 |
/// <param name="textInfo"></param> |
1063 |
/// <returns></returns> |
1064 |
public bool Zoom(TextInfo textInfo) |
1065 |
{ |
1066 |
var TextColl = this.designAutoCAD.Entities.OfType<devDept.Eyeshot.Entities.Text>().ToList(); |
1067 |
var found = TextColl.Find(x => textInfo.DoesEquals(x)); |
1068 |
if (found != null) |
1069 |
{ |
1070 |
this.designAutoCAD.Entities.ClearSelection(); |
1071 |
found.Selected = true; |
1072 |
this.designAutoCAD.ZoomFit(new List<Entity>() { found }, true, 70); |
1073 |
this.designAutoCAD.Invalidate(); |
1074 |
|
1075 |
this.designCompare.Entities.ClearSelection(); |
1076 |
TextColl = this.designCompare.Entities.OfType<devDept.Eyeshot.Entities.Text>().ToList(); |
1077 |
found = TextColl.Find(x => textInfo.DoesEquals(x)); |
1078 |
if(found != null) found.Selected = true; |
1079 |
|
1080 |
this.designAVEVA.Entities.ClearSelection(); |
1081 |
TextColl = this.designAVEVA.Entities.OfType<devDept.Eyeshot.Entities.Text>().ToList(); |
1082 |
found = TextColl.Find(x => textInfo.DoesEquals(x, Tolerance)); |
1083 |
if (found != null) |
1084 |
{ |
1085 |
found.Selected = true; |
1086 |
return true; |
1087 |
} |
1088 |
} |
1089 |
|
1090 |
return false; |
1091 |
} |
1092 |
|
1093 |
#region Camera Sync |
1094 |
private void CameraChanged(object sender, devDept.Eyeshot.Workspace.CameraMoveEventArgs e) |
1095 |
{ |
1096 |
if (sender == this.designAutoCAD) |
1097 |
{ |
1098 |
SyncCamera(this.designAutoCAD, this.designAVEVA); |
1099 |
SyncCamera(this.designAutoCAD, this.designCompare); |
1100 |
} |
1101 |
else if (sender == this.designAVEVA) |
1102 |
{ |
1103 |
SyncCamera(this.designAVEVA, this.designAutoCAD); |
1104 |
SyncCamera(this.designAVEVA, this.designCompare); |
1105 |
} |
1106 |
else |
1107 |
{ |
1108 |
SyncCamera(this.designCompare, this.designAutoCAD); |
1109 |
SyncCamera(this.designCompare, this.designAVEVA); |
1110 |
} |
1111 |
} |
1112 |
|
1113 |
private void SyncCamera(Design designMovedCamera, Design designCameraToMove) |
1114 |
{ |
1115 |
Camera savedCamera; |
1116 |
designMovedCamera.SaveView(out savedCamera); |
1117 |
|
1118 |
// restores the camera to the other model |
1119 |
designCameraToMove.RestoreView(savedCamera); |
1120 |
designCameraToMove.AdjustNearAndFarPlanes(); |
1121 |
designCameraToMove.Invalidate(); |
1122 |
} |
1123 |
#endregion |
1124 |
} |
1125 |
} |