프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Compare / Controls / Verification.cs @ 1018a498

이력 | 보기 | 이력해설 | 다운로드 (82.7 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.Data;
9
using System.Drawing;
10
using System.IO;
11
using System.Linq;
12
using System.Runtime.InteropServices;
13
using System.Text;
14
using System.Threading.Tasks;
15
using System.Windows.Forms;
16
using Telerik.WinControls;
17
using Telerik.WinControls.UI;
18
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
19
using Telerik.Windows.Documents.Fixed.Model;
20
using Telerik.Windows.Documents.Fixed.Model.Editing;
21

    
22
namespace ID2.Manager.Controls
23
{
24
    public partial class Verification : UserControl
25
    {
26
        readonly string IniFilePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), 
27
            Application.ProductName, $"{Application.ProductName}.ini");
28

    
29
        #region 기본값
30
        private static string AutoCADLayer { get; } = "AutoCAD";
31
        private static string AutoCADDiffLayer { get; } = "AutoCAD_Diff";
32
        private static string AutoCADExceptLayer { get; } = "AutoCAD_Except";
33
        private static Color AutoCADColor = Color.FromArgb(44, 44, 44);
34
        private static string AVEVALayer { get; } = "AVEVA";
35
        private static string AVEVADiffLayer { get; } = "AVEVA_Diff";
36
        private static string AVEVAExceptLayer { get; } = "AVEVA_Except";
37
        private static Color AVEVAColor = Color.FromArgb(44, 44, 44);
38
        private static string RevCloudLayer { get; } = "RevCloud";
39
        private static Color RevCloudColor = Color.Magenta;
40
        private static Color DiffColor = Color.Yellow;
41
        
42
        private static double Tolerance = 0;
43
        private static double LengthToleranceRatio { get; set; } = 0.1;
44
        #endregion
45

    
46
        private RadProgressBarElement _progressBar = null;
47

    
48
        public Verification(RadProgressBarElement progressBar)
49
        {
50
            InitializeComponent();
51

    
52
            this.Load += Verification_Load;
53
            this.radSpinEditorTolerance.ValueChanged += RadSpinEditorTolerance_ValueChanged;
54
            this.radColorBoxAutoCADColor.ValueChanged += RadColorBoxAutoCADColor_ValueChanged;
55
            this.radColorBoxAVEVAColor.ValueChanged += RadColorBoxAVEVAColor_ValueChanged;
56
            this.radColorBoxDiffColor.ValueChanged += RadColorBoxDiffColor_ValueChanged;
57
            this.radColorBoxRevCloudColor.ValueChanged += RadColorBoxRevCloudColor_ValueChanged;
58

    
59
            this.designAutoCAD.ActionMode = actionType.SelectVisibleByPickDynamic;
60
            this.designAutoCAD.ActiveViewport.CoordinateSystemIcon.Visible = false;
61
            this.designAutoCAD.Selection.ColorDynamic = Color.FromArgb(80, Color.OrangeRed);
62
            this.designAutoCAD.Selection.HaloInnerColor = Color.FromArgb(255, Color.OrangeRed);
63
            this.designAutoCAD.Selection.HaloOuterColor = Color.FromArgb(64, Color.OrangeRed);
64
            this.designAutoCAD.Selection.HaloWidthPolygons = 4;
65
            this.designAutoCAD.Selection.HaloWidthWires = 2;
66
            this.designAutoCAD.ActiveViewport.OriginSymbol.Visible = false;
67
            this.designAutoCAD.SetView(viewType.Trimetric);
68

    
69
            this.designAVEVA.ActionMode = actionType.SelectVisibleByPickDynamic;
70
            this.designAVEVA.ActiveViewport.CoordinateSystemIcon.Visible = false;
71
            this.designAVEVA.ActiveViewport.OriginSymbol.Visible = false;
72
            this.designCompare.ActionMode = actionType.SelectVisibleByPickDynamic;
73
            this.designCompare.ActiveViewport.CoordinateSystemIcon.Visible = false;
74
            this.designCompare.ActiveViewport.OriginSymbol.Visible = false;
75

    
76
            this.radCheckedDropDownListAutoCAD.ItemCheckedChanged += RadCheckedDropDownListAutoCAD_ItemCheckedChanged;
77
            this.radCheckedDropDownListAVEVA.ItemCheckedChanged += RadCheckedDropDownListAVEVA_ItemCheckedChanged;
78
            this.radCheckBoxRevCloud.CheckStateChanged += RadCheckBoxRevCloud_CheckStateChanged;
79

    
80
            _progressBar = progressBar;
81

    
82
            #region Camera Sync
83
            this.designAutoCAD.ActiveViewport.Rotate.Enabled = false;
84
            this.designAVEVA.ActiveViewport.Rotate.Enabled = false;
85
            this.designCompare.ActiveViewport.Rotate.Enabled = false;
86

    
87
            this.designAutoCAD.ActiveViewport.ViewCubeIcon.Visible = false;
88
            this.designAVEVA.ActiveViewport.ViewCubeIcon.Visible = false;
89
            this.designCompare.ActiveViewport.ViewCubeIcon.Visible = false;
90

    
91
            this.designAutoCAD.AnimateCamera = false;
92
            this.designAVEVA.AnimateCamera = false;
93
            this.designCompare.AnimateCamera = false;
94

    
95
            this.designAutoCAD.CameraChangedFrequency = 200;
96
            this.designAVEVA.CameraChangedFrequency = 200;
97
            this.designCompare.CameraChangedFrequency = 200;
98

    
99
            this.designAutoCAD.CameraChanged += CameraChanged;
100
            this.designAVEVA.CameraChanged += CameraChanged;
101
            this.designCompare.CameraChanged += CameraChanged;
102
            #endregion
103
        }
104

    
105
        private void RadCheckedDropDownListAVEVA_ItemCheckedChanged(object sender, RadCheckedListDataItemEventArgs e)
106
        {
107
            var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == e.Item.Text.ToUpper());
108
            if (layer != null) layer.Visible = e.Item.Checked;
109
            this.designCompare.Invalidate();
110

    
111
            Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", e.Item.Text, e.Item.Checked.ToString());
112
        }
113

    
114
        private void RadCheckedDropDownListAutoCAD_ItemCheckedChanged(object sender, RadCheckedListDataItemEventArgs e)
115
        {
116
            var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == e.Item.Text.ToUpper());
117
            if (layer != null) layer.Visible = e.Item.Checked;
118
            this.designCompare.Invalidate();
119

    
120
            Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", e.Item.Text, e.Item.Checked.ToString());
121
        }
122

    
123
        private void RadCheckBoxRevCloud_CheckStateChanged(object sender, EventArgs e)
124
        {
125
            var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.RevCloudLayer.ToUpper());
126
            if (layer != null) layer.Visible = (sender as RadCheckBox).Checked;
127
            this.designCompare.Invalidate();
128
        }
129

    
130
        private void RadCheckBoxAVEVA_CheckStateChanged(object sender, EventArgs e)
131
        {
132
            var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AVEVALayer.ToUpper());
133
            if (layer != null) layer.Visible = (sender as RadCheckBox).Checked;
134
            this.designCompare.Invalidate();
135
        }
136

    
137
        /// <summary>
138
        /// Cloud Mark의 색상을 설정한다.
139
        /// </summary>
140
        /// <param name="sender"></param>
141
        /// <param name="e"></param>
142
        private void RadColorBoxRevCloudColor_ValueChanged(object sender, EventArgs e)
143
        {
144
            Verification.RevCloudColor = this.radColorBoxRevCloudColor.Value;
145
            string color = $"{Verification.RevCloudColor.R},{Verification.RevCloudColor.G},{Verification.RevCloudColor.B}";
146
            Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "RevCloudColor", color);
147
        }
148

    
149
        /// <summary>
150
        /// 두 도면을 비교하여 결과를 PDF로 출력한다.
151
        /// </summary>
152
        /// <param name="sender"></param>
153
        /// <param name="e"></param>
154
        public void CompareDrawings(IList<Document> docs, bool Save = false)
155
        {
156
            string FileFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), 
157
                Application.ProductName, "Compare");
158
            if (!System.IO.Directory.Exists(FileFolder)) System.IO.Directory.CreateDirectory(FileFolder);
159

    
160
            try
161
            {
162
                Size? size = new Size();
163
                RadFixedDocument FixedDoc = null;
164
                if (Save)
165
                {
166
                    size = new Size(1920 * 2, 1080 * 2);
167
                    FixedDoc = new RadFixedDocument();
168

    
169
                    designCompare.ActiveViewport.Background.BottomColor = Color.White;
170
                    designCompare.ActiveViewport.Background.TopColor = Color.White;
171
                }
172

    
173
                _progressBar.Maximum = docs.Count();
174
                _progressBar.Value1 = 0;
175
                foreach (var doc in docs)
176
                {
177
                    _progressBar.Text = doc.DocumentNo;
178
                    CompareDrawing(doc, Save);
179

    
180
                    if (Save)
181
                    {
182
                        using (var bmp = this.designCompare.RenderToBitmap(size.Value))
183
                        {
184
                            string FilePath = System.IO.Path.Combine(FileFolder, $"{doc.DocumentNo}.jpg");
185
                            bmp.Save(FilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
186

    
187
                            var page = FixedDoc.Pages.AddPage();
188
                            page.Size = new Telerik.Documents.Primitives.Size(size.Value.Width, size.Value.Height);
189
                            var editor = new FixedContentEditor(page);
190
                            using (FileStream fs = new FileStream(FilePath, FileMode.Open))
191
                            {
192
                                editor.DrawImage(fs);
193
                            }
194
                        }
195
                    }
196

    
197
                    _progressBar.Value1 += 1;
198
                    Application.DoEvents();
199
                }
200

    
201
                if (Save)
202
                {
203
                    RadSaveFileDialog saveFileDialog = new RadSaveFileDialog()
204
                    {
205
                        Filter = "PDF files (*.pdf)|*.pdf",
206
                        RestoreDirectory = true
207
                    };
208
                    if (System.Windows.Forms.DialogResult.OK == saveFileDialog.ShowDialog())
209
                    {
210
                        string selectedFileName = saveFileDialog.FileName;
211

    
212
                        // 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: 
213
                        Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver();
214
                        Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver;
215

    
216
                        var provider = new PdfFormatProvider();
217
                        File.WriteAllBytes(selectedFileName, provider.Export(FixedDoc));
218

    
219
                        RadMessageBox.Show("Comparing document is done");
220
                    }
221
                }
222
            }
223
            catch(Exception ex)
224
            {
225
                RadMessageBox.Show(ex.Message);
226
            }
227
            finally
228
            {
229
                designCompare.ActiveViewport.Background.BottomColor = Color.Black;
230
                designCompare.ActiveViewport.Background.TopColor = Color.Black;
231
            }
232
        }
