hytos / ID2.Manager / ID2.Manager.Compare / Controls / Verification-.cs @ 2ade1e61
이력 | 보기 | 이력해설 | 다운로드 (50.6 KB)
1 | 13a36357 | humkyung | using devDept.Eyeshot; |
---|---|---|---|
2 | using devDept.Eyeshot.Entities; |
||
3 | using devDept.Geometry.Entities; |
||
4 | using ID2.Manager.Common; |
||
5 | using ID2.Manager.Data.Models; |
||
6 | using System; |
||
7 | using System.Collections.Generic; |
||
8 | using System.ComponentModel; |
||
9 | using System.Data; |
||
10 | using System.Drawing; |
||
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 | |||
18 | namespace ID2.Manager.Controls |
||
19 | { |
||
20 | public partial class Verification : UserControl |
||
21 | { |
||
22 | public delegate void DocumentSelected(Documents doc); |
||
23 | public event DocumentSelected OnDocumentSelected; |
||
24 | |||
25 | readonly Informations informations = Informations.Instance; |
||
26 | readonly string IniFilePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), |
||
27 | Application.ProductName, $"{Application.ProductName}.ini"); |
||
28 | |||
29 | private static Color EqualColor = Color.FromArgb(44, 44, 44); |
||
30 | private static Color DiffColor = Color.Yellow; |
||
31 | private static double Tolerance = 0; |
||
32 | |||
33 | public Verification() |
||
34 | { |
||
35 | InitializeComponent(); |
||
36 | this.radGridViewDocument.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; |
||
37 | |||
38 | this.Load += Verification_Load; |
||
39 | this.radGridViewDocument.SelectionChanged += RadGridViewDocument_SelectionChanged; |
||
40 | this.radBrowseEditorAVEVAPIDFolder.ValueChanged += RadBrowseEditorAVEVAPIDFolder_ValueChanged; |
||
41 | this.radSpinEditorTolerance.ValueChanged += RadSpinEditorTolerance_ValueChanged; |
||
42 | this.radColorBoxEqualColor.ValueChanged += RadColorBoxEqualColor_ValueChanged; |
||
43 | this.radColorBoxDiffColor.ValueChanged += RadColorBoxDiffColor_ValueChanged; |
||
44 | |||
45 | this.designAutoCAD.ActionMode = actionType.SelectVisibleByPickDynamic; |
||
46 | this.designAutoCAD.Selection.ColorDynamic = Color.FromArgb(80, Color.OrangeRed); |
||
47 | this.designAutoCAD.Selection.HaloInnerColor = Color.FromArgb(255, Color.OrangeRed); |
||
48 | this.designAutoCAD.Selection.HaloOuterColor = Color.FromArgb(64, Color.OrangeRed); |
||
49 | this.designAutoCAD.Selection.HaloWidthPolygons = 4; |
||
50 | this.designAutoCAD.Selection.HaloWidthWires = 2; |
||
51 | |||
52 | this.designAVEVA.ActionMode = actionType.SelectVisibleByPickDynamic; |
||
53 | |||
54 | #region Camera Sync |
||
55 | this.designAutoCAD.ActiveViewport.Rotate.Enabled = false; |
||
56 | this.designAVEVA.ActiveViewport.Rotate.Enabled = false; |
||
57 | |||
58 | this.designAutoCAD.ActiveViewport.ViewCubeIcon.Visible = false; |
||
59 | this.designAVEVA.ActiveViewport.ViewCubeIcon.Visible = false; |
||
60 | |||
61 | this.designAutoCAD.AnimateCamera = false; |
||
62 | this.designAVEVA.AnimateCamera = false; |
||
63 | |||
64 | this.designAutoCAD.CameraChangedFrequency = 200; |
||
65 | this.designAVEVA.CameraChangedFrequency = 200; |
||
66 | |||
67 | this.designAutoCAD.CameraChanged += CameraChanged; |
||
68 | this.designAVEVA.CameraChanged += CameraChanged; |
||
69 | #endregion |
||
70 | } |
||
71 | |||
72 | |||
73 | |||
74 | /// <summary> |
||
75 | /// 서로 다른 엔터티의 색상을 설정한다. |
||
76 | /// </summary> |
||
77 | /// <param name="sender"></param> |
||
78 | /// <param name="e"></param> |
||
79 | private void RadColorBoxDiffColor_ValueChanged(object sender, EventArgs e) |
||
80 | { |
||
81 | Verification.DiffColor = this.radColorBoxDiffColor.Value; |
||
82 | string color = $"{Verification.DiffColor.R},{Verification.DiffColor.G},{Verification.DiffColor.B}"; |
||
83 | Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "DiffColor", color); |
||
84 | } |
||
85 | |||
86 | /// <summary> |
||
87 | /// 동일한 엔터티의 색상을 설정한다. |
||
88 | /// </summary> |
||
89 | /// <param name="sender"></param> |
||
90 | /// <param name="e"></param> |
||
91 | private void RadColorBoxEqualColor_ValueChanged(object sender, EventArgs e) |
||
92 | { |
||
93 | Verification.EqualColor = this.radColorBoxEqualColor.Value; |
||
94 | string color = $"{Verification.EqualColor.R},{Verification.EqualColor.G},{Verification.EqualColor.B}"; |
||
95 | Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "EqualColor", color); |
||
96 | } |
||
97 | |||
98 | /// <summary> |
||
99 | /// 수정한 Tolerance를 시스템에 반영한다. |
||
100 | /// </summary> |
||
101 | /// <param name="sender"></param> |
||
102 | /// <param name="e"></param> |
||
103 | private void RadSpinEditorTolerance_ValueChanged(object sender, EventArgs e) |
||
104 | { |
||
105 | string AVEVAPIDFolder = this.radBrowseEditorAVEVAPIDFolder.Value; |
||
106 | if (System.IO.Directory.Exists(AVEVAPIDFolder)) |
||
107 | { |
||
108 | double toler = Convert.ToDouble(this.radSpinEditorTolerance.Value); |
||
109 | Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "Tolerance", toler.ToString()); |
||
110 | Verification.Tolerance = toler; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | private void RadBrowseEditorAVEVAPIDFolder_ValueChanged(object sender, EventArgs e) |
||
115 | { |
||
116 | string AVEVAPIDFolder = this.radBrowseEditorAVEVAPIDFolder.Value; |
||
117 | if (System.IO.Directory.Exists(AVEVAPIDFolder)) |
||
118 | { |
||
119 | Classes.ID2Helper.IniWriteValue(IniFilePath, "Path", "AVEVA P&ID Folder", AVEVAPIDFolder); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | private void Verification_Load(object sender, EventArgs e) |
||
124 | { |
||
125 | string AVEVAPIDFolder = Classes.ID2Helper.IniReadValue(IniFilePath, "Path", "AVEVA P&ID Folder"); |
||
126 | if (!string.IsNullOrEmpty(AVEVAPIDFolder)) this.radBrowseEditorAVEVAPIDFolder.Value = AVEVAPIDFolder; |
||
127 | |||
128 | string Toler = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Tolerance"); |
||
129 | if (!string.IsNullOrEmpty(Toler)) |
||
130 | { |
||
131 | this.radSpinEditorTolerance.Value = Convert.ToDecimal(Toler); |
||
132 | Verification.Tolerance = Convert.ToDouble(this.radSpinEditorTolerance.Value); |
||
133 | } |
||
134 | |||
135 | string _EqualColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "EqualColor"); |
||
136 | if (!string.IsNullOrEmpty(_EqualColor)) |
||
137 | { |
||
138 | var tokens = _EqualColor.Split(','); |
||
139 | if (tokens.Length == 3) |
||
140 | { |
||
141 | this.radColorBoxEqualColor.Value = |
||
142 | Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2])); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | string _DiffColor = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "DiffColor"); |
||
147 | if (!string.IsNullOrEmpty(_DiffColor)) |
||
148 | { |
||
149 | var tokens = _DiffColor.Split(','); |
||
150 | if (tokens.Length == 3) |
||
151 | { |
||
152 | this.radColorBoxDiffColor.Value = |
||
153 | Color.FromArgb(Convert.ToInt32(tokens[0]), Convert.ToInt32(tokens[1]), Convert.ToInt32(tokens[2])); |
||
154 | } |
||
155 | } |
||
156 | string Layers = Classes.ID2Helper.IniReadValue(IniFilePath, "Verification", "Except Layers"); |
||
157 | if(!string.IsNullOrEmpty(Layers)) |
||
158 | { |
||
159 | var InfoColl = Layers.Split(',').ToList().ConvertAll(x => new Forms.ExceptLayer.LayerInfo(x)); |
||
160 | InfoColl.ForEach(x => Forms.ExceptLayer.ExceptLayerInfoColl.Add(x)); |
||
161 | } |
||
162 | |||
163 | this.radButtonExceptLayer.Click += RadButtonExceptLayer_Click; |
||
164 | } |
||
165 | /// <summary> |
||
166 | /// Except Layer 폼을 띄운다. |
||
167 | /// </summary> |
||
168 | /// <param name="sender"></param> |
||
169 | /// <param name="e"></param> |
||
170 | private void RadButtonExceptLayer_Click(object sender, EventArgs e) |
||
171 | { |
||
172 | using (var frm = new Forms.ExceptLayer()) |
||
173 | |||
174 | { |
||
175 | if(DialogResult.OK == frm.ShowDialog(this)) |
||
176 | { |
||
177 | string value = string.Join(",", Forms.ExceptLayer.ExceptLayerInfoColl.Select(x => x.Name)); |
||
178 | Classes.ID2Helper.IniWriteValue(IniFilePath, "Verification", "Except Layers", value); |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 | |||
183 | /// <summary> |
||
184 | /// 엔터티들의 색상을 바꾼다. |
||
185 | /// </summary> |
||
186 | /// <param name="design"></param> |
||
187 | /// <param name="list"></param> |
||
188 | public void ColorEntities(Design design, EntityList list, Color color, colorMethodType colorMethod=colorMethodType.byEntity, bool ChangeBlkColor=true) |
||
189 | { |
||
190 | foreach (Entity ent in list) |
||
191 | { |
||
192 | ColorEntity(design, ent, color, colorMethod, ChangeBlkColor); |
||
193 | } |
||
194 | } |
||
195 | |||
196 | /// <summary> |
||
197 | /// 엔터티의 색상을 변경한다. |
||
198 | /// </summary> |
||
199 | /// <param name="design"></param> |
||
200 | /// <param name="entity"></param> |
||
201 | /// <param name="color"></param> |
||
202 | private void ColorEntity(Design design, Entity entity, Color color, colorMethodType colorMethod = colorMethodType.byEntity, |
||
203 | bool ChangeBlkColor = true) |
||
204 | { |
||
205 | if (entity is BlockReference blkref) |
||
206 | { |
||
207 | blkref.Color = color; |
||
208 | blkref.ColorMethod = colorMethod; |
||
209 | |||
210 | if (ChangeBlkColor) |
||
211 | { |
||
212 | var blk = design.Blocks.FirstOrDefault(x => x.Name == blkref.BlockName); |
||
213 | if (blk != null) |
||
214 | { |
||
215 | ColorEntities(design, blk.Entities, color, colorMethodType.byParent); |
||
216 | foreach (var attr in blkref.Attributes.Values) |
||
217 | { |
||
218 | attr.Color = color; |
||
219 | attr.ColorMethod = colorMethodType.byParent; |
||
220 | } |
||
221 | } |
||
222 | } |
||
223 | } |
||
224 | else |
||
225 | { |
||
226 | entity.Color = color; |
||
227 | entity.ColorMethod = colorMethod; |
||
228 | } |
||
229 | } |
||
230 | |||
231 | /// <summary> |
||
232 | /// 도면을 선택했을때 두 도면을 비교한다. |
||
233 | /// </summary> |
||
234 | /// <param name="sender"></param> |
||
235 | /// <param name="e"></param> |
||
236 | private void RadGridViewDocument_SelectionChanged(object sender, EventArgs e) |
||
237 | { |
||
238 | /// AutoCAD P&ID 파일을 화면에 표시한다. |
||
239 | void ShowAutoCADFile(string FilePath) |
||
240 | { |
||
241 | this.designAutoCAD.Clear(); |
||
242 | if (System.IO.File.Exists(FilePath)) |
||
243 | { |
||
244 | try |
||
245 | { |
||
246 | devDept.Eyeshot.Translators.ReadAutodesk ra = new devDept.Eyeshot.Translators.ReadAutodesk(FilePath); |
||
247 | ra.DoWork(); |
||
248 | ra.AddToScene(this.designAutoCAD); |
||
249 | } |
||
250 | catch(Exception ex) |
||
251 | { |
||
252 | RadMessageBox.Show(ex.Message, Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Error); |
||
253 | } |
||
254 | |||
255 | var AddEntities = new List<Entity>(); |
||
256 | this.designAutoCAD.Entities.ForEach(x => |
||
257 | { |
||
258 | if (x is LinearPath lp) |
||
259 | { |
||
260 | int count = Convert.ToInt32(lp.Vertices.Length); |
||
261 | for (int i = 0; i < count - 1; ++i) |
||
262 | { |
||
263 | AddEntities.Add(new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1]) |
||
264 | { |
||
265 | LayerName = lp.LayerName, |
||
266 | LineWeight = lp.LineWeight, |
||
267 | LineTypeMethod = colorMethodType.byEntity |
||
268 | }); |
||
269 | } |
||
270 | } |
||
271 | else if(x is BlockReference blkref && blkref.Attributes.Any()) |
||
272 | { |
||
273 | var attributes = blkref.Attributes; |
||
274 | var entities = blkref.Explode(this.designAutoCAD.Blocks); |
||
275 | foreach(var ent in entities.Where(y => y is devDept.Eyeshot.Entities.Attribute)) |
||
276 | { |
||
277 | var txt = ent as devDept.Eyeshot.Entities.Attribute; |
||
278 | KeyValuePair<string, AttributeReference>? kp = attributes.FirstOrDefault(z => z.Key == txt.TextString); |
||
279 | if (kp.HasValue) txt.TextString = kp.Value.Value.Value; |
||
280 | } |
||
281 | |||
282 | AddEntities.AddRange(entities.Where(y => (y is devDept.Eyeshot.Entities.Attribute) || (y is devDept.Eyeshot.Entities.Text))); |
||
283 | blkref.Attributes.Clear(); |
||
284 | } |
||
285 | }); |
||
286 | |||
287 | #region LinearPath 그리고 Except Layer에 있는 항목 제외 |
||
288 | var ExceptLayers = Forms.ExceptLayer.ExceptLayerInfoColl.Select(x => x.Name); |
||
289 | this.designAutoCAD.Entities.RemoveAll(x => (x is LinearPath) || ExceptLayers.Contains(x.LayerName)); |
||
290 | #endregion |
||
291 | this.designAutoCAD.Entities.AddRange(AddEntities); |
||
292 | |||
293 | #region 브랜치가 생성되는 부분에서 라인을 분할 |
||
294 | var queue = this.designAutoCAD.Entities.Where(x => x is Line).ToList(); |
||
295 | while(queue.Any()) |
||
296 | { |
||
297 | var line1 = queue.First() as Line; |
||
298 | var dir1 = line1.Direction; |
||
299 | dir1.Normalize(); |
||
300 | queue.Remove(line1); |
||
301 | for(int i = 0;i < queue.Count;++i) |
||
302 | { |
||
303 | var line2 = queue.ElementAt(i) as Line; |
||
304 | var dir2 = line2.Direction; |
||
305 | dir2.Normalize(); |
||
306 | if(devDept.Geometry.Vector3D.AreOrthogonal(dir1, dir2)) |
||
307 | { |
||
308 | var intersects = line1.IntersectWith(line2); |
||
309 | if(intersects.Count() == 1) |
||
310 | { |
||
311 | if(line1.StartPoint.DistanceTo(intersects[0]) > 0.1 && line1.EndPoint.DistanceTo(intersects[0]) > 0.1) |
||
312 | { |
||
313 | var split1 = new devDept.Eyeshot.Entities.Line(line1.StartPoint, intersects[0]) |
||
314 | { |
||
315 | LayerName = line1.LayerName, |
||
316 | LineWeight = line1.LineWeight, |
||
317 | LineTypeMethod = colorMethodType.byEntity |
||
318 | }; |
||
319 | var split2 = new devDept.Eyeshot.Entities.Line(intersects[0], line1.EndPoint) |
||
320 | { |
||
321 | LayerName = line1.LayerName, |
||
322 | LineWeight = line1.LineWeight, |
||
323 | LineTypeMethod = colorMethodType.byEntity |
||
324 | }; |
||
325 | this.designAutoCAD.Entities.Add(split1); |
||
326 | this.designAutoCAD.Entities.Add(split2); |
||
327 | this.designAutoCAD.Entities.Remove(line1); |
||
328 | |||
329 | queue.Add(split1); |
||
330 | queue.Add(split2); |
||
331 | |||
332 | break; |
||
333 | } |
||
334 | |||
335 | if (line2.StartPoint.DistanceTo(intersects[0]) > 0.1 && line2.EndPoint.DistanceTo(intersects[0]) > 0.1) |
||
336 | { |
||
337 | var split1 = new devDept.Eyeshot.Entities.Line(line2.StartPoint, intersects[0]) |
||
338 | { |
||
339 | LayerName = line2.LayerName, |
||
340 | LineWeight = line2.LineWeight, |
||
341 | LineTypeMethod = colorMethodType.byEntity |
||
342 | }; |
||
343 | var split2 = new devDept.Eyeshot.Entities.Line(intersects[0], line2.EndPoint) |
||
344 | { |
||
345 | LayerName = line2.LayerName, |
||
346 | LineWeight = line2.LineWeight, |
||
347 | LineTypeMethod = colorMethodType.byEntity |
||
348 | }; |
||
349 | this.designAutoCAD.Entities.Add(split1); |
||
350 | this.designAutoCAD.Entities.Add(split2); |
||
351 | this.designAutoCAD.Entities.Remove(line2); |
||
352 | |||
353 | queue.Remove(line2); |
||
354 | queue.Add(split1); |
||
355 | queue.Add(split2); |
||
356 | } |
||
357 | } |
||
358 | } |
||
359 | } |
||
360 | } |
||
361 | #endregion |
||
362 | |||
363 | ColorEntities(this.designAutoCAD, this.designAutoCAD.Entities, Verification.EqualColor); |
||
364 | |||
365 | // Sets the view as Top |
||
366 | this.designAutoCAD.SetView(viewType.Top); |
||
367 | this.designAutoCAD.ZoomFit(); |
||
368 | this.designAutoCAD.Invalidate(); |
||
369 | } |
||
370 | } |
||
371 | |||
372 | /// AVEVA P&ID 파일을 화면에 표시한다. |
||
373 | void ShowAVEVAPIDFile(string FilePath) |
||
374 | { |
||
375 | this.designAVEVA.Clear(); |
||
376 | if (System.IO.File.Exists(FilePath)) |
||
377 | { |
||
378 | devDept.Eyeshot.Translators.ReadAutodesk ra = new devDept.Eyeshot.Translators.ReadAutodesk(FilePath); |
||
379 | ra.DoWork(); |
||
380 | ra.AddToScene(this.designAVEVA); |
||
381 | |||
382 | #region 멀티 라인들을 분할하여 추가한다. |
||
383 | var AddEntities = new List<Entity>(); |
||
384 | this.designAVEVA.Entities.ForEach(x => |
||
385 | { |
||
386 | if(x is Mesh mesh && (mesh.LayerName == "AS_PIPE" || mesh.LayerName == "AS_INST")) |
||
387 | { |
||
388 | int count = Convert.ToInt32(mesh.Vertices.Length * 0.5); |
||
389 | for (int i = 0;i < count - 1; ++i) |
||
390 | { |
||
391 | AddEntities.Add(new devDept.Eyeshot.Entities.Line(mesh.Vertices[i], mesh.Vertices[i + 1]) |
||
392 | { |
||
393 | LayerName = mesh.LayerName, |
||
394 | LineWeight = 3.0f, |
||
395 | LineTypeMethod = colorMethodType.byEntity, |
||
396 | Color = Verification.DiffColor, |
||
397 | ColorMethod = colorMethodType.byEntity |
||
398 | }); |
||
399 | } |
||
400 | } |
||
401 | else if (x is TabulatedSurface tf && (tf.LayerName == "AS_PIPE" || tf.LayerName == "AS_INST")) |
||
402 | { |
||
403 | int count = Convert.ToInt32(tf.ControlPoints.Length * 0.5); |
||
404 | for (int i = 0; i < count - 1; ++i) |
||
405 | { |
||
406 | AddEntities.Add( |
||
407 | new devDept.Eyeshot.Entities.Line( |
||
408 | new devDept.Geometry.Point3D(tf.ControlPoints[i, 0].X, tf.ControlPoints[i, 0].Y, 0), |
||
409 | new devDept.Geometry.Point3D(tf.ControlPoints[i + 1, 0].X, tf.ControlPoints[i + 1, 0].Y, 0)) |
||
410 | { |
||
411 | LayerName = tf.LayerName, |
||
412 | LineWeight = 3.0f, |
||
413 | LineTypeMethod = colorMethodType.byEntity, |
||
414 | Color = Verification.DiffColor, |
||
415 | ColorMethod = colorMethodType.byEntity |
||
416 | } |
||
417 | ); |
||
418 | } |
||
419 | } |
||
420 | else if (x is LinearPath lp) |
||
421 | { |
||
422 | int count = Convert.ToInt32(lp.Vertices.Length); |
||
423 | for (int i = 0; i < count - 1; ++i) |
||
424 | { |
||
425 | AddEntities.Add(new devDept.Eyeshot.Entities.Line(lp.Vertices[i], lp.Vertices[i + 1]) |
||
426 | { |
||
427 | LayerName = lp.LayerName, |
||
428 | LineWeight = lp.LineWeight, |
||
429 | LineTypeMethod = colorMethodType.byEntity |
||
430 | }); |
||
431 | } |
||
432 | } |
||
433 | }); |
||
434 | this.designAVEVA.Entities.RemoveAll(x => |
||
435 | ((x is Mesh || x is TabulatedSurface) && (x.LayerName == "AS_PIPE" || x.LayerName == "AS_INST")) || |
||
436 | (x is LinearPath)); |
||
437 | this.designAVEVA.Entities.AddRange(AddEntities); |
||
438 | #endregion |
||
439 | |||
440 | ColorEntities(this.designAVEVA, this.designAVEVA.Entities, Verification.DiffColor); |
||
441 | |||
442 | #region 블럭 이름이 PSNODE, PENODE인 블럭은 보이지 않도록 한다. |
||
443 | this.designAVEVA.Entities.ForEach(x => |
||
444 | { |
||
445 | if (x is BlockReference blkref && (blkref.BlockName == "PSNODE" || blkref.BlockName == "PENODE" || |
||
446 | blkref.BlockName.StartsWith("ARROW"))) |
||
447 | blkref.Visible = false; |
||
448 | }); |
||
449 | #endregion |
||
450 | |||
451 | this.designAVEVA.SetView(viewType.Top); |
||
452 | this.designAVEVA.ZoomFit(); |
||
453 | this.designAVEVA.Invalidate(); |
||
454 | } |
||
455 | } |
||
456 | |||
457 | if (this.radGridViewDocument.SelectedRows.Any() && this.radGridViewDocument.SelectedRows.First().DataBoundItem is Documents doc) |
||
458 | { |
||
459 | string dwgExtension = ".dwg"; |
||
460 | string ID2DrawingFolder = @"C:\Users\dsik13460.id\Documents\Projects\ID2.Manager\Docs";/// System.IO.Path.Combine(informations.FindID2LocalPath(doc.RefProjectCode), "drawings", "Native"); |
||
461 | string dwgFilePath = System.IO.Path.Combine(ID2DrawingFolder, $"{doc.DocumentNo}{dwgExtension}"); |
||
462 | this.radTextBoxID2DrawingFolder.Text = ID2DrawingFolder; |
||
463 | |||
464 | ShowAutoCADFile(dwgFilePath); |
||
465 | string AVEVAPIDFolder = @"C:\Users\dsik13460.id\Documents\Projects\ID2.Manager\Docs\AVEVA";/// this.radBrowseEditorAVEVAPIDFolder.Value; |
||
466 | string AVEVAPIDFilePath = string.Empty; |
||
467 | if (AVEVAPIDFolder != null) |
||
468 | { |
||
469 | AVEVAPIDFilePath = System.IO.Path.Combine(AVEVAPIDFolder, $"{doc.DocumentNo}{dwgExtension}"); |
||
470 | ShowAVEVAPIDFile(AVEVAPIDFilePath); |
||
471 | |||
472 | } |
||
473 | |||
474 | if(System.IO.File.Exists(dwgFilePath) && System.IO.File.Exists(AVEVAPIDFilePath)) |
||
475 | { |
||
476 | CompareAndMark(this.designAutoCAD, this.designAutoCAD.Entities, this.designAVEVA, this.designAVEVA.Entities); |
||
477 | } |
||
478 | |||
479 | if(OnDocumentSelected != null) OnDocumentSelected(doc); |
||
480 | } |
||
481 | } |
||
482 | |||
483 | public void DocumentListBinding(List<ID2.Manager.Data.Models.Documents> docs) |
||
484 | { |
||
485 | this.radGridViewDocument.FilterDescriptors.Clear(); |
||
486 | this.radGridViewDocument.DataSource = new BindingList<ID2.Manager.Data.Models.Documents>(docs); |
||
487 | } |
||
488 | |||
489 | /// <summary> |
||
490 | /// 주어진 두 엔터티 리스트를 비교하여 틀린 엔터티의 색상을 Yellow로 변경한다. |
||
491 | /// </summary> |
||
492 | /// <param name="entList1"></param> |
||
493 | /// <param name="entList2"></param> |
||
494 | private void CompareAndMark(Design design1, IList<Entity> entList1, Design design2, IList<Entity> entList2) |
||
495 | { |
||
496 | int[] equalEntitiesInV1 = new int[entList2.Count]; |
||
497 | bool[] equalEntitiesInV2 = new bool[entList2.Count]; |
||
498 | |||
499 | /// 서로 검사 가능한 타입인지 확인한다. |
||
500 | bool CheckType(Entity ent1, Entity ent2) |
||
501 | { |
||
502 | return ent1.GetType() == ent2.GetType() || |
||
503 | (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Text) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.MultilineText)) || |
||
504 | (ent1.GetType() == typeof(devDept.Eyeshot.Entities.MultilineText) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.Text)) || |
||
505 | (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Line) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.TabulatedSurface) || |
||
506 | (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Attribute) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.Text)) || |
||
507 | (ent1.GetType() == typeof(devDept.Eyeshot.Entities.Attribute) && ent2.GetType() == typeof(devDept.Eyeshot.Entities.MultilineText))); |
||
508 | } |
||
509 | |||
510 | try |
||
511 | { |
||
512 | for (int i = 0; i < entList1.Count(); i++) |
||
513 | { |
||
514 | Entity entVp1 = entList1[i]; |
||
515 | bool foundEqual = false; |
||
516 | |||
517 | for (int j = 0; j < entList2.Count(); j++) |
||
518 | { |
||
519 | Entity entVp2 = entList2[j]; |
||
520 | |||
521 | if (entVp2 is BlockReference blkref && (blkref.BlockName == "PSNODE" || blkref.BlockName == "PENODE")) continue; |
||
522 | if (!equalEntitiesInV2[j] && CheckType(entVp1, entVp2) && |
||
523 | CompareIfEqual(this.designAutoCAD, entVp1, this.designAVEVA, entVp2)) |
||
524 | { |
||
525 | equalEntitiesInV1[j] = i; |
||
526 | equalEntitiesInV2[j] = true; |
||
527 | foundEqual = true; |
||
528 | break; |
||
529 | } |
||
530 | } |
||
531 | if (!foundEqual) |
||
532 | { |
||
533 | ColorEntity(design1, entList1[i], Verification.DiffColor, colorMethodType.byEntity, false); |
||
534 | } |
||
535 | } |
||
536 | |||
537 | for (int j = 0; j < entList2.Count; j++) |
||
538 | { |
||
539 | if (equalEntitiesInV2[j]) |
||
540 | { |
||
541 | ColorEntity(design2, entList2[j], Verification.EqualColor, colorMethodType.byEntity, false); |
||
542 | } |
||
543 | } |
||
544 | } |
||
545 | catch(Exception ex) |
||
546 | { |
||
547 | Console.Write($"Error : {ex.Message}"); |
||
548 | } |
||
549 | |||
550 | var bitmap1 = this.designAutoCAD.RenderToBitmap(new Size(2048, 1536)); |
||
551 | bitmap1.Save(@"c:\bitmap1.png", System.Drawing.Imaging.ImageFormat.Png); |
||
552 | var bitmap2 = this.designAVEVA.RenderToBitmap(new Size(2048, 1536)); |
||
553 | bitmap2.Save(@"c:\bitmap2.png", System.Drawing.Imaging.ImageFormat.Png); |
||
554 | |||
555 | } |
||
556 | |||
557 | /// <summary> |
||
558 | /// 주어진 두 엔터티를 비교한다. |
||
559 | /// </summary> |
||
560 | /// <param name="entVp1"></param> |
||
561 | /// <param name="entVp2"></param> |
||
562 | /// <returns></returns> |
||
563 | private bool CompareIfEqual(Design design1, Entity entVp1, Design design2, Entity entVp2) |
||
564 | { |
||
565 | return AreEqual(design1, entVp1, design2, entVp2); |
||
566 | } |
||
567 | |||
568 | private bool CompareGEntityIfEqual(GEntity entVp1, GEntity entVp2) |
||
569 | { |
||
570 | return AreGEntityEqual(entVp1, entVp2); |
||
571 | } |
||
572 | |||
573 | /// <summary> |
||
574 | /// 그래픽적으로 두 엔터티가 유사한지 검사한다. |
||
575 | /// </summary> |
||
576 | /// <param name="design1"></param> |
||
577 | /// <param name="ent1"></param> |
||
578 | /// <param name="design2"></param> |
||
579 | /// <param name="ent2"></param> |
||
580 | /// <returns></returns> |
||
581 | private bool AreEqual(Design design1, Entity ent1, Design design2, Entity ent2) |
||
582 | { |
||
583 | if (ent1 is CompositeCurve cc1 && ent2 is CompositeCurve cc2) |
||
584 | { |
||
585 | if (cc1.CurveList.Count == cc2.CurveList.Count) |
||
586 | { |
||
587 | int equalCurvesInListCount = 0; |
||
588 | foreach (var entC in cc1.CurveList) |
||
589 | { |
||
590 | foreach (var entC2 in cc2.CurveList) |
||
591 | { |
||
592 | if (entC.GetType() == entC2.GetType()) |
||
593 | { |
||
594 | if (entC is Entity && entC2 is Entity && CompareIfEqual(design1, entC as Entity, design2, entC2 as Entity)) |
||
595 | { |
||
596 | equalCurvesInListCount++; |
||
597 | break; |
||
598 | } |
||
599 | else if (entC is GEntity && entC2 is GEntity && CompareGEntityIfEqual(entC as GEntity, entC2 as GEntity)) |
||
600 | { |
||
601 | equalCurvesInListCount++; |
||
602 | break; |
||
603 | } |
||
604 | } |
||
605 | } |
||
606 | } |
||
607 | |||
608 | if (cc1.CurveList.Count == equalCurvesInListCount) |
||
609 | { |
||
610 | return true; |
||
611 | } |
||
612 | } |
||
613 | } |
||
614 | else if (ent1 is LinearPath lp1 && ent2 is LinearPath lp2) |
||
615 | { |
||
616 | if (lp1.Vertices.Length == lp2.Vertices.Length) |
||
617 | { |
||
618 | for (int i = 0; i < lp1.Vertices.Length; i++) |
||
619 | { |
||
620 | if (lp1.Vertices[i].DistanceTo(lp2.Vertices[i]) > Verification.Tolerance) |
||
621 | return false; |
||
622 | } |
||
623 | |||
624 | return true; |
||
625 | } |
||
626 | } |
||
627 | else if (ent1 is PlanarEntity pe1 && ent2 is PlanarEntity pe2) |
||
628 | { |
||
629 | if (ent1 is Arc arc1 && ent2 is Arc arc2) |
||
630 | { |
||
631 | if ( |
||
632 | arc1.Center.DistanceTo(arc2.Center) <= Verification.Tolerance && |
||
633 | Math.Abs(arc1.Radius - arc2.Radius) <= Verification.Tolerance && |
||
634 | Math.Abs(arc1.Domain.Min - arc2.Domain.Min) <= Verification.Tolerance && |
||
635 | Math.Abs(arc1.Domain.Max - arc2.Domain.Max) <= Verification.Tolerance |
||
636 | ) |
||
637 | { |
||
638 | return true; |
||
639 | } |
||
640 | } |
||
641 | else if (ent1 is Circle c1 && ent2 is Circle c2) |
||
642 | { |
||
643 | if ( |
||
644 | c1.Center.DistanceTo(c2.Center) <= Verification.Tolerance && |
||
645 | Math.Abs(c1.Radius - c2.Radius) <= Verification.Tolerance |
||
646 | ) |
||
647 | { |
||
648 | return true; |
||
649 | } |
||
650 | } |
||
651 | else if (ent1 is EllipticalArc e1 && ent2 is EllipticalArc e2) |
||
652 | { |
||
653 | if ( |
||
654 | e1.Center.DistanceTo(e2.Center) <= Verification.Tolerance && |
||
655 | Math.Abs(e1.RadiusX - e2.RadiusX) <= Verification.Tolerance && |
||
656 | Math.Abs(e1.RadiusY - e2.RadiusY) <= Verification.Tolerance && |
||
657 | Math.Abs(e1.Domain.Low - e2.Domain.Low) <= Verification.Tolerance && |
||
658 | Math.Abs(e1.Domain.High - e2.Domain.High) <= Verification.Tolerance |
||
659 | ) |
||
660 | { |
||
661 | return true; |
||
662 | } |
||
663 | } |
||
664 | else if (ent1 is Ellipse el1 && ent2 is Ellipse el2) |
||
665 | { |
||
666 | if ( |
||
667 | el1.Center.DistanceTo(el2.Center) <= Verification.Tolerance && |
||
668 | Math.Abs(el1.RadiusX - el2.RadiusX) <= Verification.Tolerance && |
||
669 | Math.Abs(el1.RadiusY - el2.RadiusY) <= Verification.Tolerance |
||
670 | ) |
||
671 | { |
||
672 | return true; |
||
673 | } |
||
674 | } |
||
675 | #region 해치는 삽입점만 비교 |
||
676 | else if (ent1 is Hatch hatch1 && ent2 is Hatch hatch2) |
||
677 | { |
||
678 | return hatch1.PatternOrigin.DistanceTo(hatch2.PatternOrigin) < Verification.Tolerance; |
||
679 | } |
||
680 | #endregion |
||
681 | else if (ent1 is Text) |
||
682 | { |
||
683 | if (ent1 is Dimension dim1 && ent2 is Dimension dim2) |
||
684 | { |
||
685 | if ( |
||
686 | dim1.InsertionPoint.DistanceTo(dim2.InsertionPoint) <= Verification.Tolerance && |
||
687 | dim1.DimLinePosition.DistanceTo(dim2.DimLinePosition) <= Verification.Tolerance |
||
688 | ) |
||
689 | { |
||
690 | if (ent1 is AngularDim ad1 && ent2 is AngularDim ad2) |
||
691 | { |
||
692 | if ( |
||
693 | ad1.ExtLine1.DistanceTo(ad2.ExtLine1) <= Verification.Tolerance && |
||
694 | ad1.ExtLine2.DistanceTo(ad2.ExtLine2) <= Verification.Tolerance && |
||
695 | Math.Abs(ad1.StartAngle - ad2.StartAngle) <= Verification.Tolerance && |
||
696 | Math.Abs(ad1.EndAngle - ad2.EndAngle) <= Verification.Tolerance && |
||
697 | Math.Abs(ad1.Radius - ad2.Radius) <= Verification.Tolerance |
||
698 | ) |
||
699 | { |
||
700 | return true; |
||
701 | } |
||
702 | } |
||
703 | else if (ent1 is LinearDim ld1 && ent2 is LinearDim ld2) |
||
704 | { |
||
705 | if ( |
||
706 | ld1.ExtLine1.DistanceTo(ld2.ExtLine1) <= Verification.Tolerance && |
||
707 | ld1.ExtLine2.DistanceTo(ld2.ExtLine2) <= Verification.Tolerance |
||
708 | ) |
||
709 | { |
||
710 | return true; |
||
711 | } |
||
712 | } |
||
713 | else if (ent1 is DiametricDim dd1 && ent2 is DiametricDim dd2) |
||
714 | { |
||
715 | if ( |
||
716 | Math.Abs(dd1.Distance - dd2.Distance) <= Verification.Tolerance && |
||
717 | Math.Abs(dd1.Radius - dd2.Radius) <= Verification.Tolerance && |
||
718 | Math.Abs(dd1.CenterMarkSize - dd2.CenterMarkSize) <= Verification.Tolerance |
||
719 | ) |
||
720 | { |
||
721 | return true; |
||
722 | } |
||
723 | } |
||
724 | else if (ent1 is RadialDim rd1 && ent2 is RadialDim rd2) |
||
725 | { |
||
726 | if ( |
||
727 | Math.Abs(rd1.Radius - rd2.Radius) <= Verification.Tolerance && |
||
728 | Math.Abs(rd1.CenterMarkSize - rd2.CenterMarkSize) <= Verification.Tolerance |
||
729 | ) |
||
730 | { |
||
731 | return true; |
||
732 | } |
||
733 | } |
||
734 | else if (ent1 is OrdinateDim od1 && ent2 is OrdinateDim od2) |
||
735 | { |
||
736 | if ( |
||
737 | od1.DefiningPoint.DistanceTo(od2.DefiningPoint) <= Verification.Tolerance && |
||
738 | od1.Origin.DistanceTo(od2.Origin) <= Verification.Tolerance && |
||
739 | od1.LeaderEndPoint.DistanceTo(od2.LeaderEndPoint) <= Verification.Tolerance |
||
740 | ) |
||
741 | { |
||
742 | return true; |
||
743 | } |
||
744 | } |
||
745 | else |
||
746 | { |
||
747 | Console.Write("Type " + ent1.GetType() + " not implemented."); |
||
748 | return true; |
||
749 | } |
||
750 | } |
||
751 | } |
||
752 | |||
753 | else if (ent1 is devDept.Eyeshot.Entities.Attribute att1 && ent2 is devDept.Eyeshot.Entities.Attribute att2) |
||
754 | { |
||
755 | if ( |
||
756 | att1.Value == att2.Value && |
||
757 | att1.InsertionPoint.DistanceTo(att2.InsertionPoint) <= Verification.Tolerance |
||
758 | ) |
||
759 | { |
||
760 | return true; |
||
761 | } |
||
762 | } |
||
763 | else |
||
764 | { |
||
765 | Text tx1 = (Text)ent1; |
||
766 | Text tx2 = (Text)ent2; |
||
767 | |||
768 | #region 대소문자, 공백을 무시하여 비교 |
||
769 | string string1 = tx1.TextString.Trim().ToUpper(); |
||
770 | string string2 = tx2.TextString.Trim().ToUpper(); |
||
771 | string1 = System.Text.RegularExpressions.Regex.Replace(string1, @"\s+", ""); |
||
772 | string2 = System.Text.RegularExpressions.Regex.Replace(string2, @"\s+", ""); |
||
773 | if ( |
||
774 | tx1.BoxMin.DistanceTo(tx2.BoxMin) <= Verification.Tolerance && |
||
775 | string1 == string2 && |
||
776 | Math.Abs(tx1.WidthFactor - tx2.WidthFactor) <= Verification.Tolerance && |
||
777 | Math.Abs(tx1.Height - tx2.Height) <= Verification.Tolerance |
||
778 | ) |
||
779 | { |
||
780 | return true; |
||
781 | } |
||
782 | #endregion |
||
783 | } |
||
784 | } |
||
785 | } |
||
786 | else if (ent1 is Line line1 && ent2 is Line line2) |
||
787 | { |
||
788 | var dir1 = line1.Direction; |
||
789 | dir1.Normalize(); |
||
790 | var dir2 = line2.Direction; |
||
791 | dir2.Normalize(); |
||
792 | if (devDept.Geometry.Vector3D.AreParallel(dir1, dir2, 0.1) && |
||
793 | Math.Abs(line1.Length() - line2.Length()) <= Verification.Tolerance && |
||
794 | line1.MidPoint.DistanceTo(line2.MidPoint) <= Verification.Tolerance |
||
795 | ) |
||
796 | { |
||
797 | return true; |
||
798 | } |
||
799 | } |
||
800 | else if (ent1 is Line && ent2 is devDept.Eyeshot.Entities.TabulatedSurface lwpolyline && lwpolyline.ControlPoints.Length == 4) |
||
801 | { |
||
802 | line1 = ent1 as Line; |
||
803 | var start = new devDept.Geometry.Point3D(lwpolyline.ControlPoints[0, 0].X, lwpolyline.ControlPoints[0, 0].Y, 0); |
||
804 | var end = new devDept.Geometry.Point3D(lwpolyline.ControlPoints[1, 0].X, lwpolyline.ControlPoints[1, 0].Y, 0); |
||
805 | var vec = new devDept.Geometry.Vector3D(start, end); |
||
806 | vec.Normalize(); |
||
807 | var dir = line1.Direction.Clone() as devDept.Geometry.Vector3D; |
||
808 | dir.Normalize(); |
||
809 | |||
810 | if ( |
||
811 | devDept.Geometry.Vector3D.AreParallel(dir, vec) && |
||
812 | line1.StartPoint.DistanceTo(start) <= Verification.Tolerance && |
||
813 | line1.EndPoint.DistanceTo(end) <= Verification.Tolerance |
||
814 | ) |
||
815 | { |
||
816 | return true; |
||
817 | } |
||
818 | } |
||
819 | else if (ent1 is devDept.Eyeshot.Entities.Point point1 && ent2 is devDept.Eyeshot.Entities.Point point2) |
||
820 | { |
||
821 | if (point1.Position.DistanceTo(point2.Position) <= Verification.Tolerance) |
||
822 | { |
||
823 | return true; |
||
824 | } |
||
825 | } |
||
826 | else if (ent1 is Curve cu1 && ent2 is Curve cu2) |
||
827 | { |
||
828 | if ( |
||
829 | cu1.ControlPoints.Length == cu2.ControlPoints.Length && |
||
830 | cu1.KnotVector.Length == cu2.KnotVector.Length && |
||
831 | cu1.Degree == cu2.Degree |
||
832 | ) |
||
833 | { |
||
834 | for (int k = 0; k < cu1.ControlPoints.Length; k++) |
||
835 | { |
||
836 | if (cu1.ControlPoints[k].DistanceTo(cu2.ControlPoints[k]) > Verification.Tolerance) |
||
837 | { |
||
838 | return false; |
||
839 | } |
||
840 | } |
||
841 | |||
842 | for (int k = 0; k < cu1.KnotVector.Length; k++) |
||
843 | { |
||
844 | if (cu1.KnotVector[k] != cu2.KnotVector[k]) |
||
845 | { |
||
846 | return false; |
||
847 | } |
||
848 | } |
||
849 | |||
850 | return true; |
||
851 | } |
||
852 | } |
||
853 | else if (ent1 is Mesh m1 && ent2 is Mesh m2 && m1.Vertices.Count() == m2.Vertices.Count()) |
||
854 | { |
||
855 | for (int i = 0; i < m1.Vertices.Count(); ++i) |
||
856 | { |
||
857 | if (m1.Vertices[i].DistanceTo(m2.Vertices[i]) > Verification.Tolerance) return false; |
||
858 | } |
||
859 | |||
860 | return true; |
||
861 | } |
||
862 | else if (ent1 is BlockReference blkref1 && ent2 is BlockReference blkref2) |
||
863 | { |
||
864 | int equalCurvesInEntityList = 0; |
||
865 | |||
866 | #region Point, Attribute, Text 제거 및 LinePath를 라인으로 분리 |
||
867 | var entities1 = blkref1.Explode(design1.Blocks).Where(x => x.LayerName != "AS_PORT" && !(x is devDept.Eyeshot.Entities.Point) && |
||
868 | !(x is devDept.Eyeshot.Entities.Attribute) && !(x is devDept.Eyeshot.Entities.Text)).ToList(); |
||
869 | var coll1 = new List<Entity>(); |
||
870 | entities1.ForEach(x => |
||
871 | { |
||
872 | if (x is LinearPath lp) |
||
873 | { |
||
874 | for (int i = 0; i < lp.Vertices.Length - 1; ++i) |
||
875 | { |
||
876 | if (lp.Vertices[i].DistanceTo(lp.Vertices[i + 1]) < 0.1) continue; |
||
877 | coll1.Add(new Line(lp.Vertices[i], lp.Vertices[i + 1])); |
||
878 | } |
||
879 | } |
||
880 | else |
||
881 | { |
||
882 | coll1.Add(x); |
||
883 | } |
||
884 | }); |
||
885 | #endregion |
||
886 | |||
887 | #region Point 및 Nesting Block 제거 및 LinePath를 라인으로 분리 |
||
888 | var entities2 = blkref2.Explode(design2.Blocks).Where(x => |
||
889 | !(x is devDept.Eyeshot.Entities.BlockReference blkref && blkref.BlockName == "PORT") && !(x is devDept.Eyeshot.Entities.Point)).ToList(); |
||
890 | var coll2 = new List<Entity>(); |
||
891 | entities2.ForEach(x => |
||
892 | { |
||
893 | if (x is LinearPath lp) |
||
894 | { |
||
895 | for (int i = 0; i < lp.Vertices.Length - 1; ++i) |
||
896 | { |
||
897 | if (lp.Vertices[i].DistanceTo(lp.Vertices[i + 1]) < 0.1) continue; |
||
898 | coll2.Add(new Line(lp.Vertices[i], lp.Vertices[i + 1])); |
||
899 | } |
||
900 | } |
||
901 | else if (x is devDept.Eyeshot.Entities.Attribute attr) |
||
902 | { |
||
903 | if (!attr.Invisible) coll2.Add(attr); |
||
904 | } |
||
905 | else if (x.GetType().Name == "AttributeReferenceData") |
||
906 | { |
||
907 | } |
||
908 | else |
||
909 | { |
||
910 | coll2.Add(x); |
||
911 | } |
||
912 | }); |
||
913 | #endregion |
||
914 | |||
915 | if (coll1.Count != coll2.Count) return false; |
||
916 | |||
917 | foreach (var entC in coll1) |
||
918 | { |
||
919 | foreach (var entC2 in coll2) |
||
920 | { |
||
921 | if (entC.GetType() == entC2.GetType()) |
||
922 | { |
||
923 | if (entC is Entity && entC2 is Entity && CompareIfEqual(design1, entC as Entity, design2, entC2 as Entity)) |
||
924 | { |
||
925 | equalCurvesInEntityList++; |
||
926 | break; |
||
927 | } |
||
928 | } |
||
929 | } |
||
930 | } |
||
931 | |||
932 | if (coll1.Count == equalCurvesInEntityList) |
||
933 | { |
||
934 | return true; |
||
935 | } |
||
936 | } |
||
937 | else |
||
938 | { |
||
939 | Console.Write("Type " + ent1.GetType() + " not implemented."); |
||
940 | return false; |
||
941 | } |
||
942 | |||
943 | return false; |
||
944 | } |
||
945 | |||
946 | private bool AreGEntityEqual(GEntity ent1, GEntity ent2) |
||
947 | { |
||
948 | if (ent1 is GCompositeCurve cc1 && ent2 is GCompositeCurve cc2) |
||
949 | { |
||
950 | if (cc1.CurveList.Count == cc2.CurveList.Count) |
||
951 | { |
||
952 | int equalCurvesInListCount = 0; |
||
953 | foreach (var entC in cc1.CurveList) |
||
954 | { |
||
955 | foreach (var entC2 in cc2.CurveList) |
||
956 | { |
||
957 | if (entC.GetType() == entC2.GetType()) |
||
958 | { |
||
959 | if (entC is GEntity && entC2 is GEntity && CompareGEntityIfEqual(entC as GEntity, entC2 as GEntity)) |
||
960 | { |
||
961 | equalCurvesInListCount++; |
||
962 | break; |
||
963 | } |
||
964 | } |
||
965 | } |
||
966 | } |
||
967 | |||
968 | if (cc1.CurveList.Count == equalCurvesInListCount) |
||
969 | { |
||
970 | return true; |
||
971 | } |
||
972 | } |
||
973 | } |
||
974 | else if (ent1 is GLinearPath lp1 && ent2 is GLinearPath lp2) |
||
975 | { |
||
976 | if (lp1.Vertices.Length == lp2.Vertices.Length) |
||
977 | { |
||
978 | for (int i = 0; i < lp1.Vertices.Length; i++) |
||
979 | { |
||
980 | if (lp1.Vertices[i].DistanceTo(lp2.Vertices[i]) > Verification.Tolerance) |
||
981 | return false; |
||
982 | } |
||
983 | return true; |
||
984 | } |
||
985 | } |
||
986 | |||
987 | else if (ent1 is GPlanarEntity pe1 && ent2 is GPlanarEntity pe2) |
||
988 | { |
||
989 | if ( |
||
990 | pe1.Plane.AxisZ == pe2.Plane.AxisZ && |
||
991 | pe1.Plane.AxisX == pe2.Plane.AxisX |
||
992 | ) |
||
993 | { |
||
994 | if (ent1 is GArc arc1 && ent2 is GArc arc2) |
||
995 | { |
||
996 | if ( |
||
997 | arc1.Center.DistanceTo(arc2.Center) <= Verification.Tolerance && |
||
998 | Math.Abs(arc1.Radius - arc2.Radius) <= Verification.Tolerance && |
||
999 | Math.Abs(arc1.Domain.Min - arc2.Domain.Min) <= Verification.Tolerance && |
||
1000 | Math.Abs(arc1.Domain.Max - arc2.Domain.Max) <= Verification.Tolerance |
||
1001 | ) |
||
1002 | { |
||
1003 | return true; |
||
1004 | } |
||
1005 | } |
||
1006 | else if (ent1 is GCircle c1 && ent2 is GCircle c2) |
||
1007 | { |
||
1008 | if (c1.Center.DistanceTo(c2.Center) <= Verification.Tolerance && |
||
1009 | Math.Abs(c1.Radius - c2.Radius) <= Verification.Tolerance) |
||
1010 | { |
||
1011 | return true; |
||
1012 | } |
||
1013 | } |
||
1014 | else if (ent1 is GEllipticalArc e1 && ent2 is GEllipticalArc e2) |
||
1015 | { |
||
1016 | if ( |
||
1017 | e1.Center.DistanceTo(e2.Center) <= Verification.Tolerance && |
||
1018 | Math.Abs(e1.RadiusX - e2.RadiusX) <= Verification.Tolerance && |
||
1019 | Math.Abs(e1.RadiusY - e2.RadiusY) <= Verification.Tolerance && |
||
1020 | Math.Abs(e1.Domain.Low - e2.Domain.Low) <= Verification.Tolerance && |
||
1021 | Math.Abs(e1.Domain.High - e2.Domain.High) <= Verification.Tolerance |
||
1022 | ) |
||
1023 | { |
||
1024 | return true; |
||
1025 | } |
||
1026 | } |
||
1027 | else if (ent1 is GEllipse el1 && ent2 is GEllipse el2) |
||
1028 | { |
||
1029 | if ( |
||
1030 | el1.Center.DistanceTo(el2.Center) <= Verification.Tolerance && |
||
1031 | Math.Abs(el1.RadiusX - el2.RadiusX) <= Verification.Tolerance && |
||
1032 | Math.Abs(el1.RadiusY - el2.RadiusY) <= Verification.Tolerance |
||
1033 | ) |
||
1034 | { |
||
1035 | return true; |
||
1036 | } |
||
1037 | } |
||
1038 | else |
||
1039 | { |
||
1040 | Console.Write("Type " + ent1.GetType() + " not implemented."); |
||
1041 | return true; |
||
1042 | } |
||
1043 | } |
||
1044 | } |
||
1045 | |||
1046 | else if (ent1 is GLine line1 && ent2 is GLine line2) |
||
1047 | { |
||
1048 | if (line1.StartPoint.DistanceTo(line2.StartPoint) <= Verification.Tolerance && |
||
1049 | line1.EndPoint.DistanceTo(line2.EndPoint) <= Verification.Tolerance |
||
1050 | ) |
||
1051 | { |
||
1052 | return true; |
||
1053 | } |
||
1054 | } |
||
1055 | #if NURBS |
||
1056 | else if (ent1 is Curve) |
||
1057 | { |
||
1058 | Curve cu1 = (Curve)ent1; |
||
1059 | Curve cu2 = (Curve)ent2; |
||
1060 | |||
1061 | if ( |
||
1062 | cu1.ControlPoints.Length == cu2.ControlPoints.Length && |
||
1063 | cu1.KnotVector.Length == cu2.KnotVector.Length && |
||
1064 | cu1.Degree == cu2.Degree |
||
1065 | ) |
||
1066 | { |
||
1067 | for (int k = 0; k < cu1.ControlPoints.Length; k++) |
||
1068 | { |
||
1069 | if (cu1.ControlPoints[k] != cu2.ControlPoints[k]) |
||
1070 | { |
||
1071 | return false; |
||
1072 | } |
||
1073 | } |
||
1074 | |||
1075 | for (int k = 0; k < cu1.KnotVector.Length; k++) |
||
1076 | { |
||
1077 | if (cu1.KnotVector[k] != cu2.KnotVector[k]) |
||
1078 | { |
||
1079 | return false; |
||
1080 | } |
||
1081 | } |
||
1082 | |||
1083 | return true; |
||
1084 | } |
||
1085 | } |
||
1086 | #endif |
||
1087 | |||
1088 | else |
||
1089 | { |
||
1090 | Console.Write("Type " + ent1.GetType() + " not implemented."); |
||
1091 | return true; |
||
1092 | } |
||
1093 | return false; |
||
1094 | } |
||
1095 | |||
1096 | #region Camera Sync |
||
1097 | private void CameraChanged(object sender, devDept.Eyeshot.Workspace.CameraMoveEventArgs e) |
||
1098 | { |
||
1099 | if (sender == this.designAutoCAD) |
||
1100 | SyncCamera(this.designAutoCAD, this.designAVEVA); |
||
1101 | else |
||
1102 | SyncCamera(this.designAVEVA, this.designAutoCAD); |
||
1103 | } |
||
1104 | |||
1105 | private void SyncCamera(Design designMovedCamera, Design designCameraToMove) |
||
1106 | { |
||
1107 | Camera savedCamera; |
||
1108 | designMovedCamera.SaveView(out savedCamera); |
||
1109 | |||
1110 | // restores the camera to the other model |
||
1111 | designCameraToMove.RestoreView(savedCamera); |
||
1112 | designCameraToMove.AdjustNearAndFarPlanes(); |
||
1113 | designCameraToMove.Invalidate(); |
||
1114 | } |
||
1115 | #endregion |
||
1116 | } |
||
1117 | } |