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