233

    
234
        /// <summary>
235
        /// 서로 다른 엔터티의 색상을 설정한다.
236
        /// </summary>
237
        /// <param name="sender"></param>
238
        /// <param name="e"></param>
239
        private void RadColorBoxDiffColor_ValueChanged(object sender, EventArgs e)
240
        {
241
            Verification.DiffColor = this.radColorBoxDiffColor.Value;
242
            string color = $"{Verification.DiffColor.R},{Verification.DiffColor.G},{Verification.DiffColor.B}";
243
            Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "DiffColor", color);
244
        }
245

    
246
        /// <summary>
247
        /// AutoCAD 엔터티의 색상을 설정한다.
248
        /// </summary>
249
        /// <param name="sender"></param>
250
        /// <param name="e"></param>
251
        private void RadColorBoxAutoCADColor_ValueChanged(object sender, EventArgs e)
252
        {
253
            Verification.AutoCADColor = this.radColorBoxAutoCADColor.Value;
254
            string color = $"{Verification.AutoCADColor.R},{Verification.AutoCADColor.G},{Verification.AutoCADColor.B}";
255
            Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "AutoCADColor", color);
256
        }
257

    
258
        /// <summary>
259
        /// AVEVA 엔터티의 색상을 설정한다.
260
        /// </summary>
261
        /// <param name="sender"></param>
262
        /// <param name="e"></param>
263
        private void RadColorBoxAVEVAColor_ValueChanged(object sender, EventArgs e)
264
        {
265
            Verification.AVEVAColor = this.radColorBoxAVEVAColor.Value;
266
            string color = $"{Verification.AVEVAColor.R},{Verification.AVEVAColor.G},{Verification.AVEVAColor.B}";
267
            Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "AVEVAColor", color);
268
        }
269

    
270
        /// <summary>
271
        /// 수정한 Tolerance를 시스템에 반영한다.
272
        /// </summary>
273
        /// <param name="sender"></param>
274
        /// <param name="e"></param>
275
        private void RadSpinEditorTolerance_ValueChanged(object sender, EventArgs e)
276
        {
277
            double toler = Convert.ToDouble(this.radSpinEditorTolerance.Value);
278
            Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "Tolerance", toler.ToString());
279
            Verification.Tolerance = toler;
280
        }
281

    
282
        private void Verification_Load(object sender, EventArgs e)
283
        {
284
            string Toler = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Tolerance");
285
            if (!string.IsNullOrEmpty(Toler))
286
            {
287
                this.radSpinEditorTolerance.Value = Convert.ToDecimal(Toler);
288
                Verification.Tolerance = Convert.ToDouble(this.radSpinEditorTolerance.Value);
289
            }
290

    
291
            string _AutoCADLayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AutoCADLayer);
292
            if (!string.IsNullOrEmpty(_AutoCADLayer))
293
            {
294
                bool Checked = Convert.ToBoolean(_AutoCADLayer);
295
                var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text == Verification.AutoCADLayer);
296
                if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked; 
297
            }
298

    
299
            string _AutoCADDiffLayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AutoCADDiffLayer);
300
            if (!string.IsNullOrEmpty(_AutoCADDiffLayer))
301
            {
302
                bool Checked = Convert.ToBoolean(_AutoCADDiffLayer);
303
                var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text == Verification.AutoCADDiffLayer);
304
                if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked;
305
            }
306

    
307
            string _AutoCADColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "AutoCADColor");
308
            if (!string.IsNullOrEmpty(_AutoCADColor))
309
            {
310
                var tokens = _AutoCADColor.Split(',');
311
                if (tokens.Length == 3)
312
                {
313
                    this.radColorBoxAutoCADColor.Value =
314
                         Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2]));
315
                }
316
            }
317

    
318
            string _AVEVALayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AVEVALayer);
319
            if (!string.IsNullOrEmpty(_AutoCADLayer))
320
            {
321
                bool Checked = Convert.ToBoolean(_AVEVALayer);
322
                var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text == Verification.AVEVALayer);
323
                if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked;
324
            }
325

    
326
            string _AVEVADiffLayer = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", Verification.AVEVADiffLayer);
327
            if (!string.IsNullOrEmpty(_AVEVADiffLayer))
328
            {
329
                bool Checked = Convert.ToBoolean(_AVEVADiffLayer);
330
                var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text == Verification.AVEVADiffLayer);
331
                if (item is RadCheckedListDataItem CheckedItem) CheckedItem.Checked = Checked;
332
            }
333

    
334
            string _AVEVAColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "AVEVAColor");
335
            if (!string.IsNullOrEmpty(_AVEVAColor))
336
            {
337
                var tokens = _AVEVAColor.Split(',');
338
                if (tokens.Length == 3)
339
                {
340
                    this.radColorBoxAVEVAColor.Value =
341
                        Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2]));
342
                }
343
            }
344

    
345
            string _DiffColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "DiffColor");
346
            if (!string.IsNullOrEmpty(_DiffColor))
347
            {
348
                var tokens = _DiffColor.Split(',');
349
                if (tokens.Length == 3)
350
                {
351
                    this.radColorBoxDiffColor.Value =
352
                        Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2]));
353
                }
354
            }
355

    
356
            string _RevCloudColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "RevCloudColor");
357
            if (!string.IsNullOrEmpty(_RevCloudColor))
358
            {
359
                var tokens = _RevCloudColor.Split(',');
360
                if (tokens.Length == 3)
361
                {
362
                    this.radColorBoxRevCloudColor.Value =
363
                        Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2]));
364
                }
365
            }
366

    
367
            string _LengthToleranceRatio = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Length Tolerance Ratio");
368
            if (!string.IsNullOrEmpty(_LengthToleranceRatio))
369
            {
370
                LengthToleranceRatio = Convert.ToDouble(_LengthToleranceRatio);
371
            }
372

    
373
            string _ArrowMaxLength = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Arrow Max Length");
374
            if (!string.IsNullOrEmpty(_ArrowMaxLength))
375
            {
376
                Forms.ExceptLayer.ArrowMaxLength = Convert.ToDouble(_ArrowMaxLength);
377
            }
378

    
379
            #region Except Layer를 로딩한다.
380
            LoadLayerSettings();
381
            #endregion
382
        }
383

    
384
        /// <summary>
385
        /// 레이어 설정을 읽는다.
386
        /// </summary>
387
        public void LoadLayerSettings()
388
        {
389
            Forms.ExceptLayer.ExceptLayers.Clear();
390
            Forms.ExceptLayer.LineLayers.Clear();
391

    
392
            string _ExceptLayers = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Except Layers");
393
            if (!string.IsNullOrEmpty(_ExceptLayers))
394
            {
395
                Forms.ExceptLayer.ExceptLayers.AddRange(_ExceptLayers.Split(',').ToList().ConvertAll(x => new Forms.ExceptLayer.Layer(x)));
396

    
397
                string _ExceptLayersVisible = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Except Layers Visible");
398
                if (!string.IsNullOrEmpty(_ExceptLayersVisible))
399
                {
400
                    var tokens = _ExceptLayersVisible.Split(',').ToList().ConvertAll(x => Convert.ToBoolean(x));
401
                    for (int i = 0; i < Forms.ExceptLayer.ExceptLayers.Count; ++i)
402
                    {
403
                        if (i < tokens.Count)
404
                        {
405
                            Forms.ExceptLayer.ExceptLayers[i].Visible = tokens[i];
406
                        }
407
                    }
408
                }
409
            }
410

    
411
            string _LineLayers = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Line Layers");
412
            if (!string.IsNullOrEmpty(_LineLayers))
413
            {
414
                Forms.ExceptLayer.LineLayers.AddRange(_LineLayers.Split(',').ToList().ConvertAll(x => new Forms.ExceptLayer.Layer(x)));
415
            }
416
        }
417

    
418
        /// <summary>
419
        /// 엔터티들의 색상을 바꾼다.
420
        /// </summary>
421
        /// <param name="design"></param>
422
        /// <param name="list"></param>
423
        public void ColorEntities(Design design, IList<Entity> list, Color color, colorMethodType colorMethod=colorMethodType.byEntity, bool ChangeBlkColor=true)
424
        {
425
            foreach (Entity ent in list)
426
            {
427
                ColorEntity(design, ent, color, colorMethod, ChangeBlkColor);
428
            }
429
        }
430

    
431
        /// <summary>
432
        /// 엔터티의 색상을 변경한다.
433
        /// </summary>
434
        /// <param name="design"></param>
435
        /// <param name="entity"></param>
436
        /// <param name="color"></param>
437
        private void ColorEntity(Design design, Entity entity, Color color, colorMethodType colorMethod = colorMethodType.byEntity, 
438
            bool ChangeBlkColor = true)
439
        {
440
            if (entity is BlockReference blkref)
441
            {
442
                blkref.Color = color;
443
                blkref.ColorMethod = colorMethod;
444

    
445
                if (ChangeBlkColor)
446
                {
447
                    var blk = design.Blocks.FirstOrDefault(x => x.Name == blkref.BlockName);
448
                    if (blk != null)
449
                    {
450
                        ColorEntities(design, blk.Entities, color, colorMethodType.byParent);
451
                        foreach (var attr in blkref.Attributes.Values)
452
                        {
453
                            attr.Color = color;
454
                            attr.ColorMethod = colorMethodType.byParent;
455
                        }
456
                    }
457
                }
458
            }
459
            else
460
            {
461
                entity.Color = color;
462
                entity.ColorMethod = colorMethod;
463
            }
464
        }
