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