465

    
466
        /// <summary>
467
        /// 블럭 참조를 깨어 블럭의 구성 요소들을 리트스트 리턴한다.
468
        /// </summary>
469
        /// <param name="design"></param>
470
        /// <param name="blkref"></param>
471
        /// <param name="LayerName"></param>
472
        /// <param name="color"></param>
473
        /// <returns></returns>
474
        private List<Entity> ExplodeBlockReference(BlockKeyedCollection Blocks, BlockReference blkref, string LayerName, Color color)
475
        {
476
            var res = new List<Entity>();
477

    
478
            var entities = blkref.Explode(Blocks);
479
            entities.ToList().ForEach(y =>
480
            {
481
                #region 블럭 이름이 ARROW로 시작되는 경우 Hatch로 화살표를 그려준다.
482
                if (y is LinearPath arrow && arrow.Vertices.Length == 2 && blkref.BlockName.StartsWith("ARROW"))
483
                {
484
                    double weight = arrow.LineWeight * blkref.GetScaleFactorY();
485
                    var dir = new devDept.Geometry.Vector3D(arrow.Vertices[0], arrow.Vertices[1]);
486
                    dir.Normalize();
487
                    var cross = devDept.Geometry.Vector3D.Cross(devDept.Geometry.Vector3D.AxisZ, dir);
488
                    var pts = new devDept.Geometry.Point3D[]
489
                    {
490
                        arrow.Vertices[1] + cross * weight * 0.5,
491
                        arrow.Vertices[0],
492
                        arrow.Vertices[1] - cross * weight * 0.5
493
                    };
494

    
495
                    var hatch = new Hatch("SOLID", new List<ICurve>() { new LinearPath(pts)});
496
                    res.Add(hatch);
497
                }
498
                #endregion
499
                else if (y is LinearPath lp)
500
                {
501
                    int count = Convert.ToInt32(lp.Vertices.Length);
502
                    for (int i = 0; i < count - 1; ++i)
503
                    {
504
                        var line = new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1])
505
                        {
506
                            LayerName = lp.LayerName,
507
                            LineWeight = lp.LineWeight,
508
                            LineTypeMethod = colorMethodType.byEntity,
509
                            Color = lp.Color,
510
                            ColorMethod = colorMethodType.byEntity
511
                        };
512
                        res.Add(line);
513
                    }
514
                }
515
                /// PORT, ARROW로 시작하는 블럭은 제외
516
                else if(y is BlockReference subblkref && subblkref.BlockName != "PORT")
517
                {
518
                    res.AddRange(ExplodeBlockReference(Blocks, subblkref, LayerName, color));
519
                }
520
            });
521

    
522
            var attributes = blkref.Attributes;
523
            foreach (var ent in entities.Where(y => y is devDept.Eyeshot.Entities.Attribute attr && !attr.Invisible))
524
            {
525
                var txt = ent as devDept.Eyeshot.Entities.Attribute;
526
                #region 텍스트가 뒤집어지는 것을 방지하기 위해 평면을 교체
527
                if (txt.Plane.AxisX.Equals(devDept.Geometry.Vector3D.AxisMinusX) && txt.Plane.AxisY.Equals(devDept.Geometry.Vector3D.AxisY))
528
                {
529
                    txt.Plane = new devDept.Geometry.Plane(txt.Plane.Origin, devDept.Geometry.Vector3D.AxisX, devDept.Geometry.Vector3D.AxisY);
530
                }
531
                #endregion
532
                txt.LayerName = LayerName;
533
                txt.Color = color;
534
                txt.ColorMethod = colorMethodType.byEntity;
535
                KeyValuePair<string, AttributeReference>? kp = attributes.FirstOrDefault(z => z.Key == txt.TextString);
536
                if (kp.HasValue) txt.TextString = (kp.Value.Value) != null ? kp.Value.Value.Value : string.Empty;
537
            }
538

    
539
            res.AddRange(entities.Where(y =>
540
            {
541
                if (y is devDept.Eyeshot.Entities.Attribute attr && (string.IsNullOrEmpty(attr.TextString) || attr.Invisible)) return false;
542
                if (y is devDept.Eyeshot.Entities.Text text && string.IsNullOrEmpty(text.TextString)) return false;
543
                if (y is devDept.Eyeshot.Entities.Point) return false;
544
                if (y is BlockReference subblkref) return false;
545
                if (y is LinearPath) return false;
546
                if (y.LayerName.ToUpper() == "AS_PORT") return false;
547
                return true;
548
            }));
549

    
550
            #region 제외 레이어에 속한 항목은 포함하지 않는다.
551
            res.RemoveAll(x =>
552
            {
553
                return Forms.ExceptLayer.ExceptLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper() && !y.Visible);
554
            });
555
            #endregion
556
            foreach (var ent in res) ent.LayerName = LayerName;
557

    
558
            blkref.Attributes.Clear();
559
            ///blkref.UpdateBoundingBox(new TraversalParams(design));
560

    
561
            return res;
562
        }
563

    
564
        /// <summary>
565
        /// 주어진 도면의 원본과 AVEVA를 비교한다.
566
        /// </summary>
567
        private void CompareDrawing(Document doc, bool ResultOnly = false)
568
        {
569
            /// AutoCAD P&ID 파일을 화면에 표시한다.
570
            void ShowAutoCADFile(string FilePath, Design design, bool clear = true)
571
            {
572
                if (clear) design.Clear();
573
                var AddEntities = new List<Entity>();
574

    
575
                if (System.IO.File.Exists(FilePath))
576
                {
577
                    try
578
                    {
579
                        #region 다른 프로세스에서 파일을 열고 있는 경우 처리
580
                        using (var fs = File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
581
                        #endregion
582

    
583
                        {
584
                            devDept.Eyeshot.Translators.ReadAutodesk ra = new devDept.Eyeshot.Translators.ReadAutodesk(fs);
585
                            ra.DoWork();
586
                            var min = ra.Min;
587
                            if (!ra.Layers.Contains(Verification.AutoCADLayer)) ra.Layers.Add(Verification.AutoCADLayer, Verification.AutoCADColor);
588
                            if (!ra.Layers.Contains(Verification.AutoCADDiffLayer)) ra.Layers.Add(Verification.AutoCADDiffLayer, Verification.DiffColor);
589
                            if (!ra.Layers.Contains(Verification.AutoCADExceptLayer)) ra.Layers.Add(Verification.AutoCADExceptLayer, Verification.AutoCADColor);
590
                            foreach (var ent in ra.Entities)
591
                            {
592
                                /// 도면을 원점으로 맞춘다.
593
                                if (min.X != 0 && min.Y != 0) ent.Translate(-min.X, -min.Y);
594

    
595
                                if (ent is BlockReference blkref)
596
                                {
597
                                    AddEntities.AddRange(ExplodeBlockReference(ra.Blocks, blkref, Verification.AutoCADLayer, Verification.AutoCADColor));
598
                                }
599
                            }
600
                            ra.AddToScene(design);
601
                        }
602
                    }
603
                    catch (Exception ex)
604
                    {
605
                        RadMessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, RadMessageIcon.Error);
606
                        return;
607
                    }
608

    
609
                    #region LinearPath를 Line으로 분할한다.
610
                    design.Entities.ForEach(x =>
611
                    {
612
                        if (x is LinearPath lp)
613
                        {
614
                            #region 정점 수가 2이고 LineWeight이 0 초과이고 길이가 ArrowMaxLength보다 작을때 화살표를 그려준다.
615
                            if (lp.Vertices.Count() == 2 && lp.LineWeight > 0 && lp.Length() < Forms.ExceptLayer.ArrowMaxLength)
616
                            {
617
                                double weight = lp.LineWeight;
618
                                var dir = new devDept.Geometry.Vector3D(lp.Vertices[0], lp.Vertices[1]);
619
                                dir.Normalize();
620
                                var cross = devDept.Geometry.Vector3D.Cross(devDept.Geometry.Vector3D.AxisZ, dir);
621
                                var pts = new devDept.Geometry.Point3D[]
622
                                {
623
                                    lp.Vertices[1] + cross * weight * 0.5,
624
                                    lp.Vertices[0],
625
                                    lp.Vertices[1] - cross * weight * 0.5
626
                                };
627

    
628
                                var hatch = new Hatch("SOLID", new List<ICurve>() { new LinearPath(pts) });
629
                                AddEntities.Add(hatch);
630
                            }
631
                            #endregion
632
                            else
633
                            {
634
                                int count = Convert.ToInt32(lp.Vertices.Length);
635
                                for (int i = 0; i < count - 1; ++i)
636
                                {
637
                                    AddEntities.Add(new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1])
638
                                    {
639
                                        LayerName = lp.LayerName,
640
                                        LineWeight = lp.LineWeight,
641
                                        LineTypeMethod = colorMethodType.byEntity
642
                                    });
643
                                }
644
                            }
645
                        }
646
                    });
647
                    design.Entities.RemoveAll(x => (x is LinearPath));
648
                    #endregion
649

    
650
                    design.Entities.AddRange(AddEntities);
651

    
652
                    #region 브랜치가 생성되는 부분에서 파이프 라인을 분할
653
                    var queue = design.Entities.Where(x => x is Line && 
654
                    Forms.ExceptLayer.LineLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper())).ToList();
655
                    while (queue.Any())
656
                    {
657
                        var line1 = queue.First() as Line;
658
                        var dir1 = line1.Direction;
659
                        dir1.Normalize();
660
                        queue.Remove(line1);
661
                        for (int i = 0; i < queue.Count; ++i)
662
                        {
663
                            var line2 = queue.ElementAt(i) as Line;
664
                            var dir2 = line2.Direction;
665
                            dir2.Normalize();
666
                            if (devDept.Geometry.Vector3D.AreOrthogonal(dir1, dir2))
667
                            {
668
                                var intersects = line1.IntersectWith(line2);
669
                                if (intersects.Count() == 1)
670
                                {
671
                                    if (line1.StartPoint.DistanceTo(intersects[0]) > 0.1 && line1.EndPoint.DistanceTo(intersects[0]) > 0.1)
672
                                    {
673
                                        var split1 = new devDept.Eyeshot.Entities.Line(line1.StartPoint, intersects[0])
674
                                        {
675
                                            LayerName = line1.LayerName,
676
                                            LineWeight = line1.LineWeight,
677
                                            LineTypeMethod = colorMethodType.byEntity
678
                                        };
679
                                        var split2 = new devDept.Eyeshot.Entities.Line(intersects[0], line1.EndPoint)
680
                                        {
681
                                            LayerName = line1.LayerName,
682
                                            LineWeight = line1.LineWeight,
683
                                            LineTypeMethod = colorMethodType.byEntity
684
                                        };
685
                                        design.Entities.Add(split1);
686
                                        design.Entities.Add(split2);
687
                                        design.Entities.Remove(line1);
688

    
689
                                        queue.Add(split1);
690
                                        queue.Add(split2);
691

    
692
                                        break;
693
                                    }
694

    
695
                                    if (line2.StartPoint.DistanceTo(intersects[0]) > 0.1 && line2.EndPoint.DistanceTo(intersects[0]) > 0.1)
696
                                    {
697
                                        var split1 = new devDept.Eyeshot.Entities.Line(line2.StartPoint, intersects[0])
698
                                        {
699
                                            LayerName = line2.LayerName,
700
                                            LineWeight = line2.LineWeight,
701
                                            LineTypeMethod = colorMethodType.byEntity
702
                                        };
703
                                        var split2 = new devDept.Eyeshot.Entities.Line(intersects[0], line2.EndPoint)
704
                                        {
705
                                            LayerName = line2.LayerName,
706
                                            LineWeight = line2.LineWeight,
707
                                            LineTypeMethod = colorMethodType.byEntity
708
                                        };
709
                                        design.Entities.Add(split1);
710
                                        design.Entities.Add(split2);
711
                                        design.Entities.Remove(line2);
712

    
713
                                        queue.Remove(line2);
714
                                        queue.Add(split1);
715
                                        queue.Add(split2);
716
                                    }
717
                                }
718
                            }
719
                        }
720
                    }
721
                    #endregion
722

    
723
                    #region 레이어 변경
724
                    foreach (var ent in design.Entities)
725
                    {
726
                        ent.Color = Verification.AutoCADColor;
727
                        ent.ColorMethod = colorMethodType.byEntity;
728
                        if (!Forms.ExceptLayer.ExceptLayers.Exists(x => x.Name.ToUpper() == ent.LayerName.ToUpper()))
729
                        {
730
                            ent.LayerName = Verification.AutoCADLayer;
731
                        }
732
                        else
733
                        {
734
                            ent.LayerName = Verification.AutoCADExceptLayer;
735
                        }
736
                    }
737
                    #endregion
738

    
739
                    #region 블럭이거나 제외 레이어에 속한 항목은 제거
740
                    design.Entities.RemoveAll(x => (x is BlockReference) || Forms.ExceptLayer.ExceptLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper() && !y.Visible));
741
                    #endregion
742

    
743
                    #region 눈에 보이지 않는 라인은 제거
744
                    design.Entities.RemoveAll(x => x is Line line && line.Length() < 0.001);
745
                    #endregion
746

    
747
                    ColorEntities(design, design.Entities, Verification.AutoCADColor);
748

    
749
                    // Sets the view as Top
750
                    design.SetView(viewType.Top);
751
                    design.ZoomFit();
752
                    design.Invalidate();
753
                }
754
            }
755

    
756
            /// AVEVA P&ID 파일을 화면에 표시한다.
757
            void ShowAVEVAPIDFile(string FilePath, Design design, bool clear = true)
758
            {
759
                if (clear) design.Clear();
760
                if (System.IO.File.Exists(FilePath))
761
                {
762
                    var AddEntities = new List<Entity>();
763

    
764
                    #region 다른 프로세스에서 파일을 열고 있는 경우 처리
765
                    using (var fs = File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
766
                    #endregion
767
                    {
768
                        devDept.Eyeshot.Translators.ReadAutodesk ra = new devDept.Eyeshot.Translators.ReadAutodesk(fs);
769
                        ra.DoWork();
770

    
771
                        if (!ra.Layers.Contains(Verification.AVEVALayer)) ra.Layers.Add(Verification.AVEVALayer, Verification.AVEVAColor);
772
                        if (!ra.Layers.Contains(Verification.AVEVADiffLayer)) ra.Layers.Add(Verification.AVEVADiffLayer, Verification.DiffColor);
773
                        if (!ra.Layers.Contains(Verification.AVEVAExceptLayer)) ra.Layers.Add(Verification.AVEVAExceptLayer, Verification.AVEVAColor);
774
                        var min = ra.Min;
775
                        foreach (var ent in ra.Entities)
776
                        {
777
                            /// 도면을 원점으로 맞춘다.
778
                            if (min.X != 0 && min.Y != 0) ent.Translate(-min.X, -min.Y);
779

    
780
                            #region 멀티 라인들을 분할하여 추가한다.
781
                            if (ent is Mesh mesh && (mesh.LayerName == "AS_PIPE" || mesh.LayerName == "AS_INST"))
782
                            {
783
                                int count = Convert.ToInt32(mesh.Vertices.Length * 0.5);
784
                                for (int i = 0; i < count - 1; ++i)
785
                                {
786
                                    AddEntities.Add(new devDept.Eyeshot.Entities.Line(mesh.Vertices[i], mesh.Vertices[i + 1])
787
                                    {
788
                                        LayerName = Verification.AVEVALayer,
789
                                        LineWeight = 3.0f,
790
                                        LineTypeMethod = colorMethodType.byEntity,
791
                                        Color = Verification.AVEVAColor,
792
                                        ColorMethod = colorMethodType.byEntity
793
                                    });
794
                                }
795
                            }
796
                            else if (ent is TabulatedSurface tf && (tf.LayerName == "AS_PIPE" || tf.LayerName == "AS_INST"))
797
                            {
798
                                int count = Convert.ToInt32(tf.ControlPoints.Length * 0.5);
799
                                for (int i = 0; i < count - 1; ++i)
800
                                {
801
                                    AddEntities.Add(
802
                                        new devDept.Eyeshot.Entities.Line(
803
                                        new devDept.Geometry.Point3D(tf.ControlPoints[i, 0].X, tf.ControlPoints[i, 0].Y, 0),
804
                                        new devDept.Geometry.Point3D(tf.ControlPoints[i + 1, 0].X, tf.ControlPoints[i + 1, 0].Y, 0))
805
                                        {
806
                                            LayerName = Verification.AVEVALayer,
807
                                            LineWeight = 3.0f,
808
                                            LineTypeMethod = colorMethodType.byEntity,
809
                                            Color = Verification.AVEVAColor,
810
                                            ColorMethod = colorMethodType.byEntity
811
                                        }
812
                                    );
813
                                }
814
                            }
815
                            else if (ent is LinearPath lp)
816
                            {
817
                                string LayerName = Forms.ExceptLayer.ExceptLayers.Exists(x => x.Name.ToUpper() == lp.LayerName.ToUpper()) ?
818
                                    Verification.AVEVAExceptLayer : Verification.AVEVALayer;
819
                                int count = Convert.ToInt32(lp.Vertices.Length);
820
                                for (int i = 0; i < count - 1; ++i)
821
                                {
822
                                    AddEntities.Add(new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1])
823
                                    {
824
                                        LayerName = LayerName,
825
                                        LineWeight = lp.LineWeight,
826
                                        Color = Verification.AVEVAColor,
827
                                        LineTypeMethod = colorMethodType.byEntity
828
                                    });
829
                                }
830

    
831
                                #region 밑에서 제거하기 위해 레이어를 AVEVALayer로 바꿔준다.
832
                                lp.LayerName = Verification.AVEVALayer;
833
                                #endregion
834
                            }
835
                            #endregion
836
                            else if (ent is BlockReference blkref)
837
                            {
838
                                if (blkref.BlockName != "LBRK" && blkref.BlockName != "PSNODE" && blkref.BlockName != "PENODE")
839
                                {
840
                                    AddEntities.AddRange(ExplodeBlockReference(ra.Blocks, blkref, Verification.AVEVALayer, Verification.AVEVAColor));
841
                                }
842
                            }
843

    
844
                            ent.Color = Verification.AVEVAColor;
845
                            ent.ColorMethod = colorMethodType.byEntity;
846
                            if (!Forms.ExceptLayer.ExceptLayers.Exists(x => x.Name.ToUpper() == ent.LayerName.ToUpper()))
847
                            {
848
                                ent.LayerName = Verification.AVEVALayer;
849
                            }
850
                            else
851
                            {
852
                                ent.LayerName = Verification.AVEVAExceptLayer;
853
                            }
854
                        }
855
                        ra.AddToScene(design);
856
                    }
857

    
858
                    #region 불필요한 블럭들은 제거
859
                    design.Entities.RemoveAll(x => x is BlockReference);
860
                    #endregion
861

    
862
                    #region 블럭을 깸
863
                    design.Entities.Where(x => x.LayerName == Verification.AVEVALayer).ToList().ForEach(x =>
864
                    {
865
                        if(x is BlockReference blkref)
866
                        {
867
                            AddEntities.AddRange(ExplodeBlockReference(design.Blocks, blkref, Verification.AVEVALayer, Verification.AVEVAColor));
868
                        }
869
                    });
870
                    design.Entities.RemoveAll(x =>
871
                    ((x is Mesh || x is TabulatedSurface) && (x.LayerName == Verification.AVEVALayer)) ||
872
                    (x is LinearPath && x.LayerName == Verification.AVEVALayer) || (x is BlockReference) ||
873
                    Forms.ExceptLayer.ExceptLayers.Exists(y => y.Name.ToUpper() == x.LayerName.ToUpper() && !y.Visible));
874
                    design.Entities.AddRange(AddEntities);
875
                    #endregion
876

    
877
                    #region 눈에 보이지 않는 라인은 제거
878
                    design.Entities.RemoveAll(x => x is Line line && line.Length() < 0.001);
879
                    #endregion
880

    
881
                    ColorEntities(design, design.Entities.Where(x => x.LayerName == Verification.AVEVALayer).ToList(), Verification.AVEVAColor);
882

    
883
                    design.SetView(viewType.Top);
884
                    design.ZoomFit();
885
                    design.Invalidate();
886
                }
887
            }
888

    
889
            string dwgExtension = ".dwg";
890
            string ID2DrawingFolder = Program.AutoCADFolder;
891
            string dwgFilePath = System.IO.Path.Combine(ID2DrawingFolder, $"{doc.DocumentNo}{dwgExtension}");
892
            if (!ResultOnly) ShowAutoCADFile(dwgFilePath, this.designAutoCAD);
893
            ShowAutoCADFile(dwgFilePath, this.designCompare);
894

    
895
            string AVEVAPIDFolder = Program.AVEVAPIDFolder;
896
            string AVEVAPIDFilePath = string.Empty;
897
            if (AVEVAPIDFolder != null)
898
            {
899
                AVEVAPIDFilePath = System.IO.Path.Combine(AVEVAPIDFolder, $"{doc.DocumentNo}{dwgExtension}");
900
                if (!ResultOnly) ShowAVEVAPIDFile(AVEVAPIDFilePath, this.designAVEVA);
901
                ShowAVEVAPIDFile(AVEVAPIDFilePath, this.designCompare, false);
902
            }
903

    
904
            if (System.IO.File.Exists(dwgFilePath) && System.IO.File.Exists(AVEVAPIDFilePath))
905
            {
906
                var AutoCADEntities = this.designCompare.Entities.Where(x => x.LayerName == Verification.AutoCADLayer).ToList();
907
                var AVEVAtities = this.designCompare.Entities.Where(x => x.LayerName == Verification.AVEVALayer).ToList();
908
                CompareAndMark(this.designCompare, AutoCADEntities, this.designCompare, AVEVAtities);
909
            }
910

    
911
            var others = this.designCompare.Entities.Where(x =>
912
            {
913
                return (x.LayerName != Verification.AVEVALayer && x.LayerName != Verification.AVEVADiffLayer &&
914
                x.LayerName != Verification.AutoCADLayer && x.LayerName != Verification.AutoCADDiffLayer &&
915
                x.LayerName != Verification.RevCloudLayer);
916
            }).ToList();
917

    
918
            others.ForEach(x =>
919
            {
920
                if (x.LayerName == Verification.AutoCADExceptLayer)
921
                    x.LayerName = Verification.AutoCADLayer;
922
                else if (x.LayerName == Verification.AVEVAExceptLayer)
923
                    x.LayerName = Verification.AVEVALayer;
924
            });
925

    
926
            #region 레이어 설정 적용
927
            var layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.RevCloudLayer.ToUpper());
928
            if (layer != null) layer.Visible = this.radCheckBoxRevCloud.Checked;
929

    
930
            layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AVEVALayer.ToUpper());
931
            if (layer != null)
932
            {
933
                var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AVEVALayer.ToUpper());
934
                if (item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked;
935
            }
936

    
937
            layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AVEVADiffLayer.ToUpper());
938
            if (layer != null)
939
            {
940
                var item = this.radCheckedDropDownListAVEVA.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AVEVADiffLayer.ToUpper());
941
                if (item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked;
942
            }
943

    
944
            layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AutoCADLayer.ToUpper());
945
            if (layer != null) 
946
            {
947
                var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AutoCADLayer.ToUpper());
948
                if(item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked;
949
            }
950

    
951
            layer = this.designCompare.Layers.FirstOrDefault(x => x.Name.ToUpper() == Verification.AutoCADDiffLayer.ToUpper());
952
            if (layer != null)
953
            {
954
                var item = this.radCheckedDropDownListAutoCAD.Items.FirstOrDefault(x => x.Text.ToUpper() == Verification.AutoCADDiffLayer.ToUpper());
955
                if(item is RadCheckedListDataItem CheckedItem) layer.Visible = CheckedItem.Checked;
956
            }
957

    
958
            this.designCompare.Invalidate();
959
            #endregion
960
        }
961

    
962
        /// <summary>
963
        /// 주어진 두 엔터티 리스트를 비교하여 틀린 엔터티의 색상을 설정한 색상으로 변경한다.
964
        /// </summary>
965
        /// <param name="entList1"></param>
966
        /// <param name="entList2"></param>
967
        private void CompareAndMark(Design design1, IList<Entity> AutoCADEntities, Design design2, IList<Entity> AVEVAEntities)
968
        {
969
            var DiffRegions = new List<devDept.Eyeshot.OrientedBoundingRect>();
970

    
971
            bool[] equalEntitiesInV2 = new bool[AVEVAEntities.Count];
972
            var EqualIndices = new List<int>();
973

    
974
            /// 서로 검사 가능한 타입인지 확인한다.
975
            bool CheckType(Entity ent1, Entity ent2)
976
            {
977
                return ent1.GetType() == ent2.GetType() ||
978
                    (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Text) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.MultilineText)) ||
979
                    (ent1.GetType() == typeof(devDept.Eyeshot.Entities.MultilineText) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.Text)) ||
980
                    (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Line) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.TabulatedSurface)) ||
981
                    (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Attribute) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.Text)) ||
982
                    (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Attribute) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.MultilineText));
983
            }
984

    
985
            try
986
            {
987
                for (int i = 0; i < AutoCADEntities.Count(); i++)
988
                {
989
                    Entity entVp1 = AutoCADEntities[i];
990
                    EqualIndices.Clear();
991

    
992
                    for (int j = 0; j < AVEVAEntities.Count(); j++)
993
                    {
994
                        Entity entVp2 = AVEVAEntities[j];
995

    
996
                        if (entVp2 is BlockReference blkref && (blkref.BlockName == "PSNODE" || blkref.BlockName == "PENODE")) continue;
997
                        if (!equalEntitiesInV2[j] && CheckType(entVp1, entVp2) && 
998
                            CompareIfEqual(design1, entVp1, design2, entVp2))
999
                        {
1000
                            EqualIndices.Add(j);
1001
                        }
1002
                    }
1003

    
1004
                    #region 임계값 안에 들어오는 항목이 여러개 있을 경우 가장 가까운 항목을 유사 항목으로 선택한다.
1005
                    if (EqualIndices.Any())
1006
                    {
1007
                        var ordered = EqualIndices.ConvertAll(x => AVEVAEntities[x]).OrderBy(x =>
1008
                        {
1009
                            return x.BoxMin.DistanceTo(entVp1.BoxMin);
1010
                        });
1011

    
1012
                        int idx = AVEVAEntities.ToList().FindIndex(x => x == ordered.First());
1013
                        equalEntitiesInV2[idx] = true;
1014
                    }
1015
                    #endregion
1016

    
1017
                    if (!EqualIndices.Any())
1018
                    {
1019
                        AutoCADEntities[i].LayerName = Verification.AutoCADDiffLayer;
1020
                        ColorEntity(design1, AutoCADEntities[i], Verification.DiffColor, colorMethodType.byEntity, false);
1021

    
1022
                        #region 틀린 엔터티의 BoundingBox를 구함
1023
                        var origin = new devDept.Geometry.Point2D(entVp1.BoxMin.X - 1, entVp1.BoxMin.Y - 1);
1024
                        double width = entVp1.BoxMax.X - entVp1.BoxMin.X;
1025
                        double height = entVp1.BoxMax.Y - entVp1.BoxMin.Y;
1026
                        if (Math.Abs(width) != double.PositiveInfinity && Math.Abs(height) != double.PositiveInfinity)
1027
                        {
1028
                            var rect = new devDept.Eyeshot.OrientedBoundingRect(origin, width + 2, height + 2);
1029
                            DiffRegions.Add(rect);
1030
                        }
1031
                        #endregion
1032
                    }
1033
                }
1034

    
1035
                for (int j = 0; j < AVEVAEntities.Count; j++)
1036
                {
1037
                    if (!equalEntitiesInV2[j])
1038
                    {
1039
                        AVEVAEntities[j].LayerName = Verification.AVEVADiffLayer;
1040
                        ColorEntity(design2, AVEVAEntities[j], Verification.DiffColor, colorMethodType.byEntity, false);
1041

    
1042
                        #region 틀린 엔터티의 BoundingBox를 구함 
1043
                        var origin = new devDept.Geometry.Point2D(AVEVAEntities[j].BoxMin.X - 1, AVEVAEntities[j].BoxMin.Y - 1);
1044
                        double width = AVEVAEntities[j].BoxMax.X - AVEVAEntities[j].BoxMin.X;
1045
                        double height = AVEVAEntities[j].BoxMax.Y - AVEVAEntities[j].BoxMin.Y;
1046
                        if (Math.Abs(width) != double.PositiveInfinity && Math.Abs(height) != double.PositiveInfinity)
1047
                        {
1048
                            var rect = new devDept.Eyeshot.OrientedBoundingRect(origin, width + 2, height + 2);
1049
                            DiffRegions.Add(rect);
1050
                        }
1051
                        #endregion
1052
                    }
1053
                }
1054

    
1055
                #region 인접한 영역을 하나로 합친다.
1056
                var queue = new List<devDept.Eyeshot.OrientedBoundingRect>(DiffRegions);
1057
                DiffRegions.Clear();
1058
                while (queue.Any())
1059
                {
1060
                    var first = queue[0];
1061
                    var FirstMin = first.GetOrigin();
1062
                    var FirstMax = FirstMin + first.GetAxis()[0] * first.Size.X + first.GetAxis()[1] * first.Size.Y;
1063

    
1064
                    queue.Remove(first);
1065
                    bool overlap = false;
1066
                    for (int i = 0; i < queue.Count; ++i)
1067
                    {
1068
                        var second = queue[i];
1069
                        overlap = devDept.Eyeshot.OrientedBoundingRect.DoOverlapOrTouch(first, second);
1070
                        if (overlap)
1071
                        {
1072
                            var SecondMin = second.GetOrigin();
1073
                            var SecondMax = SecondMin + second.GetAxis()[0] * second.Size.X + second.GetAxis()[1] * second.Size.Y;
1074

    
1075
                            var min = new devDept.Geometry.Point2D(Math.Min(FirstMin.X, SecondMin.X), Math.Min(FirstMin.Y, SecondMin.Y));
1076
                            var max = new devDept.Geometry.Point2D(Math.Max(FirstMax.X, SecondMax.X), Math.Max(FirstMax.Y, SecondMax.Y));
1077
                            double width = max.X - min.X;
1078
                            double height = max.Y - min.Y;
1079

    
1080
                            #region 두 영역을 합친다.(작업 완료된 영역도 다시 queue에 넣는다.)
1081
                            var rect = new devDept.Eyeshot.OrientedBoundingRect(min, width, height);
1082
                            queue.Add(rect);
1083
                            queue.AddRange(DiffRegions);
1084
                            DiffRegions.Clear();
1085
                            queue.Remove(second);
1086
                            #endregion
1087
                            break;
1088
                        }
1089
                    }
1090

    
1091
                    if (!overlap) DiffRegions.Add(first);
1092
                }
1093
                #endregion
1094

    
1095
                if (!design2.Layers.Contains(Verification.RevCloudLayer))
1096
                    design2.Layers.Add(Verification.RevCloudLayer.ToUpper(), Verification.RevCloudColor);
1097
                DiffRegions.ForEach(x => DrawRevCloud(design2, x));
1098
            }
1099
            catch(Exception ex)
1100
            {
1101
                Console.Write($"Error : {ex.Message}");
1102
            }
1103
        }
1104

    
1105
        /// <summary>
1106
        /// Revision mark를 그린다.
1107
        /// </summary>
1108
        /// <param name="design"></param>
1109
        /// <param name="obr"></param>
1110
        private void DrawRevCloud(Design design, devDept.Eyeshot.OrientedBoundingRect obr)
1111
        {
1112
            IList<IGCurve> DrawRevCloudLine(devDept.Geometry.Point2D start, devDept.Geometry.Point2D end)
1113
            {
1114
                var res = new List<IGCurve>();
1115

    
1116
                var AxisX = new devDept.Geometry.Vector3D(end.X - start.X, end.Y - start.Y);
1117
                AxisX.Normalize();
1118
                var AxisY = devDept.Geometry.Vector3D.Cross(devDept.Geometry.Vector3D.AxisZ, AxisX);
1119

    
1120
                double step = 10;
1121
                double dist = start.DistanceTo(end);
1122
                int count = Convert.ToInt32(dist / step);
1123
                if (count == 0 && dist > 0)
1124
                {
1125
                    var tmp = (start + end) * 0.5;
1126

    
1127
                    var center = new devDept.Geometry.Point3D(tmp.X, tmp.Y, 0);
1128
                    var plane = new devDept.Geometry.Plane(center, AxisX, AxisY);
1129
                    GArc arc = new GArc(plane, center, start.DistanceTo(end) * 0.5, Math.PI, Math.PI * 2);
1130
                    res.Add(arc);
1131
                }
1132
                else
1133
                {
1134
                    for (int i = 0; i < count; ++i)
1135
                    {
1136
                        var _start = (start + AxisX * i * step);
1137
                        var _end = (start + AxisX * (i + 1) * step);
1138
                        if (i == count - 1) _end = end;
1139
                        var tmp = (_start + _end) * 0.5;
1140

    
1141
                        var center = new devDept.Geometry.Point3D(tmp.X, tmp.Y, 0);
1142
                        var plane = new devDept.Geometry.Plane(center, AxisX, AxisY);
1143
                        GArc arc = new GArc(plane, center, _start.DistanceTo(_end) * 0.5, Math.PI, Math.PI * 2);
1144
                        res.Add(arc);
1145
                    }
1146
                }
1147

    
1148
                return res;
1149
            }
1150

    
1151
            GCompositeCurve profile = new GCompositeCurve();
1152

    
1153
            var vertices = obr.GetVertices();
1154
            for(int i = 0;i < vertices.Length;++i)
1155
            {
1156
                var curves = DrawRevCloudLine(vertices[i], vertices[(i + 1) % vertices.Length]);
1157
                profile.CurveList.AddRange(curves);
1158
            }
1159

    
1160
            var revcloud = new devDept.Eyeshot.Entities.CompositeCurve(profile);
1161
            revcloud.LayerName = Verification.RevCloudLayer;
1162
            revcloud.Color = Verification.RevCloudColor;
1163
            revcloud.ColorMethod = colorMethodType.byEntity;
1164
            revcloud.LineWeight = 3;
1165
            revcloud.LineWeightMethod = colorMethodType.byEntity;
1166
            design.Entities.Add(revcloud);
1167
        }
1168

    
1169
        /// <summary>
1170
        /// 주어진 두 엔터티를 비교한다.
1171
        /// </summary>
1172
        /// <param name="entVp1"></param>
1173
        /// <param name="entVp2"></param>
1174
        /// <returns></returns>
1175
        private bool CompareIfEqual(Design design1, Entity entVp1, Design design2, Entity entVp2)
1176
        {
1177
            return AreEqual(design1, entVp1, design2, entVp2);
1178
        }
1179

    
1180
        private bool CompareGEntityIfEqual(GEntity entVp1, GEntity entVp2)
1181
        {
1182
            return AreGEntityEqual(entVp1, entVp2);
1183
        }
1184

    
1185
        /// <summary>
1186
        /// 그래픽적으로 두 엔터티가 유사한지 검사한다.
1187
        /// </summary>
1188
        /// <param name="design1"></param>
1189
        /// <param name="ent1"></param>
1190
        /// <param name="design2"></param>
1191
        /// <param name="ent2"></param>
1192
        /// <returns></returns>
1193
        private bool AreEqual(Design design1, Entity ent1, Design design2, Entity ent2)
1194
        {
1195
            if (ent1 is CompositeCurve cc1 && ent2 is CompositeCurve cc2)
1196
            {
1197
                if (cc1.CurveList.Count == cc2.CurveList.Count)
1198
                {
1199
                    int equalCurvesInListCount = 0;
1200
                    foreach (var entC in cc1.CurveList)
1201
                    {
1202
                        foreach (var entC2 in cc2.CurveList)
1203
                        {
1204
                            if (entC.GetType() == entC2.GetType())
1205
                            {
1206
                                if (entC is Entity && entC2 is Entity && CompareIfEqual(design1, entC as Entity, design2, entC2 as Entity))
1207
                                {
1208
                                    equalCurvesInListCount++;
1209
                                    break;
1210
                                }
1211
                                else if (entC is GEntity && entC2 is GEntity && CompareGEntityIfEqual(entC as GEntity, entC2 as GEntity))
1212
                                {
1213
                                    equalCurvesInListCount++;
1214
                                    break;
1215
                                }
1216
                            }
1217
                        }
1218
                    }
1219

    
1220
                    if (cc1.CurveList.Count == equalCurvesInListCount)
1221
                    {
1222
                        return true;
1223
                    }
1224
                }
1225
            }
1226
            else if (ent1 is LinearPath lp1 && ent2 is LinearPath lp2)
1227
            {
1228
                if (lp1.Vertices.Length == lp2.Vertices.Length)
1229
                {
1230
                    for (int i = 0; i < lp1.Vertices.Length; i++)
1231
                    {
1232
                        if (lp1.Vertices[i].DistanceTo(lp2.Vertices[i]) > Verification.Tolerance)
1233
                            return false;
1234
                    }
1235

    
1236
                    return true;
1237
                }
1238
            }
1239
            else if (ent1 is PlanarEntity && ent2 is PlanarEntity)
1240
            {
1241
                if (ent1 is Arc arc1 && ent2 is Arc arc2)
1242
                {
1243
                    if (
1244
                        arc1.Center.DistanceTo(arc2.Center) <= Verification.Tolerance &&
1245
                        Math.Abs(arc1.Radius - arc2.Radius) <= Verification.Tolerance &&
1246
                        Math.Abs(arc1.Domain.Min - arc2.Domain.Min) <= Verification.Tolerance &&
1247
                        Math.Abs(arc1.Domain.Max - arc2.Domain.Max) <= Verification.Tolerance
1248
                        )
1249
                    {
1250
                        return true;
1251
                    }
1252
                }
1253
                else if (ent1 is Circle c1 && ent2 is Circle c2)
1254
                {
1255
                    if (
1256
                        c1.Center.DistanceTo(c2.Center) <= Verification.Tolerance &&
1257
                        Math.Abs(c1.Radius - c2.Radius) <= Verification.Tolerance
1258
                        )
1259
                    {
1260
                        return true;
1261
                    }
1262
                }
1263
                else if (ent1 is EllipticalArc e1 && ent2 is EllipticalArc e2)
1264
                {
1265
                    if (
1266
                        e1.Center.DistanceTo(e2.Center) <= Verification.Tolerance &&
1267
                        Math.Abs(e1.RadiusX - e2.RadiusX) <= Verification.Tolerance &&
1268
                        Math.Abs(e1.RadiusY - e2.RadiusY) <= Verification.Tolerance &&
1269
                        Math.Abs(e1.Domain.Low - e2.Domain.Low) <= Verification.Tolerance &&
1270
                        Math.Abs(e1.Domain.High - e2.Domain.High) <= Verification.Tolerance
1271
                    )
1272
                    {
1273
                        return true;
1274
                    }
1275
                }
1276
                else if (ent1 is Ellipse el1 && ent2 is Ellipse el2)
1277
                {
1278
                    if (
1279
                        el1.Center.DistanceTo(el2.Center) <= Verification.Tolerance &&
1280
                        Math.Abs(el1.RadiusX - el2.RadiusX) <= Verification.Tolerance &&
1281
                        Math.Abs(el1.RadiusY - el2.RadiusY) <= Verification.Tolerance
1282
                    )
1283
                    {
1284
                        return true;
1285
                    }
1286
                }
1287
                #region 해치는 중점만 비교
1288
                else if (ent1 is Hatch hatch1 && ent2 is Hatch hatch2)
1289
                {
1290
                    var center1 = (hatch1.BoxMin + hatch1.BoxMax) * 0.5;
1291
                    center1.Z = 0;
1292
                    var center2 = (hatch2.BoxMin + hatch2.BoxMax) * 0.5;
1293
                    center2.Z = 0;
1294
                    return center1.DistanceTo(center2) < Verification.Tolerance;
1295
                }
1296
                #endregion
1297
                else if (ent1 is Text)
1298
                {
1299
                    if (ent1 is Dimension dim1 && ent2 is Dimension dim2)
1300
                    {
1301
                        if (
1302
                            dim1.InsertionPoint.DistanceTo(dim2.InsertionPoint) <= Verification.Tolerance &&
1303
                            dim1.DimLinePosition.DistanceTo(dim2.DimLinePosition) <= Verification.Tolerance
1304
                            )
1305
                        {
1306
                            if (ent1 is AngularDim ad1 && ent2 is AngularDim ad2)
1307
                            {
1308
                                if (
1309
                                    ad1.ExtLine1.DistanceTo(ad2.ExtLine1) <= Verification.Tolerance &&
1310
                                    ad1.ExtLine2.DistanceTo(ad2.ExtLine2) <= Verification.Tolerance &&
1311
                                    Math.Abs(ad1.StartAngle - ad2.StartAngle) <= Verification.Tolerance &&
1312
                                    Math.Abs(ad1.EndAngle - ad2.EndAngle) <= Verification.Tolerance &&
1313
                                    Math.Abs(ad1.Radius - ad2.Radius) <= Verification.Tolerance
1314
                                    )
1315
                                {
1316
                                    return true;
1317
                                }
1318
                            }
1319
                            else if (ent1 is LinearDim ld1 && ent2 is LinearDim ld2)
1320
                            {
1321
                                if (
1322
                                    ld1.ExtLine1.DistanceTo(ld2.ExtLine1) <= Verification.Tolerance &&
1323
                                    ld1.ExtLine2.DistanceTo(ld2.ExtLine2) <= Verification.Tolerance
1324
                                    )
1325
                                {
1326
                                    return true;
1327
                                }
1328
                            }
1329
                            else if (ent1 is DiametricDim dd1 && ent2 is DiametricDim dd2)
1330
                            {
1331
                                if (
1332
                                    Math.Abs(dd1.Distance - dd2.Distance) <= Verification.Tolerance &&
1333
                                    Math.Abs(dd1.Radius - dd2.Radius) <= Verification.Tolerance &&
1334
                                    Math.Abs(dd1.CenterMarkSize - dd2.CenterMarkSize) <= Verification.Tolerance
1335
                                )
1336
                                {
1337
                                    return true;
1338
                                }
1339
                            }
1340
                            else if (ent1 is RadialDim rd1 && ent2 is RadialDim rd2)
1341
                            {
1342
                                if (
1343
                                    Math.Abs(rd1.Radius - rd2.Radius) <= Verification.Tolerance &&
1344
                                    Math.Abs(rd1.CenterMarkSize - rd2.CenterMarkSize) <= Verification.Tolerance
1345
                                )
1346
                                {
1347
                                    return true;
1348
                                }
1349
                            }
1350
                            else if (ent1 is OrdinateDim od1 && ent2 is OrdinateDim od2)
1351
                            {
1352
                                if (
1353
                                    od1.DefiningPoint.DistanceTo(od2.DefiningPoint) <= Verification.Tolerance &&
1354
                                    od1.Origin.DistanceTo(od2.Origin) <= Verification.Tolerance &&
1355
                                    od1.LeaderEndPoint.DistanceTo(od2.LeaderEndPoint) <= Verification.Tolerance
1356
                                )
1357
                                {
1358
                                    return true;
1359
                                }
1360
                            }
1361
                            else
1362
                            {
1363
                                Console.Write("Type " + ent1.GetType() + " not implemented.");
1364
                                return true;
1365
                            }
1366
                        }
1367
                    }
1368

    
1369
                    else if (ent1 is devDept.Eyeshot.Entities.Attribute att1 && ent2 is devDept.Eyeshot.Entities.Attribute att2)
1370
                    {
1371
                        if (
1372
                            att1.Value == att2.Value &&
1373
                            att1.InsertionPoint.DistanceTo(att2.InsertionPoint) <= Verification.Tolerance
1374
                            )
1375
                        {
1376
                            return true;
1377
                        }
1378
                    }
1379
                    else
1380
                    {
1381
                        Text tx1 = (Text)ent1;
1382
                        Text tx2 = (Text)ent2;
1383

    
1384
                        #region 대소문자, 공백을 무시하여 비교
1385
                        string string1 = tx1.TextString.Trim().ToUpper();
1386
                        string string2 = tx2.TextString.Trim().ToUpper();
1387
                        string1 = System.Text.RegularExpressions.Regex.Replace(string1, @"\s+", "");
1388
                        string2 = System.Text.RegularExpressions.Regex.Replace(string2, @"\s+", "");
1389
                        if (
1390
                            tx1.BoxMin.DistanceTo(tx2.BoxMin) <= Verification.Tolerance &&
1391
                            string1 == string2 &&
1392
                            Math.Abs(tx1.WidthFactor - tx2.WidthFactor) <= Verification.Tolerance &&
1393
                            Math.Abs(tx1.Height - tx2.Height) <= Verification.Tolerance
1394
                            )
1395
                        {
1396
                            return true;
1397
                        }
1398
                        #endregion
1399
                    }
1400
                }
1401
            }
1402
            else if (ent1 is Line line1 && ent2 is Line line2)
1403
            {
1404
                var dir1 = line1.Direction;
1405
                dir1.Normalize();
1406
                var dir2 = line2.Direction;
1407
                dir2.Normalize();
1408
                if (devDept.Geometry.Vector3D.AreParallel(dir1, dir2, 0.1) &&
1409
                    Math.Abs(line1.Length() - line2.Length()) <= line1.Length() * LengthToleranceRatio &&
1410
                    line1.MidPoint.DistanceTo(line2.MidPoint) <= Verification.Tolerance
1411
                )
1412
                {
1413
                    return true;
1414
                }
1415
            }
1416
            else if (ent1 is Line && ent2 is devDept.Eyeshot.Entities.TabulatedSurface lwpolyline && lwpolyline.ControlPoints.Length == 4)
1417
            {
1418
                line1 = ent1 as Line;
1419
                var start = new devDept.Geometry.Point3D(lwpolyline.ControlPoints[0, 0].X, lwpolyline.ControlPoints[0, 0].Y, 0);
1420
                var end = new devDept.Geometry.Point3D(lwpolyline.ControlPoints[1, 0].X, lwpolyline.ControlPoints[1, 0].Y, 0);
1421
                var vec = new devDept.Geometry.Vector3D(start, end);
1422
                vec.Normalize();
1423
                var dir = line1.Direction.Clone() as devDept.Geometry.Vector3D;
1424
                dir.Normalize();
1425

    
1426
                if (
1427
                    devDept.Geometry.Vector3D.AreParallel(dir, vec) &&
1428
                    line1.StartPoint.DistanceTo(start) <= Verification.Tolerance &&
1429
                    line1.EndPoint.DistanceTo(end) <= Verification.Tolerance
1430
                )
1431
                {
1432
                    return true;
1433
                }
1434
            }
1435
            else if (ent1 is devDept.Eyeshot.Entities.Point point1 && ent2 is devDept.Eyeshot.Entities.Point point2)
1436
            {
1437
                if (point1.Position.DistanceTo(point2.Position) <= Verification.Tolerance)
1438
                {
1439
                    return true;
1440
                }
1441
            }
1442
            else if (ent1 is Curve cu1 && ent2 is Curve cu2)
1443
            {
1444
                if (
1445
                    cu1.ControlPoints.Length == cu2.ControlPoints.Length &&
1446
                    cu1.KnotVector.Length == cu2.KnotVector.Length &&
1447
                    cu1.Degree == cu2.Degree
1448
                    )
1449
                {
1450
                    for (int k = 0; k < cu1.ControlPoints.Length; k++)
1451
                    {
1452
                        if (cu1.ControlPoints[k].DistanceTo(cu2.ControlPoints[k]) > Verification.Tolerance)
1453
                        {
1454
                            return false;
1455
                        }
1456
                    }
1457

    
1458
                    for (int k = 0; k < cu1.KnotVector.Length; k++)
1459
                    {
1460
                        if (cu1.KnotVector[k] != cu2.KnotVector[k])
1461
                        {
1462
                            return false;
1463
                        }
1464
                    }
1465

    
1466
                    return true;
1467
                }
1468
            }
1469
            else if (ent1 is Mesh m1 && ent2 is Mesh m2 && m1.Vertices.Count() == m2.Vertices.Count())
1470
            {
1471
                for (int i = 0; i < m1.Vertices.Count(); ++i)
1472
                {
1473
                    if (m1.Vertices[i].DistanceTo(m2.Vertices[i]) > Verification.Tolerance) return false;
1474
                }
1475

    
1476
                return true;
1477
            }
1478
            else if (ent1 is BlockReference blkref1 && ent2 is BlockReference blkref2)
1479
            {
1480
                int equalCurvesInEntityList = 0;
1481

    
1482
                #region Point, Attribute, Text 제거 및 LinePath를 라인으로 분리
1483
                var entities1 = blkref1.Explode(design1.Blocks).Where(x => x.LayerName != "AS_PORT" && !(x is devDept.Eyeshot.Entities.Point) &&
1484
                !(x is devDept.Eyeshot.Entities.Attribute) && !(x is devDept.Eyeshot.Entities.Text)).ToList();
1485
                var coll1 = new List<Entity>();
1486
                entities1.ForEach(x =>
1487
                {
1488
                    if (x is LinearPath lp)
1489
                    {
1490
                        for (int i = 0; i < lp.Vertices.Length - 1; ++i)
1491
                        {
1492
                            if (lp.Vertices[i].DistanceTo(lp.Vertices[i + 1]) < 0.1) continue;
1493
                            coll1.Add(new Line(lp.Vertices[i], lp.Vertices[i + 1]));
1494
                        }
1495
                    }
1496
                    else
1497
                    {
1498
                        coll1.Add(x);
1499
                    }
1500
                });
1501
                #endregion
1502

    
1503
                #region Point 및 Nesting Block 제거 및 LinePath를 라인으로 분리
1504
                var entities2 = blkref2.Explode(design2.Blocks).Where(x => 
1505
                !(x is devDept.Eyeshot.Entities.BlockReference blkref && blkref.BlockName == "PORT") && !(x is devDept.Eyeshot.Entities.Point)).ToList();
1506
                var coll2 = new List<Entity>();
1507
                entities2.ForEach(x =>
1508
                {
1509
                    if (x is LinearPath lp)
1510
                    {
1511
                        for (int i = 0; i < lp.Vertices.Length - 1; ++i)
1512
                        {
1513
                            if (lp.Vertices[i].DistanceTo(lp.Vertices[i + 1]) < 0.1) continue;
1514
                            coll2.Add(new Line(lp.Vertices[i], lp.Vertices[i + 1]));
1515
                        }
1516
                    }
1517
                    else if (x is devDept.Eyeshot.Entities.Attribute attr)
1518
                    {
1519
                        if (!attr.Invisible) coll2.Add(attr);
1520
                    }
1521
                    else if (x.GetType().Name == "AttributeReferenceData")
1522
                    {
1523
                    }
1524
                    else
1525
                    {
1526
                        coll2.Add(x);
1527
                    }
1528
                });
1529
                #endregion
1530

    
1531
                if (coll1.Count != coll2.Count) return false;
1532

    
1533
                foreach (var entC in coll1)
1534
                {
1535
                    foreach (var entC2 in coll2)
1536
                    {
1537
                        if (entC.GetType() == entC2.GetType())
1538
                        {
1539
                            if (entC is Entity && entC2 is Entity && CompareIfEqual(design1, entC as Entity, design2, entC2 as Entity))
1540
                            {
1541
                                equalCurvesInEntityList++;
1542
                                break;
1543
                            }
1544
                        }
1545
                    }
1546
                }
1547

    
1548
                if (coll1.Count == equalCurvesInEntityList)
1549
                {
1550
                    return true;
1551
                }
1552
            }
1553
            else
1554
            {
1555
                Console.Write("Type " + ent1.GetType() + " not implemented.");
1556
                return false;
1557
            }
1558

    
1559
            return false;
1560
        }
1561

    
1562
        private bool AreGEntityEqual(GEntity ent1, GEntity ent2)
1563
        {
1564
            if (ent1 is GCompositeCurve cc1 && ent2 is GCompositeCurve cc2)
1565
            {
1566
                if (cc1.CurveList.Count == cc2.CurveList.Count)
1567
                {
1568
                    int equalCurvesInListCount = 0;
1569
                    foreach (var entC in cc1.CurveList)
1570
                    {
1571
                        foreach (var entC2 in cc2.CurveList)
1572
                        {
1573
                            if (entC.GetType() == entC2.GetType())
1574
                            {
1575
                                if (entC is GEntity && entC2 is GEntity && CompareGEntityIfEqual(entC as GEntity, entC2 as GEntity))
1576
                                {
1577
                                    equalCurvesInListCount++;
1578
                                    break;
1579
                                }
1580
                            }
1581
                        }
1582
                    }
1583

    
1584
                    if (cc1.CurveList.Count == equalCurvesInListCount)
1585
                    {
1586
                        return true;
1587
                    }
1588
                }
1589
            }
1590
            else if (ent1 is GLinearPath lp1 && ent2 is GLinearPath lp2)
1591
            {
1592
                if (lp1.Vertices.Length == lp2.Vertices.Length)
1593
                {
1594
                    for (int i = 0; i < lp1.Vertices.Length; i++)
1595
                    {
1596
                        if (lp1.Vertices[i].DistanceTo(lp2.Vertices[i]) > Verification.Tolerance)
1597
                            return false;
1598
                    }
1599
                    return true;
1600
                }
1601
            }
1602

    
1603
            else if (ent1 is GPlanarEntity pe1 && ent2 is GPlanarEntity pe2)
1604
            {
1605
                if (
1606
                    pe1.Plane.AxisZ == pe2.Plane.AxisZ &&
1607
                    pe1.Plane.AxisX == pe2.Plane.AxisX
1608
                    )
1609
                {
1610
                    if (ent1 is GArc arc1 && ent2 is GArc arc2)
1611
                    {
1612
                        if (
1613
                            arc1.Center.DistanceTo(arc2.Center) <= Verification.Tolerance &&
1614
                            Math.Abs(arc1.Radius - arc2.Radius) <= Verification.Tolerance &&
1615
                            Math.Abs(arc1.Domain.Min - arc2.Domain.Min) <= Verification.Tolerance &&
1616
                            Math.Abs(arc1.Domain.Max - arc2.Domain.Max) <= Verification.Tolerance
1617
                            )
1618
                        {
1619
                            return true;
1620
                        }
1621
                    }
1622
                    else if (ent1 is GCircle c1 && ent2 is GCircle c2)
1623
                    {
1624
                        if (c1.Center.DistanceTo(c2.Center) <= Verification.Tolerance && 
1625
                            Math.Abs(c1.Radius - c2.Radius) <= Verification.Tolerance)
1626
                        {
1627
                            return true;
1628
                        }
1629
                    }
1630
                    else if (ent1 is GEllipticalArc e1 && ent2 is GEllipticalArc e2)
1631
                    {
1632
                        if (
1633
                            e1.Center.DistanceTo(e2.Center) <= Verification.Tolerance &&
1634
                            Math.Abs(e1.RadiusX - e2.RadiusX) <= Verification.Tolerance &&
1635
                            Math.Abs(e1.RadiusY - e2.RadiusY) <= Verification.Tolerance &&
1636
                            Math.Abs(e1.Domain.Low - e2.Domain.Low) <= Verification.Tolerance &&
1637
                            Math.Abs(e1.Domain.High - e2.Domain.High) <= Verification.Tolerance
1638
                        )
1639
                        {
1640
                            return true;
1641
                        }
1642
                    }
1643
                    else if (ent1 is GEllipse el1 && ent2 is GEllipse el2)
1644
                    {
1645
                        if (
1646
                            el1.Center.DistanceTo(el2.Center) <= Verification.Tolerance &&
1647
                            Math.Abs(el1.RadiusX - el2.RadiusX) <= Verification.Tolerance &&
1648
                            Math.Abs(el1.RadiusY - el2.RadiusY) <= Verification.Tolerance
1649
                        )
1650
                        {
1651
                            return true;
1652
                        }
1653
                    }
1654
                    else
1655
                    {
1656
                        Console.Write("Type " + ent1.GetType() + " not implemented.");
1657
                        return true;
1658
                    }
1659
                }
1660
            }
1661

    
1662
            else if (ent1 is GLine line1 && ent2 is GLine line2)
1663
            {
1664
                if (line1.StartPoint.DistanceTo(line2.StartPoint) <= Verification.Tolerance && 
1665
                    line1.EndPoint.DistanceTo(line2.EndPoint) <= Verification.Tolerance
1666
                )
1667
                {
1668
                    return true;
1669
                }
1670
            }
1671
#if NURBS
1672
            else if (ent1 is Curve)
1673
            {
1674
                Curve cu1 = (Curve)ent1;
1675
                Curve cu2 = (Curve)ent2;
1676

    
1677
                if (
1678
                    cu1.ControlPoints.Length == cu2.ControlPoints.Length &&
1679
                    cu1.KnotVector.Length == cu2.KnotVector.Length &&
1680
                    cu1.Degree == cu2.Degree
1681
                    )
1682
                {
1683
                    for (int k = 0; k < cu1.ControlPoints.Length; k++)
1684
                    {
1685
                        if (cu1.ControlPoints[k] != cu2.ControlPoints[k])
1686
                        {
1687
                            return false;
1688
                        }
1689
                    }
1690

    
1691
                    for (int k = 0; k < cu1.KnotVector.Length; k++)
1692
                    {
1693
                        if (cu1.KnotVector[k] != cu2.KnotVector[k])
1694
                        {
1695
                            return false;
1696
                        }
1697
                    }
1698

    
1699
                    return true;
1700
                }
1701
            }
1702
#endif
1703

    
1704
            else
1705
            {
1706
                Console.Write("Type " + ent1.GetType() + " not implemented.");
1707
                return true;
1708
            }
1709
            return false;
1710
        }
1711

    
1712
        #region Camera Sync
1713
        private void CameraChanged(object sender, devDept.Eyeshot.Workspace.CameraMoveEventArgs e)
1714
        {
1715
            if (sender == this.designAutoCAD)
1716
            {
1717
                SyncCamera(this.designAutoCAD, this.designAVEVA);
1718
                SyncCamera(this.designAutoCAD, this.designCompare);
1719
            }
1720
            else if (sender == this.designAVEVA)
1721
            {
1722
                SyncCamera(this.designAVEVA, this.designAutoCAD);
1723
                SyncCamera(this.designAVEVA, this.designCompare);
1724
            }
1725
            else
1726
            {
1727
                SyncCamera(this.designCompare, this.designAutoCAD);
1728
                SyncCamera(this.designCompare, this.designAVEVA);
1729
            }
1730
        }
1731

    
1732
        private void SyncCamera(Design designMovedCamera, Design designCameraToMove)
1733
        {
1734
            Camera savedCamera;
1735
            designMovedCamera.SaveView(out savedCamera);
1736

    
1737
            // restores the camera to the other model
1738
            designCameraToMove.RestoreView(savedCamera);
1739
            designCameraToMove.AdjustNearAndFarPlanes();
1740
            designCameraToMove.Invalidate();
1741
        }
1742
        #endregion
1743
    }
1744
}
클립보드 이미지 추가 (최대 크기: 500 MB)