hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 0bbd73b5
이력 | 보기 | 이력해설 | 다운로드 (96.6 KB)
1 | cfda1fed | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using Llama; |
||
7 | using Plaice; |
||
8 | 8aa6f2db | gaqhf | using Ingr.RAD2D.Interop.RAD2D; |
9 | using Ingr.RAD2D.Internal; |
||
10 | using Ingr.RAD2D.Helper; |
||
11 | cfda1fed | gaqhf | using Converter.BaseModel; |
12 | using Converter.SPPID.Model; |
||
13 | using Converter.SPPID.Properties; |
||
14 | using Converter.SPPID.Util; |
||
15 | using Converter.SPPID.DB; |
||
16 | 5e6ecf05 | gaqhf | using Ingr.RAD2D.MacroControls.CmdCtrl; |
17 | using Ingr.RAD2D; |
||
18 | 5dfb8a24 | gaqhf | using System.Windows; |
19 | cfda1fed | gaqhf | using System.Threading; |
20 | 5dfb8a24 | gaqhf | using System.Drawing; |
21 | cfda1fed | gaqhf | using Microsoft.VisualBasic; |
22 | using Newtonsoft.Json; |
||
23 | |||
24 | ca214bc3 | gaqhf | using DevExpress.XtraSplashScreen; |
25 | cfda1fed | gaqhf | namespace Converter.SPPID |
26 | { |
||
27 | public class AutoModeling |
||
28 | { |
||
29 | 809a7640 | gaqhf | Placement _placement; |
30 | LMADataSource dataSource; |
||
31 | 1ba9c671 | gaqhf | dynamic newDrawing; |
32 | d19ae675 | gaqhf | dynamic application; |
33 | 5e6ecf05 | gaqhf | Ingr.RAD2D.Application radApp; |
34 | cfda1fed | gaqhf | SPPID_Document document; |
35 | b65a7e32 | gaqhf | ETCSetting _ETCSetting; |
36 | f1c9dbaa | gaqhf | |
37 | d5ec4d0f | gaqhf | public string DocumentLabelText { get; set; } |
38 | |||
39 | f31645b6 | gaqhf | int CurrentCount; |
40 | |||
41 | List <Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>(); |
||
42 | d19ae675 | gaqhf | public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp) |
43 | cfda1fed | gaqhf | { |
44 | this.document = document; |
||
45 | d19ae675 | gaqhf | this.application = application; |
46 | 5e6ecf05 | gaqhf | this.radApp = radApp; |
47 | b65a7e32 | gaqhf | this._ETCSetting = ETCSetting.GetInstance(); |
48 | cfda1fed | gaqhf | } |
49 | |||
50 | b265df51 | gaqhf | private int ClacProgressCount() |
51 | f31645b6 | gaqhf | { |
52 | b265df51 | gaqhf | int EquipCount = 0; |
53 | int SymbolCount = 0; |
||
54 | int LineCount = 0; |
||
55 | int NoteCount = 0; |
||
56 | int TextCount = 0; |
||
57 | int EndBreakCount = 0; |
||
58 | int LineNumberCount = 0; |
||
59 | |||
60 | f31645b6 | gaqhf | EquipCount = document.Equipments.Count; |
61 | SymbolCount = document.SYMBOLS.Count; |
||
62 | SymbolCount = SymbolCount * 3; |
||
63 | |||
64 | foreach (LineNumber lineNumber in document.LINENUMBERS) |
||
65 | foreach (LineRun run in lineNumber.RUNS) |
||
66 | foreach (var item in run.RUNITEMS) |
||
67 | if (item.GetType() == typeof(Line)) |
||
68 | LineCount++; |
||
69 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
70 | foreach (LineRun run in trimLine.RUNS) |
||
71 | foreach (var item in run.RUNITEMS) |
||
72 | if (item.GetType() == typeof(Line)) |
||
73 | LineCount++; |
||
74 | |||
75 | LineCount = LineCount * 2; |
||
76 | NoteCount = document.NOTES.Count; |
||
77 | TextCount = document.TEXTINFOS.Count; |
||
78 | EndBreakCount = document.EndBreaks.Count; |
||
79 | LineNumberCount = document.LINENUMBERS.Count; |
||
80 | LineNumberCount = LineNumberCount * 2; |
||
81 | |||
82 | b265df51 | gaqhf | return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount; |
83 | f31645b6 | gaqhf | } |
84 | |||
85 | 74752074 | gaqhf | /// <summary> |
86 | /// 도면 단위당 실행되는 메서드 |
||
87 | /// </summary> |
||
88 | 1ba9c671 | gaqhf | public void Run() |
89 | c2fef4ca | gaqhf | { |
90 | 1ba9c671 | gaqhf | try |
91 | c2fef4ca | gaqhf | { |
92 | 1ba9c671 | gaqhf | _placement = new Placement(); |
93 | dataSource = _placement.PIDDataSource; |
||
94 | |||
95 | 0e0edfad | gaqhf | CreateDocument(); |
96 | 1ba9c671 | gaqhf | |
97 | 0e0edfad | gaqhf | if (DocumentCoordinateCorrection()) |
98 | 310aeb31 | gaqhf | { |
99 | b265df51 | gaqhf | int AllCount = ClacProgressCount(); |
100 | 3939eebf | gaqhf | |
101 | 965eb728 | gaqhf | SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
102 | 20972c61 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount); |
103 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText); |
||
104 | 0e0edfad | gaqhf | Thread.Sleep(1000); |
105 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd); |
106 | 0e0edfad | gaqhf | Thread.Sleep(1000); |
107 | 965eb728 | gaqhf | |
108 | d1eac84d | gaqhf | List<List<Symbol>> symbolGroups = SPPIDUtil.GetThreeConnectedSymbolGroup(document); |
109 | foreach (List<Symbol> symbolGroup in symbolGroups) |
||
110 | SymbolModelingByThreeSymbolGroup(symbolGroup); |
||
111 | |||
112 | 3939eebf | gaqhf | // Equipment Modeling |
113 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling"); |
114 | 3939eebf | gaqhf | foreach (Equipment equipment in document.Equipments) |
115 | EquipmentModeling(equipment); |
||
116 | |||
117 | // LineRun Symbol Modeling |
||
118 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling"); |
119 | 3939eebf | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
120 | foreach (LineRun run in lineNumber.RUNS) |
||
121 | SymbolModelingByRun(run); |
||
122 | // TrimLineRun Symbol Modeling |
||
123 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
124 | foreach (LineRun run in trimLine.RUNS) |
||
125 | SymbolModelingByRun(run); |
||
126 | |||
127 | // LineRun Line Modeling |
||
128 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling"); |
129 | 3939eebf | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
130 | foreach (LineRun run in lineNumber.RUNS) |
||
131 | LineModelingByRun(run); |
||
132 | // TrimLineRun Line Modeling |
||
133 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
134 | foreach (LineRun run in trimLine.RUNS) |
||
135 | LineModelingByRun(run); |
||
136 | |||
137 | // Branch Line Modeling |
||
138 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling"); |
139 | 3939eebf | gaqhf | foreach (var item in BranchLines) |
140 | BranchLineModeling(item); |
||
141 | |||
142 | // EndBreak Modeling |
||
143 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling"); |
144 | 3939eebf | gaqhf | foreach (var item in document.EndBreaks) |
145 | EndBreakModeling(item); |
||
146 | |||
147 | // LineNumber Modeling |
||
148 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling"); |
149 | 3939eebf | gaqhf | foreach (var item in document.LINENUMBERS) |
150 | LineNumberModeling(item); |
||
151 | |||
152 | // Note Modeling |
||
153 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling"); |
154 | 3939eebf | gaqhf | foreach (var item in document.NOTES) |
155 | NoteModeling(item); |
||
156 | |||
157 | // Text Modeling |
||
158 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling"); |
159 | 3939eebf | gaqhf | foreach (var item in document.TEXTINFOS) |
160 | TextModeling(item); |
||
161 | |||
162 | // LineRun Line Join |
||
163 | 73415441 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns"); |
164 | 3939eebf | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
165 | foreach (LineRun run in lineNumber.RUNS) |
||
166 | JoinRunLine(run); |
||
167 | // TrimLineRun Line Join |
||
168 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
169 | foreach (LineRun run in trimLine.RUNS) |
||
170 | JoinRunLine(run); |
||
171 | |||
172 | // Input LineNumber Attribute |
||
173 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Lines Attribute"); |
174 | 3939eebf | gaqhf | foreach (var item in document.LINENUMBERS) |
175 | InputLineNumberAttribute(item); |
||
176 | |||
177 | // Input Symbol Attribute |
||
178 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute"); |
179 | 3939eebf | gaqhf | foreach (var item in document.SYMBOLS) |
180 | 73415441 | gaqhf | InputSymbolAttribute(item, item.ATTRIBUTES); |
181 | 3939eebf | gaqhf | |
182 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling"); |
183 | 3939eebf | gaqhf | foreach (var item in document.SYMBOLS) |
184 | 73415441 | gaqhf | LabelSymbolModeling(item); |
185 | f31645b6 | gaqhf | |
186 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount); |
||
187 | 310aeb31 | gaqhf | } |
188 | 809a7640 | gaqhf | } |
189 | 5e6ecf05 | gaqhf | catch (Exception ex) |
190 | { |
||
191 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
192 | } |
||
193 | finally |
||
194 | { |
||
195 | 1ba9c671 | gaqhf | application.ActiveWindow.Fit(); |
196 | 3939eebf | gaqhf | |
197 | 1ba9c671 | gaqhf | if (newDrawing != null) |
198 | 3939eebf | gaqhf | { |
199 | radApp.ActiveDocument.SaveOnClose = false; |
||
200 | radApp.ActiveDocument.Save(); |
||
201 | 1ba9c671 | gaqhf | ReleaseCOMObjects(newDrawing); |
202 | 3939eebf | gaqhf | } |
203 | 1ba9c671 | gaqhf | |
204 | 5e6ecf05 | gaqhf | ReleaseCOMObjects(dataSource); |
205 | ReleaseCOMObjects(_placement); |
||
206 | 965eb728 | gaqhf | |
207 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
208 | 965eb728 | gaqhf | SplashScreenManager.CloseForm(false); |
209 | 5e6ecf05 | gaqhf | } |
210 | 65a1ed4b | gaqhf | } |
211 | |||
212 | 74752074 | gaqhf | /// <summary> |
213 | /// 도면 생성 메서드 |
||
214 | /// </summary> |
||
215 | 0e0edfad | gaqhf | private void CreateDocument() |
216 | { |
||
217 | newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName); |
||
218 | application.ActiveWindow.Fit(); |
||
219 | Thread.Sleep(1000); |
||
220 | application.ActiveWindow.Zoom = 2000; |
||
221 | Thread.Sleep(2000); |
||
222 | } |
||
223 | |||
224 | 74752074 | gaqhf | /// <summary> |
225 | /// 도면 크기 구하는 메서드 |
||
226 | /// </summary> |
||
227 | /// <returns></returns> |
||
228 | 0e0edfad | gaqhf | private bool DocumentCoordinateCorrection() |
229 | { |
||
230 | double maxX = 0; |
||
231 | double maxY = 0; |
||
232 | foreach (object drawingObj in radApp.ActiveDocument.ActiveSheet.DrawingObjects) |
||
233 | { |
||
234 | Ingr.RAD2D.SmartFrame2d smartFrame2d = drawingObj as Ingr.RAD2D.SmartFrame2d; |
||
235 | if (smartFrame2d != null) |
||
236 | { |
||
237 | double x1 = 0; |
||
238 | double x2 = 0; |
||
239 | double y1 = 0; |
||
240 | double y2 = 0; |
||
241 | smartFrame2d.Range(out x1, out y1, out x2, out y2); |
||
242 | maxX = Math.Max(x2, maxX); |
||
243 | maxY = Math.Max(y2, maxY); |
||
244 | } |
||
245 | } |
||
246 | if (maxX != 0 && maxY != 0) |
||
247 | { |
||
248 | document.SetSPPIDLocation(maxX, maxY); |
||
249 | return true; |
||
250 | } |
||
251 | else |
||
252 | return false; |
||
253 | } |
||
254 | |||
255 | 74752074 | gaqhf | /// <summary> |
256 | /// 라인을 Run 단위로 모델링하는 진입 메서드 |
||
257 | /// </summary> |
||
258 | /// <param name="run"></param> |
||
259 | 8aa6f2db | gaqhf | private void LineModelingByRun(LineRun run) |
260 | 809a7640 | gaqhf | { |
261 | Line prevLine = null; |
||
262 | List<Line> lines = new List<Line>(); |
||
263 | foreach (var item in run.RUNITEMS) |
||
264 | { |
||
265 | // Line일 경우 |
||
266 | if (item.GetType() == typeof(Line)) |
||
267 | { |
||
268 | Line line = item as Line; |
||
269 | if (prevLine == null) |
||
270 | lines.Add(line); |
||
271 | else if (prevLine != null) |
||
272 | { |
||
273 | if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
||
274 | lines.Add(line); |
||
275 | else |
||
276 | f1c9dbaa | gaqhf | { |
277 | f2baa6a3 | gaqhf | if (lines.Count > 0) |
278 | { |
||
279 | LineModeling(lines); |
||
280 | lines.Clear(); |
||
281 | } |
||
282 | 809a7640 | gaqhf | lines.Add(line); |
283 | 5dfb8a24 | gaqhf | } |
284 | } |
||
285 | |||
286 | 809a7640 | gaqhf | prevLine = line; |
287 | f31645b6 | gaqhf | |
288 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
289 | 809a7640 | gaqhf | } |
290 | // Symbol 일 경우 |
||
291 | else if (item.GetType() == typeof(Symbol)) |
||
292 | { |
||
293 | f1c9dbaa | gaqhf | if (lines.Count > 0) |
294 | 809a7640 | gaqhf | { |
295 | f1c9dbaa | gaqhf | LineModeling(lines); |
296 | 809a7640 | gaqhf | lines.Clear(); |
297 | } |
||
298 | 5dfb8a24 | gaqhf | } |
299 | } |
||
300 | |||
301 | 809a7640 | gaqhf | if (lines.Count > 0) |
302 | LineModeling(lines); |
||
303 | } |
||
304 | 5dfb8a24 | gaqhf | |
305 | 74752074 | gaqhf | /// <summary> |
306 | /// 심볼을 Run 단위로 모델링하는 진입 메서드 |
||
307 | /// </summary> |
||
308 | /// <param name="run"></param> |
||
309 | 8aa6f2db | gaqhf | private void SymbolModelingByRun(LineRun run) |
310 | 809a7640 | gaqhf | { |
311 | // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling |
||
312 | if (run.RUNITEMS.Count > 0) |
||
313 | { |
||
314 | if (run.RUNITEMS[0].GetType() == typeof(Symbol)) |
||
315 | SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run); |
||
316 | |||
317 | if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol)) |
||
318 | SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run); |
||
319 | } |
||
320 | |||
321 | Symbol prevSymbol = null; |
||
322 | Symbol targetSymbol = null; |
||
323 | foreach (var item in run.RUNITEMS) |
||
324 | { |
||
325 | if (item.GetType() == typeof(Symbol)) |
||
326 | { |
||
327 | Symbol symbol = item as Symbol; |
||
328 | SymbolModeling(symbol, targetSymbol, prevSymbol); |
||
329 | prevSymbol = symbol; |
||
330 | targetSymbol = symbol; |
||
331 | } |
||
332 | else |
||
333 | { |
||
334 | targetSymbol = null; |
||
335 | } |
||
336 | } |
||
337 | } |
||
338 | |||
339 | 74752074 | gaqhf | /// <summary> |
340 | /// Run에 있는 심볼을 모델링하는데 기준이 Run의 시작점 |
||
341 | /// </summary> |
||
342 | /// <param name="symbol"></param> |
||
343 | /// <param name="run"></param> |
||
344 | 8aa6f2db | gaqhf | private void SymbolModelingByRunStart(Symbol symbol, LineRun run) |
345 | 809a7640 | gaqhf | { |
346 | foreach (var connector in symbol.CONNECTORS) |
||
347 | { |
||
348 | object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
349 | if (targetItem != null && |
||
350 | (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
||
351 | 74752074 | gaqhf | !IsSameLineRun(symbol, targetItem)) |
352 | 809a7640 | gaqhf | { |
353 | SymbolModeling(symbol, targetItem as Symbol, null); |
||
354 | for (int i = 1; i < run.RUNITEMS.Count; i++) |
||
355 | { |
||
356 | object item = run.RUNITEMS[i]; |
||
357 | if (item.GetType() == typeof(Symbol)) |
||
358 | SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null); |
||
359 | else |
||
360 | break; |
||
361 | } |
||
362 | break; |
||
363 | } |
||
364 | } |
||
365 | |||
366 | |||
367 | } |
||
368 | |||
369 | 74752074 | gaqhf | /// <summary> |
370 | /// Run에 있는 심볼을 모델링하는데 기준이 Run의 끝점 |
||
371 | /// </summary> |
||
372 | /// <param name="symbol"></param> |
||
373 | /// <param name="run"></param> |
||
374 | 8aa6f2db | gaqhf | private void SymbolModelingByRunEnd(Symbol symbol, LineRun run) |
375 | 809a7640 | gaqhf | { |
376 | foreach (var connector in symbol.CONNECTORS) |
||
377 | { |
||
378 | object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
379 | if (targetItem != null && |
||
380 | (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
||
381 | 74752074 | gaqhf | !IsSameLineRun(symbol, targetItem)) |
382 | 809a7640 | gaqhf | { |
383 | SymbolModeling(symbol, targetItem as Symbol, null); |
||
384 | for (int i = run.RUNITEMS.Count - 2; i >= 0; i--) |
||
385 | { |
||
386 | object item = run.RUNITEMS[i]; |
||
387 | if (item.GetType() == typeof(Symbol)) |
||
388 | SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null); |
||
389 | else |
||
390 | break; |
||
391 | } |
||
392 | break; |
||
393 | } |
||
394 | } |
||
395 | 5dfb8a24 | gaqhf | } |
396 | cfda1fed | gaqhf | |
397 | 74752074 | gaqhf | /// <summary> |
398 | /// 심볼을 실제로 Modeling 메서드 |
||
399 | /// </summary> |
||
400 | /// <param name="symbol"></param> |
||
401 | /// <param name="targetSymbol"></param> |
||
402 | /// <param name="prevSymbol"></param> |
||
403 | 809a7640 | gaqhf | private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol) |
404 | { |
||
405 | 73415441 | gaqhf | // OWNERSYMBOL Attribute, 값을 가지고 있을 경우 |
406 | BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL"); |
||
407 | if (itemAttribute != null && string.IsNullOrEmpty(itemAttribute.VALUE) && itemAttribute.VALUE != "None") |
||
408 | c3d2e266 | gaqhf | return; |
409 | 73415441 | gaqhf | // 이미 모델링 됐을 경우 |
410 | else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
||
411 | 809a7640 | gaqhf | return; |
412 | |||
413 | LMSymbol _LMSymbol = null; |
||
414 | |||
415 | string mappingPath = symbol.SPPID.MAPPINGNAME; |
||
416 | double x = symbol.SPPID.ORIGINAL_X; |
||
417 | double y = symbol.SPPID.ORIGINAL_Y; |
||
418 | int mirror = 0; |
||
419 | double angle = symbol.ANGLE; |
||
420 | 20972c61 | gaqhf | |
421 | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
||
422 | |||
423 | 73415441 | gaqhf | // OPC 일경우 180도 일때 Mirror |
424 | c2fef4ca | gaqhf | if (mappingPath.Contains("Piping OPC's") && angle == Math.PI) |
425 | mirror = 1; |
||
426 | 809a7640 | gaqhf | |
427 | if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
||
428 | { |
||
429 | LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
||
430 | 2fdb56bf | gaqhf | Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol); |
431 | if (connector != null) |
||
432 | GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y); |
||
433 | |||
434 | 809a7640 | gaqhf | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
435 | ReleaseCOMObjects(_TargetItem); |
||
436 | } |
||
437 | else if (prevSymbol != null) |
||
438 | { |
||
439 | LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
||
440 | SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
||
441 | double prevX = _PrevSymbol.get_XCoordinate(); |
||
442 | double prevY = _PrevSymbol.get_YCoordinate(); |
||
443 | 06b40010 | gaqhf | //if (slopeType == SlopeType.HORIZONTAL) |
444 | // y = prevY; |
||
445 | //else if (slopeType == SlopeType.VERTICAL) |
||
446 | // x = prevX; |
||
447 | ReleaseCOMObjects(_PrevSymbol); |
||
448 | 809a7640 | gaqhf | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
449 | } |
||
450 | else |
||
451 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
452 | |||
453 | |||
454 | if (_LMSymbol != null) |
||
455 | { |
||
456 | _LMSymbol.Commit(); |
||
457 | symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
458 | 20972c61 | gaqhf | symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID(); |
459 | ac78b508 | gaqhf | |
460 | 4b4dbca9 | gaqhf | foreach (var item in symbol.ChildSymbols) |
461 | CreateChildSymbol(item, _LMSymbol); |
||
462 | 809a7640 | gaqhf | } |
463 | |||
464 | ReleaseCOMObjects(_LMSymbol); |
||
465 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
466 | 809a7640 | gaqhf | } |
467 | |||
468 | d1eac84d | gaqhf | /// <summary> |
469 | /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다. |
||
470 | /// </summary> |
||
471 | /// <param name="targetConnector"></param> |
||
472 | /// <param name="targetSymbol"></param> |
||
473 | /// <param name="x"></param> |
||
474 | /// <param name="y"></param> |
||
475 | private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y) |
||
476 | { |
||
477 | LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
||
478 | 2fdb56bf | gaqhf | |
479 | double[] range = null; |
||
480 | d1eac84d | gaqhf | List<double[]> points = new List<double[]>(); |
481 | 2fdb56bf | gaqhf | GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points); |
482 | double x1 = range[0]; |
||
483 | double y1 = range[1]; |
||
484 | double x2 = range[2]; |
||
485 | double y2 = range[3]; |
||
486 | d1eac84d | gaqhf | |
487 | // Origin 기준 Connector의 위치차이 |
||
488 | double sceneX = 0; |
||
489 | double sceneY = 0; |
||
490 | SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY); |
||
491 | double originX = 0; |
||
492 | double originY = 0; |
||
493 | SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY); |
||
494 | double gapX = originX - sceneX; |
||
495 | double gapY = originY - sceneY; |
||
496 | |||
497 | // SPPID Symbol과 ID2 심볼의 크기 차이 |
||
498 | double sizeWidth = 0; |
||
499 | double sizeHeight = 0; |
||
500 | SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight); |
||
501 | double percentX = (x2 - x1) / sizeWidth; |
||
502 | double percentY = (y2 - y1) / sizeHeight; |
||
503 | |||
504 | double SPPIDgapX = gapX * percentX; |
||
505 | double SPPIDgapY = gapY * percentY; |
||
506 | |||
507 | double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY }; |
||
508 | double distance = double.MaxValue; |
||
509 | double[] resultPoint; |
||
510 | foreach (var point in points) |
||
511 | { |
||
512 | double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]); |
||
513 | if (distance > result) |
||
514 | { |
||
515 | distance = result; |
||
516 | resultPoint = point; |
||
517 | x = point[0]; |
||
518 | y = point[1]; |
||
519 | } |
||
520 | } |
||
521 | 2fdb56bf | gaqhf | |
522 | ReleaseCOMObjects(_TargetItem); |
||
523 | } |
||
524 | |||
525 | /// <summary> |
||
526 | /// SPPID Symbol의 Range를 구한다. |
||
527 | /// </summary> |
||
528 | /// <param name="symbol"></param> |
||
529 | /// <param name="range"></param> |
||
530 | private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points) |
||
531 | { |
||
532 | LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
533 | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
||
534 | double x1 = 0; |
||
535 | double y1 = 0; |
||
536 | double x2 = 0; |
||
537 | double y2 = 0; |
||
538 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
539 | range = new double[] { x1, y1, x2, y2 }; |
||
540 | |||
541 | for (int i = 1; i < int.MaxValue; i++) |
||
542 | { |
||
543 | double connX = 0; |
||
544 | double connY = 0; |
||
545 | if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY)) |
||
546 | points.Add(new double[] { connX, connY }); |
||
547 | else |
||
548 | break; |
||
549 | } |
||
550 | |||
551 | foreach (var childSymbol in symbol.ChildSymbols) |
||
552 | GetSPPIDChildSymbolRange(childSymbol, ref range, points); |
||
553 | |||
554 | ReleaseCOMObjects(_TargetItem); |
||
555 | } |
||
556 | |||
557 | /// <summary> |
||
558 | /// Child Modeling 된 Symbol의 Range를 구한다. |
||
559 | /// </summary> |
||
560 | /// <param name="childSymbol"></param> |
||
561 | /// <param name="range"></param> |
||
562 | private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points) |
||
563 | { |
||
564 | LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId); |
||
565 | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()]; |
||
566 | double x1 = 0; |
||
567 | double y1 = 0; |
||
568 | double x2 = 0; |
||
569 | double y2 = 0; |
||
570 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
571 | range[0] = Math.Min(range[0], x1); |
||
572 | range[1] = Math.Min(range[1], y1); |
||
573 | range[2] = Math.Max(range[2], x2); |
||
574 | range[3] = Math.Max(range[3], y2); |
||
575 | |||
576 | for (int i = 1; i < int.MaxValue; i++) |
||
577 | { |
||
578 | double connX = 0; |
||
579 | double connY = 0; |
||
580 | if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY)) |
||
581 | points.Add(new double[] { connX, connY }); |
||
582 | else |
||
583 | break; |
||
584 | } |
||
585 | |||
586 | foreach (var loopChildSymbol in childSymbol.ChildSymbols) |
||
587 | GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points); |
||
588 | |||
589 | ReleaseCOMObjects(_ChildSymbol); |
||
590 | d1eac84d | gaqhf | } |
591 | |||
592 | /// <summary> |
||
593 | /// Label Symbol Modeling |
||
594 | /// </summary> |
||
595 | /// <param name="symbol"></param> |
||
596 | 73415441 | gaqhf | private void LabelSymbolModeling(Symbol symbol) |
597 | { |
||
598 | BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL"); |
||
599 | if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE)) |
||
600 | return; |
||
601 | |||
602 | Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y }; |
||
603 | |||
604 | string symbolUID = itemAttribute.VALUE; |
||
605 | object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID); |
||
606 | if (targetItem != null) |
||
607 | { |
||
608 | // Object 아이템이 Symbol일 경우 Equipment일 경우 |
||
609 | string sRep = null; |
||
610 | if (targetItem.GetType() == typeof(Symbol)) |
||
611 | sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
||
612 | else if (targetItem.GetType() == typeof(Equipment)) |
||
613 | sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
||
614 | |||
615 | if (!string.IsNullOrEmpty(sRep)) |
||
616 | { |
||
617 | // LEADER Line 검사 |
||
618 | bool leaderLine = false; |
||
619 | SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID); |
||
620 | if (symbolMapping != null) |
||
621 | leaderLine = symbolMapping.LEADERLINE; |
||
622 | |||
623 | // Target Symbol Item 가져오고 Label Modeling |
||
624 | LMSymbol _TargetItem = dataSource.GetSymbol(sRep); |
||
625 | LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
||
626 | |||
627 | // Target Item에 Label의 Attribute Input |
||
628 | InputSymbolAttribute(targetItem, symbol.ATTRIBUTES); |
||
629 | |||
630 | //Leader 선 센터로 |
||
631 | string OID = _LMLabelPresist.get_GraphicOID(); |
||
632 | DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject; |
||
633 | if (dependency != null) |
||
634 | { |
||
635 | bool result = false; |
||
636 | foreach (var attributes in dependency.AttributeSets) |
||
637 | { |
||
638 | foreach (var attribute in attributes) |
||
639 | { |
||
640 | string name = attribute.Name; |
||
641 | string value = attribute.GetValue().ToString(); |
||
642 | if (name == "DrawingItemType" && value == "LabelPersist") |
||
643 | { |
||
644 | foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects) |
||
645 | { |
||
646 | if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d) |
||
647 | { |
||
648 | Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d; |
||
649 | double prevX = _TargetItem.get_XCoordinate(); |
||
650 | double prevY = _TargetItem.get_YCoordinate(); |
||
651 | lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY); |
||
652 | lineString2D.RemoveVertex(lineString2D.VertexCount); |
||
653 | result = true; |
||
654 | break; |
||
655 | } |
||
656 | } |
||
657 | } |
||
658 | |||
659 | if (result) |
||
660 | break; |
||
661 | } |
||
662 | |||
663 | if (result) |
||
664 | break; |
||
665 | } |
||
666 | } |
||
667 | |||
668 | _LMLabelPresist.Commit(); |
||
669 | ReleaseCOMObjects(_TargetItem); |
||
670 | ReleaseCOMObjects(_LMLabelPresist); |
||
671 | } |
||
672 | } |
||
673 | |||
674 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
675 | } |
||
676 | |||
677 | 74752074 | gaqhf | /// <summary> |
678 | /// Equipment를 실제로 Modeling 메서드 |
||
679 | /// </summary> |
||
680 | /// <param name="equipment"></param> |
||
681 | b9e9f4c8 | gaqhf | private void EquipmentModeling(Equipment equipment) |
682 | { |
||
683 | if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId)) |
||
684 | return; |
||
685 | |||
686 | LMSymbol _LMSymbol = null; |
||
687 | LMSymbol targetItem = null; |
||
688 | string mappingPath = equipment.SPPID.MAPPINGNAME; |
||
689 | double x = equipment.SPPID.ORIGINAL_X; |
||
690 | double y = equipment.SPPID.ORIGINAL_Y; |
||
691 | int mirror = 0; |
||
692 | double angle = equipment.ANGLE; |
||
693 | |||
694 | 20972c61 | gaqhf | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
695 | |||
696 | b9e9f4c8 | gaqhf | Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None"); |
697 | if (connector != null) |
||
698 | { |
||
699 | Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment; |
||
700 | if (connEquipment != null) |
||
701 | { |
||
702 | if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
||
703 | EquipmentModeling(connEquipment); |
||
704 | |||
705 | if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
||
706 | { |
||
707 | targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId); |
||
708 | if (targetItem != null) |
||
709 | { |
||
710 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
||
711 | } |
||
712 | else |
||
713 | { |
||
714 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
715 | } |
||
716 | } |
||
717 | else |
||
718 | { |
||
719 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
720 | } |
||
721 | } |
||
722 | else |
||
723 | { |
||
724 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
725 | } |
||
726 | } |
||
727 | else |
||
728 | { |
||
729 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
730 | } |
||
731 | |||
732 | if (_LMSymbol != null) |
||
733 | { |
||
734 | _LMSymbol.Commit(); |
||
735 | equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
736 | 20972c61 | gaqhf | equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID(); |
737 | b9e9f4c8 | gaqhf | ReleaseCOMObjects(_LMSymbol); |
738 | } |
||
739 | |||
740 | if (targetItem != null) |
||
741 | { |
||
742 | ReleaseCOMObjects(targetItem); |
||
743 | } |
||
744 | |||
745 | ReleaseCOMObjects(_LMSymbol); |
||
746 | f31645b6 | gaqhf | |
747 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
748 | b9e9f4c8 | gaqhf | } |
749 | |||
750 | 74752074 | gaqhf | /// <summary> |
751 | d1eac84d | gaqhf | /// 3개의 Symbol이 붙어있을경우 CenterSymbol을 Grid기준으로 맞추기 위해서 모델링 |
752 | /// </summary> |
||
753 | /// <param name="group"></param> |
||
754 | private void SymbolModelingByThreeSymbolGroup(List<Symbol> group) |
||
755 | { |
||
756 | // Group의 가운데 찾기 |
||
757 | Symbol symbol1 = null; |
||
758 | Symbol symbol2 = null; |
||
759 | Symbol centerSymbol = null; |
||
760 | foreach (var symbol in group) |
||
761 | { |
||
762 | int count = 0; |
||
763 | foreach (var connector in symbol.CONNECTORS) |
||
764 | { |
||
765 | object item = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
766 | if (item != null && item.GetType() == typeof(Symbol)) |
||
767 | count++; |
||
768 | } |
||
769 | |||
770 | // Center Symbol |
||
771 | if (count == 2) |
||
772 | { |
||
773 | SymbolModeling(symbol, null, null); |
||
774 | centerSymbol = symbol; |
||
775 | } |
||
776 | else if (symbol1 == null) |
||
777 | symbol1 = symbol; |
||
778 | else |
||
779 | symbol2 = symbol; |
||
780 | } |
||
781 | |||
782 | SymbolModeling(symbol1, centerSymbol, null); |
||
783 | SymbolModeling(symbol2, centerSymbol, null); |
||
784 | } |
||
785 | |||
786 | /// <summary> |
||
787 | 74752074 | gaqhf | /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드 |
788 | /// </summary> |
||
789 | /// <param name="childSymbol"></param> |
||
790 | /// <param name="parentSymbol"></param> |
||
791 | 4b4dbca9 | gaqhf | private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol) |
792 | ac78b508 | gaqhf | { |
793 | 4b4dbca9 | gaqhf | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()]; |
794 | double x1 = 0; |
||
795 | double x2 = 0; |
||
796 | double y1 = 0; |
||
797 | double y2 = 0; |
||
798 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
799 | |||
800 | LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol); |
||
801 | if (_LMSymbol != null) |
||
802 | { |
||
803 | childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
804 | foreach (var item in childSymbol.ChildSymbols) |
||
805 | CreateChildSymbol(item, _LMSymbol); |
||
806 | } |
||
807 | |||
808 | ac78b508 | gaqhf | |
809 | ReleaseCOMObjects(_LMSymbol); |
||
810 | } |
||
811 | |||
812 | 74752074 | gaqhf | /// <summary> |
813 | /// item이 TargetItem과 같은 LineRun에 있는지 검사 |
||
814 | /// </summary> |
||
815 | /// <param name="item"></param> |
||
816 | /// <param name="targetItem"></param> |
||
817 | /// <returns></returns> |
||
818 | private bool IsSameLineRun(object item, object targetItem) |
||
819 | 809a7640 | gaqhf | { |
820 | foreach (var lineNumber in document.LINENUMBERS) |
||
821 | { |
||
822 | foreach (var run in lineNumber.RUNS) |
||
823 | { |
||
824 | foreach (var runItem in run.RUNITEMS) |
||
825 | { |
||
826 | if (runItem == item) |
||
827 | { |
||
828 | foreach (var findItem in run.RUNITEMS) |
||
829 | { |
||
830 | if (findItem == targetItem) |
||
831 | { |
||
832 | return true; |
||
833 | } |
||
834 | } |
||
835 | |||
836 | return false; |
||
837 | |||
838 | } |
||
839 | } |
||
840 | } |
||
841 | } |
||
842 | |||
843 | return false; |
||
844 | } |
||
845 | |||
846 | 74752074 | gaqhf | /// <summary> |
847 | /// Line을 실제로 모델링하는 메서드 |
||
848 | /// </summary> |
||
849 | /// <param name="lines"></param> |
||
850 | 1b261371 | gaqhf | private void LineModeling(List<Line> lines) |
851 | { |
||
852 | 335b7a24 | gaqhf | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
853 | 1b261371 | gaqhf | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
854 | f1c9dbaa | gaqhf | LMSymbol _LMSymbol1 = null; |
855 | LMSymbol _LMSymbol2 = null; |
||
856 | 5e6ecf05 | gaqhf | Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
857 | LMConnector targetConnector1 = null; |
||
858 | Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
||
859 | LMConnector targetConnector2 = null; |
||
860 | 335b7a24 | gaqhf | |
861 | Line startBranchLine = null; |
||
862 | Line endBranchLine = null; |
||
863 | |||
864 | 0bbd73b5 | gaqhf | // Type, Line, TargetObjet, x, y |
865 | List<Tuple<string, Line, object, double, double>> linePointInfo = new List<Tuple<string, Line, object, double, double>>(); |
||
866 | // Point 정리 |
||
867 | 1b261371 | gaqhf | for (int i = 0; i < lines.Count; i++) |
868 | { |
||
869 | Line line = lines[i]; |
||
870 | f1c9dbaa | gaqhf | if (i == 0 || i + 1 != lines.Count) |
871 | { |
||
872 | 809a7640 | gaqhf | // 시작점에 연결된 Symbol 찾기 |
873 | f1c9dbaa | gaqhf | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
874 | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
||
875 | { |
||
876 | 2fdb56bf | gaqhf | Symbol symbol1 = connItem as Symbol; |
877 | _LMSymbol1 = GetTargetSymbol(symbol1, line); |
||
878 | f1c9dbaa | gaqhf | if (_LMSymbol1 != null) |
879 | 2fdb56bf | gaqhf | { |
880 | double x = line.SPPID.START_X; |
||
881 | double y = line.SPPID.START_Y; |
||
882 | Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol1); |
||
883 | if (connector != null) |
||
884 | { |
||
885 | GetTargetSymbolConnectorPoint(connector, symbol1, ref x, ref y); |
||
886 | line.SPPID.START_X = x; |
||
887 | line.SPPID.START_Y = y; |
||
888 | } |
||
889 | |||
890 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol1, x, y)); |
891 | 2fdb56bf | gaqhf | } |
892 | f1c9dbaa | gaqhf | else |
893 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
894 | f1c9dbaa | gaqhf | } |
895 | 335b7a24 | gaqhf | else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
896 | 5e6ecf05 | gaqhf | { |
897 | connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
||
898 | 56bc67e1 | gaqhf | targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
899 | 5e6ecf05 | gaqhf | |
900 | if (targetConnector1 != null) |
||
901 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector1, line.SPPID.START_X, line.SPPID.START_Y)); |
902 | 5e6ecf05 | gaqhf | else |
903 | 335b7a24 | gaqhf | { |
904 | startBranchLine = connItem as Line; |
||
905 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
906 | 335b7a24 | gaqhf | } |
907 | 5e6ecf05 | gaqhf | } |
908 | f1c9dbaa | gaqhf | else |
909 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
910 | ca7d0ada | gaqhf | |
911 | f1c9dbaa | gaqhf | } |
912 | if (i + 1 == lines.Count) |
||
913 | { |
||
914 | 809a7640 | gaqhf | // 끝점에 연결된 Symbol 찾기 |
915 | f1c9dbaa | gaqhf | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
916 | 5e6ecf05 | gaqhf | |
917 | if (i != 0) |
||
918 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
919 | 5e6ecf05 | gaqhf | |
920 | f1c9dbaa | gaqhf | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
921 | { |
||
922 | 2fdb56bf | gaqhf | Symbol symbol2 = connItem as Symbol; |
923 | f2baa6a3 | gaqhf | _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line); |
924 | f1c9dbaa | gaqhf | if (_LMSymbol2 != null) |
925 | 2fdb56bf | gaqhf | { |
926 | double x = line.SPPID.END_X; |
||
927 | double y = line.SPPID.END_Y; |
||
928 | Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol2); |
||
929 | if (connector != null) |
||
930 | { |
||
931 | GetTargetSymbolConnectorPoint(connector, symbol2, ref x, ref y); |
||
932 | line.SPPID.END_X = x; |
||
933 | line.SPPID.END_Y = y; |
||
934 | } |
||
935 | |||
936 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol2, x, y)); |
937 | 2fdb56bf | gaqhf | } |
938 | f1c9dbaa | gaqhf | else |
939 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
940 | f1c9dbaa | gaqhf | } |
941 | 335b7a24 | gaqhf | else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
942 | 5e6ecf05 | gaqhf | { |
943 | connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
||
944 | 56bc67e1 | gaqhf | targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y); |
945 | 5e6ecf05 | gaqhf | |
946 | if (targetConnector2 != null) |
||
947 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector2, line.SPPID.END_X, line.SPPID.END_Y)); |
948 | 5e6ecf05 | gaqhf | else |
949 | 335b7a24 | gaqhf | { |
950 | endBranchLine = connItem as Line; |
||
951 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
952 | 335b7a24 | gaqhf | } |
953 | 5e6ecf05 | gaqhf | } |
954 | f1c9dbaa | gaqhf | else |
955 | 0bbd73b5 | gaqhf | linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
956 | f1c9dbaa | gaqhf | } |
957 | } |
||
958 | |||
959 | 0bbd73b5 | gaqhf | double prevX = double.NaN; |
960 | double prevY = double.NaN; |
||
961 | SlopeType prevSlopeType = SlopeType.None; |
||
962 | ca7d0ada | gaqhf | for (int i = 0; i < linePointInfo.Count; i++) |
963 | { |
||
964 | 0bbd73b5 | gaqhf | Tuple<string, Line, object, double, double> item = linePointInfo[i]; |
965 | Line line = item.Item2; |
||
966 | double x = item.Item4; |
||
967 | double y = item.Item5; |
||
968 | SlopeType slopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
||
969 | // Symbol일 경우 바로 Input Point |
||
970 | ca7d0ada | gaqhf | if (item.Item1 == "SYMBOL") |
971 | 0bbd73b5 | gaqhf | { |
972 | placeRunInputs.AddSymbolTarget(item.Item3 as LMSymbol, x, y); |
||
973 | prevX = x; |
||
974 | prevY = y; |
||
975 | prevSlopeType = slopeType; |
||
976 | continue; |
||
977 | } |
||
978 | |||
979 | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
||
980 | // i == 0은 그대로 사용 |
||
981 | if (i != 0) |
||
982 | { |
||
983 | Tuple<string, Line, object, double, double> prevItem = linePointInfo[i - 1]; |
||
984 | // y 좌표가 같아야함 |
||
985 | if (prevSlopeType == SlopeType.HORIZONTAL) |
||
986 | y = prevY; |
||
987 | else if (prevSlopeType == SlopeType.VERTICAL) |
||
988 | x = prevX; |
||
989 | |||
990 | if (i + 1 == linePointInfo.Count - 1 && linePointInfo[i + 1].Item1 == "SYMBOL") |
||
991 | { |
||
992 | Line nextLine = linePointInfo[i + 1].Item2; |
||
993 | SlopeType nextSlopeType = SPPIDUtil.CalcSlope(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y); |
||
994 | if (prevSlopeType == SlopeType.HORIZONTAL) |
||
995 | y = linePointInfo[i + 1].Item5; |
||
996 | else if (prevSlopeType == SlopeType.VERTICAL) |
||
997 | x = linePointInfo[i + 1].Item4; |
||
998 | } |
||
999 | } |
||
1000 | |||
1001 | if (item.Item1 == "LINE") |
||
1002 | placeRunInputs.AddConnectorTarget(item.Item3 as LMConnector, x, y); |
||
1003 | ca7d0ada | gaqhf | else |
1004 | 0bbd73b5 | gaqhf | placeRunInputs.AddPoint(x, y); |
1005 | |||
1006 | prevX = x; |
||
1007 | prevY = y; |
||
1008 | prevSlopeType = slopeType; |
||
1009 | ca7d0ada | gaqhf | } |
1010 | |||
1011 | f1c9dbaa | gaqhf | LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1012 | 335b7a24 | gaqhf | |
1013 | f1c9dbaa | gaqhf | if (_lMConnector != null) |
1014 | { |
||
1015 | foreach (var line in lines) |
||
1016 | 5e6ecf05 | gaqhf | line.SPPID.ModelItemId = _lMConnector.ModelItemID; |
1017 | f1c9dbaa | gaqhf | _lMConnector.Commit(); |
1018 | 335b7a24 | gaqhf | if (startBranchLine != null || endBranchLine != null) |
1019 | { |
||
1020 | 3165c259 | gaqhf | BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine)); |
1021 | 335b7a24 | gaqhf | } |
1022 | 1b261371 | gaqhf | } |
1023 | 5e6ecf05 | gaqhf | |
1024 | 1b261371 | gaqhf | |
1025 | f1c9dbaa | gaqhf | if (_LMSymbol1 != null) |
1026 | ReleaseCOMObjects(_LMSymbol1); |
||
1027 | if (_LMSymbol2 != null) |
||
1028 | ReleaseCOMObjects(_LMSymbol2); |
||
1029 | 5e6ecf05 | gaqhf | if (targetConnector1 != null) |
1030 | ReleaseCOMObjects(targetConnector1); |
||
1031 | if (targetConnector2 != null) |
||
1032 | ReleaseCOMObjects(targetConnector2); |
||
1033 | foreach (var item in connectorVertices1) |
||
1034 | ReleaseCOMObjects(item.Key); |
||
1035 | foreach (var item in connectorVertices2) |
||
1036 | ReleaseCOMObjects(item.Key); |
||
1037 | 1b261371 | gaqhf | |
1038 | f1c9dbaa | gaqhf | ReleaseCOMObjects(_lMConnector); |
1039 | 1b261371 | gaqhf | ReleaseCOMObjects(placeRunInputs); |
1040 | ReleaseCOMObjects(_LMAItem); |
||
1041 | } |
||
1042 | |||
1043 | 74752074 | gaqhf | /// <summary> |
1044 | /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발 |
||
1045 | /// </summary> |
||
1046 | /// <param name="symbol"></param> |
||
1047 | /// <param name="line"></param> |
||
1048 | /// <returns></returns> |
||
1049 | f2baa6a3 | gaqhf | private LMSymbol GetTargetSymbol(Symbol symbol, Line line) |
1050 | { |
||
1051 | LMSymbol _LMSymbol = null; |
||
1052 | foreach (var connector in symbol.CONNECTORS) |
||
1053 | { |
||
1054 | if (connector.CONNECTEDITEM == line.UID) |
||
1055 | { |
||
1056 | if (connector.Index == 0) |
||
1057 | _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1058 | else |
||
1059 | { |
||
1060 | ChildSymbol child = null; |
||
1061 | foreach (var childSymbol in symbol.ChildSymbols) |
||
1062 | { |
||
1063 | if (childSymbol.Connectors.Contains(connector)) |
||
1064 | child = childSymbol; |
||
1065 | else |
||
1066 | child = GetChildSymbolByConnector(childSymbol, connector); |
||
1067 | |||
1068 | if (child != null) |
||
1069 | break; |
||
1070 | } |
||
1071 | |||
1072 | if (child != null) |
||
1073 | _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
||
1074 | } |
||
1075 | |||
1076 | break; |
||
1077 | } |
||
1078 | } |
||
1079 | |||
1080 | return _LMSymbol; |
||
1081 | } |
||
1082 | |||
1083 | 74752074 | gaqhf | /// <summary> |
1084 | /// Connector를 가지고 있는 ChildSymbol Object 반환 |
||
1085 | /// </summary> |
||
1086 | /// <param name="item"></param> |
||
1087 | /// <param name="connector"></param> |
||
1088 | /// <returns></returns> |
||
1089 | f2baa6a3 | gaqhf | private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
1090 | { |
||
1091 | foreach (var childSymbol in item.ChildSymbols) |
||
1092 | { |
||
1093 | if (childSymbol.Connectors.Contains(connector)) |
||
1094 | return childSymbol; |
||
1095 | else |
||
1096 | return GetChildSymbolByConnector(childSymbol, connector); |
||
1097 | } |
||
1098 | |||
1099 | return null; |
||
1100 | } |
||
1101 | |||
1102 | 74752074 | gaqhf | /// <summary> |
1103 | /// Branch 라인을 다시 모델링하는 진입 메서드 |
||
1104 | /// </summary> |
||
1105 | /// <param name="branch"></param> |
||
1106 | 335b7a24 | gaqhf | private void BranchLineModeling(Tuple<string, Line, Line> branch) |
1107 | { |
||
1108 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
||
1109 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
||
1110 | |||
1111 | 8b085570 | gaqhf | LMConnector _StartConnector = null; |
1112 | LMConnector _EndConnector = null; |
||
1113 | 335b7a24 | gaqhf | double lengthStart = double.MaxValue; |
1114 | double lengthEnd = double.MaxValue; |
||
1115 | List<double[]> startPoints = new List<double[]>(); |
||
1116 | List<double[]> endPoints = new List<double[]>(); |
||
1117 | |||
1118 | foreach (var item in connectorVertices) |
||
1119 | { |
||
1120 | foreach (var point in item.Value) |
||
1121 | { |
||
1122 | // Start Point가 Branch |
||
1123 | if (branch.Item2 != null) |
||
1124 | { |
||
1125 | Line targetLine = branch.Item2; |
||
1126 | double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
||
1127 | if (lengthStart > distance) |
||
1128 | { |
||
1129 | 8b085570 | gaqhf | _StartConnector = item.Key; |
1130 | 335b7a24 | gaqhf | lengthStart = distance; |
1131 | startPoints = item.Value; |
||
1132 | } |
||
1133 | } |
||
1134 | // End Point가 Branch |
||
1135 | if (branch.Item3 != null) |
||
1136 | { |
||
1137 | Line targetLine = branch.Item3; |
||
1138 | double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
||
1139 | if (lengthEnd > distance) |
||
1140 | { |
||
1141 | 8b085570 | gaqhf | _EndConnector = item.Key; |
1142 | 335b7a24 | gaqhf | lengthEnd = distance; |
1143 | endPoints = item.Value; |
||
1144 | } |
||
1145 | } |
||
1146 | } |
||
1147 | } |
||
1148 | #region Branch가 양쪽 전부일 때 |
||
1149 | 8b085570 | gaqhf | if (_StartConnector != null && _StartConnector == _EndConnector) |
1150 | 335b7a24 | gaqhf | { |
1151 | 8b085570 | gaqhf | _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
1152 | 335b7a24 | gaqhf | |
1153 | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
||
1154 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
1155 | |||
1156 | Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
||
1157 | 8b085570 | gaqhf | LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
1158 | 335b7a24 | gaqhf | Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
1159 | 8b085570 | gaqhf | LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices, |
1160 | 335b7a24 | gaqhf | startPoints[startPoints.Count - 1][0], |
1161 | startPoints[startPoints.Count - 1][1], |
||
1162 | startPoints[startPoints.Count - 2][0], |
||
1163 | startPoints[startPoints.Count - 2][1]); |
||
1164 | |||
1165 | for (int i = 0; i < startPoints.Count; i++) |
||
1166 | { |
||
1167 | double[] point = startPoints[i]; |
||
1168 | if (i == 0) |
||
1169 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
1170 | 335b7a24 | gaqhf | else if (i == startPoints.Count - 1) |
1171 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
1172 | 335b7a24 | gaqhf | else |
1173 | placeRunInputs.AddPoint(point[0], point[1]); |
||
1174 | } |
||
1175 | |||
1176 | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
1177 | if (_LMConnector != null) |
||
1178 | { |
||
1179 | _LMConnector.Commit(); |
||
1180 | foreach (var item in lines) |
||
1181 | item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
1182 | } |
||
1183 | |||
1184 | foreach (var item in startConnectorVertices) |
||
1185 | ReleaseCOMObjects(item.Key); |
||
1186 | foreach (var item in endConnectorVertices) |
||
1187 | ReleaseCOMObjects(item.Key); |
||
1188 | ReleaseCOMObjects(placeRunInputs); |
||
1189 | ReleaseCOMObjects(_LMAItem); |
||
1190 | ReleaseCOMObjects(_LMConnector); |
||
1191 | } |
||
1192 | #endregion |
||
1193 | 8b085570 | gaqhf | #region 양쪽이 다른 Branch |
1194 | 335b7a24 | gaqhf | else |
1195 | { |
||
1196 | // Branch 시작 Connector |
||
1197 | 8b085570 | gaqhf | if (_StartConnector != null) |
1198 | 6b298450 | gaqhf | BranchLineModelingByConnector(branch, _StartConnector, startPoints, true); |
1199 | 335b7a24 | gaqhf | |
1200 | 6b298450 | gaqhf | // Branch 끝 Connector |
1201 | if (_EndConnector != null) |
||
1202 | BranchLineModelingByConnector(branch, _EndConnector, endPoints, false); |
||
1203 | } |
||
1204 | #endregion |
||
1205 | 335b7a24 | gaqhf | |
1206 | 6b298450 | gaqhf | if (_StartConnector != null) |
1207 | ReleaseCOMObjects(_StartConnector); |
||
1208 | if (_EndConnector != null) |
||
1209 | ReleaseCOMObjects(_EndConnector); |
||
1210 | foreach (var item in connectorVertices) |
||
1211 | ReleaseCOMObjects(item.Key); |
||
1212 | } |
||
1213 | 335b7a24 | gaqhf | |
1214 | 74752074 | gaqhf | /// <summary> |
1215 | /// Branch 라인을 다시 실제로 모델링하는 메서드 |
||
1216 | /// </summary> |
||
1217 | /// <param name="branch"></param> |
||
1218 | /// <param name="_Connector"></param> |
||
1219 | /// <param name="points"></param> |
||
1220 | /// <param name="IsStart"></param> |
||
1221 | 6b298450 | gaqhf | private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart) |
1222 | { |
||
1223 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
||
1224 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
||
1225 | LMConnector _SameRunTargetConnector = null; |
||
1226 | LMSymbol _SameRunTargetSymbol = null; |
||
1227 | Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null; |
||
1228 | LMConnector _BranchTargetConnector = null; |
||
1229 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
1230 | 335b7a24 | gaqhf | |
1231 | 6b298450 | gaqhf | // 같은 Line Run의 Connector 찾기 |
1232 | foreach (var item in connectorVertices) |
||
1233 | { |
||
1234 | if (item.Key == _Connector) |
||
1235 | continue; |
||
1236 | 335b7a24 | gaqhf | |
1237 | 6b298450 | gaqhf | if (IsStart && |
1238 | !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) && |
||
1239 | !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& |
||
1240 | item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID) |
||
1241 | { |
||
1242 | _SameRunTargetConnector = item.Key; |
||
1243 | break; |
||
1244 | } |
||
1245 | else if (!IsStart && |
||
1246 | !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) && |
||
1247 | !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && |
||
1248 | item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID) |
||
1249 | { |
||
1250 | _SameRunTargetConnector = item.Key; |
||
1251 | break; |
||
1252 | } |
||
1253 | } |
||
1254 | |||
1255 | // Branch 반대편이 Symbol |
||
1256 | if (_SameRunTargetConnector == null) |
||
1257 | { |
||
1258 | foreach (var line in lines) |
||
1259 | { |
||
1260 | foreach (var connector in line.CONNECTORS) |
||
1261 | 335b7a24 | gaqhf | { |
1262 | 6b298450 | gaqhf | Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
1263 | if (symbol != null) |
||
1264 | 335b7a24 | gaqhf | { |
1265 | 6b298450 | gaqhf | _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1266 | break; |
||
1267 | 335b7a24 | gaqhf | } |
1268 | } |
||
1269 | 6b298450 | gaqhf | } |
1270 | } |
||
1271 | 335b7a24 | gaqhf | |
1272 | 6b298450 | gaqhf | // 기존 Connector 제거 |
1273 | _placement.PIDRemovePlacement(_Connector.AsLMRepresentation()); |
||
1274 | |||
1275 | // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함 |
||
1276 | if (IsStart) |
||
1277 | { |
||
1278 | branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
||
1279 | _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]); |
||
1280 | } |
||
1281 | // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함 |
||
1282 | else |
||
1283 | { |
||
1284 | branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
||
1285 | _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, |
||
1286 | points[points.Count - 1][0], |
||
1287 | points[points.Count - 1][1], |
||
1288 | points[points.Count - 2][0], |
||
1289 | points[points.Count - 2][1]); |
||
1290 | } |
||
1291 | 335b7a24 | gaqhf | |
1292 | 6b298450 | gaqhf | for (int i = 0; i < points.Count; i++) |
1293 | { |
||
1294 | double[] point = points[i]; |
||
1295 | if (i == 0) |
||
1296 | 335b7a24 | gaqhf | { |
1297 | 6b298450 | gaqhf | if (IsStart) |
1298 | 335b7a24 | gaqhf | { |
1299 | 6b298450 | gaqhf | placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
1300 | 335b7a24 | gaqhf | } |
1301 | 6b298450 | gaqhf | else |
1302 | 335b7a24 | gaqhf | { |
1303 | 6b298450 | gaqhf | if (_SameRunTargetConnector != null) |
1304 | placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
||
1305 | 65a1ed4b | gaqhf | else if (_SameRunTargetSymbol != null) |
1306 | 6b298450 | gaqhf | placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
1307 | else |
||
1308 | placeRunInputs.AddPoint(point[0], point[1]); |
||
1309 | 335b7a24 | gaqhf | } |
1310 | 6b298450 | gaqhf | } |
1311 | else if (i == points.Count - 1) |
||
1312 | { |
||
1313 | if (IsStart) |
||
1314 | 335b7a24 | gaqhf | { |
1315 | 6b298450 | gaqhf | if (_SameRunTargetConnector != null) |
1316 | placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
||
1317 | else if (_SameRunTargetSymbol != null) |
||
1318 | placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
||
1319 | 335b7a24 | gaqhf | else |
1320 | placeRunInputs.AddPoint(point[0], point[1]); |
||
1321 | } |
||
1322 | 6b298450 | gaqhf | else |
1323 | 335b7a24 | gaqhf | { |
1324 | f9125a54 | gaqhf | if (_BranchTargetConnector != null) |
1325 | { |
||
1326 | placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
||
1327 | } |
||
1328 | 335b7a24 | gaqhf | } |
1329 | 6b298450 | gaqhf | } |
1330 | else |
||
1331 | placeRunInputs.AddPoint(point[0], point[1]); |
||
1332 | } |
||
1333 | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
||
1334 | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
1335 | 335b7a24 | gaqhf | |
1336 | 6b298450 | gaqhf | if (_LMConnector != null) |
1337 | { |
||
1338 | if (_SameRunTargetConnector != null) |
||
1339 | { |
||
1340 | JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID); |
||
1341 | } |
||
1342 | else |
||
1343 | { |
||
1344 | foreach (var item in lines) |
||
1345 | item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
1346 | 335b7a24 | gaqhf | } |
1347 | |||
1348 | 6b298450 | gaqhf | _LMConnector.Commit(); |
1349 | ReleaseCOMObjects(_LMConnector); |
||
1350 | 335b7a24 | gaqhf | } |
1351 | |||
1352 | 6b298450 | gaqhf | ReleaseCOMObjects(placeRunInputs); |
1353 | ReleaseCOMObjects(_LMAItem); |
||
1354 | if (_BranchTargetConnector != null) |
||
1355 | ReleaseCOMObjects(_BranchTargetConnector); |
||
1356 | if (_SameRunTargetConnector != null) |
||
1357 | ReleaseCOMObjects(_SameRunTargetConnector); |
||
1358 | if (_SameRunTargetSymbol != null) |
||
1359 | ReleaseCOMObjects(_SameRunTargetSymbol); |
||
1360 | 335b7a24 | gaqhf | foreach (var item in connectorVertices) |
1361 | ReleaseCOMObjects(item.Key); |
||
1362 | 6b298450 | gaqhf | foreach (var item in branchConnectorVertices) |
1363 | ReleaseCOMObjects(item.Key); |
||
1364 | 335b7a24 | gaqhf | } |
1365 | |||
1366 | 74752074 | gaqhf | /// <summary> |
1367 | /// EndBreak 모델링 메서드 |
||
1368 | /// </summary> |
||
1369 | /// <param name="endBreak"></param> |
||
1370 | 3165c259 | gaqhf | private void EndBreakModeling(EndBreak endBreak) |
1371 | 335b7a24 | gaqhf | { |
1372 | 10c7195c | gaqhf | object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
1373 | 2a4872ec | gaqhf | LMConnector targetLMConnector = null; |
1374 | 10c7195c | gaqhf | if (ownerObj !=null && ownerObj.GetType() == typeof(Line)) |
1375 | 335b7a24 | gaqhf | { |
1376 | 10c7195c | gaqhf | Line ownerLine = ownerObj as Line; |
1377 | 3165c259 | gaqhf | LMLabelPersist _LmLabelPersist = null; |
1378 | ac78b508 | gaqhf | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId); |
1379 | 3165c259 | gaqhf | |
1380 | 2a4872ec | gaqhf | targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1381 | b9e9f4c8 | gaqhf | |
1382 | 2a4872ec | gaqhf | if (targetLMConnector != null) |
1383 | 335b7a24 | gaqhf | { |
1384 | ac78b508 | gaqhf | Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1385 | 2a4872ec | gaqhf | _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1386 | ac78b508 | gaqhf | } |
1387 | 3165c259 | gaqhf | |
1388 | ac78b508 | gaqhf | if (_LmLabelPersist != null) |
1389 | { |
||
1390 | _LmLabelPersist.Commit(); |
||
1391 | ReleaseCOMObjects(_LmLabelPersist); |
||
1392 | 335b7a24 | gaqhf | } |
1393 | b9e9f4c8 | gaqhf | else |
1394 | 2a4872ec | gaqhf | RetryEndBreakModeling(endBreak, targetLMConnector); |
1395 | b9e9f4c8 | gaqhf | |
1396 | ac78b508 | gaqhf | foreach (var item in connectorVertices) |
1397 | ReleaseCOMObjects(item.Key); |
||
1398 | 2a4872ec | gaqhf | |
1399 | 335b7a24 | gaqhf | } |
1400 | 10c7195c | gaqhf | else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol)) |
1401 | { |
||
1402 | Symbol ownerSymbol = ownerObj as Symbol; |
||
1403 | LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId); |
||
1404 | |||
1405 | 2a4872ec | gaqhf | targetLMConnector = null; |
1406 | 10c7195c | gaqhf | double distance = double.MaxValue; |
1407 | b9e9f4c8 | gaqhf | |
1408 | 10c7195c | gaqhf | foreach (LMConnector connector in _LMSymbol.Avoid1Connectors) |
1409 | { |
||
1410 | 26c6f818 | gaqhf | if (connector.get_ItemStatus() == "Active") |
1411 | 10c7195c | gaqhf | { |
1412 | 26c6f818 | gaqhf | dynamic OID = connector.get_GraphicOID(); |
1413 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
1414 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
1415 | int verticesCount = lineStringGeometry.VertexCount; |
||
1416 | double[] vertices = null; |
||
1417 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1418 | for (int i = 0; i < verticesCount; i++) |
||
1419 | 10c7195c | gaqhf | { |
1420 | 26c6f818 | gaqhf | double x = 0; |
1421 | double y = 0; |
||
1422 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
1423 | |||
1424 | b9e9f4c8 | gaqhf | double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1425 | 26c6f818 | gaqhf | if (result < distance) |
1426 | { |
||
1427 | targetLMConnector = connector; |
||
1428 | distance = result; |
||
1429 | } |
||
1430 | 10c7195c | gaqhf | } |
1431 | } |
||
1432 | } |
||
1433 | |||
1434 | foreach (LMConnector connector in _LMSymbol.Avoid2Connectors) |
||
1435 | { |
||
1436 | b9e9f4c8 | gaqhf | if (connector.get_ItemStatus() == "Active") |
1437 | 10c7195c | gaqhf | { |
1438 | b9e9f4c8 | gaqhf | dynamic OID = connector.get_GraphicOID(); |
1439 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
1440 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
1441 | int verticesCount = lineStringGeometry.VertexCount; |
||
1442 | double[] vertices = null; |
||
1443 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1444 | for (int i = 0; i < verticesCount; i++) |
||
1445 | 10c7195c | gaqhf | { |
1446 | b9e9f4c8 | gaqhf | double x = 0; |
1447 | double y = 0; |
||
1448 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
1449 | |||
1450 | double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
||
1451 | if (result < distance) |
||
1452 | { |
||
1453 | targetLMConnector = connector; |
||
1454 | distance = result; |
||
1455 | } |
||
1456 | 10c7195c | gaqhf | } |
1457 | } |
||
1458 | } |
||
1459 | |||
1460 | if (targetLMConnector != null) |
||
1461 | { |
||
1462 | LMLabelPersist _LmLabelPersist = null; |
||
1463 | Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
||
1464 | _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
||
1465 | if (_LmLabelPersist != null) |
||
1466 | { |
||
1467 | _LmLabelPersist.Commit(); |
||
1468 | ReleaseCOMObjects(_LmLabelPersist); |
||
1469 | } |
||
1470 | b9e9f4c8 | gaqhf | else |
1471 | 2a4872ec | gaqhf | RetryEndBreakModeling(endBreak, targetLMConnector); |
1472 | } |
||
1473 | |||
1474 | ReleaseCOMObjects(_LMSymbol); |
||
1475 | } |
||
1476 | f31645b6 | gaqhf | |
1477 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1478 | 2a4872ec | gaqhf | } |
1479 | b9e9f4c8 | gaqhf | |
1480 | 74752074 | gaqhf | /// <summary> |
1481 | /// EndBreak 모델링이 실패시 다시 시도하는 메서드 |
||
1482 | /// </summary> |
||
1483 | /// <param name="endBreak"></param> |
||
1484 | /// <param name="targetLMConnector"></param> |
||
1485 | 2a4872ec | gaqhf | private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector) |
1486 | { |
||
1487 | bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength()); |
||
1488 | Array array = null; |
||
1489 | LMLabelPersist _LMLabelPersist = null; |
||
1490 | LMConnector _LMConnector = null; |
||
1491 | dynamic OID = targetLMConnector.get_GraphicOID(); |
||
1492 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
1493 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
1494 | int verticesCount = lineStringGeometry.VertexCount; |
||
1495 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
1496 | _LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym"); |
||
1497 | b9e9f4c8 | gaqhf | |
1498 | 2a4872ec | gaqhf | if (isZeroLength) |
1499 | { |
||
1500 | double[] vertices = null; |
||
1501 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1502 | double x = 0; |
||
1503 | double y = 0; |
||
1504 | lineStringGeometry.GetVertex(1, ref x, ref y); |
||
1505 | b9e9f4c8 | gaqhf | |
1506 | 2a4872ec | gaqhf | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y); |
1507 | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y); |
||
1508 | b9e9f4c8 | gaqhf | |
1509 | 2a4872ec | gaqhf | _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1510 | _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
1511 | |||
1512 | array = new double[] { 0, x, y }; |
||
1513 | _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
||
1514 | 5a83fda2 | gaqhf | |
1515 | AutoJoinPipeRun(_LMConnector.ModelItemID); |
||
1516 | 2a4872ec | gaqhf | } |
1517 | else |
||
1518 | { |
||
1519 | List<double[]> vertices = new List<double[]>(); |
||
1520 | for (int i = 1; i <= verticesCount; i++) |
||
1521 | { |
||
1522 | double x = 0; |
||
1523 | double y = 0; |
||
1524 | lineStringGeometry.GetVertex(i, ref x, ref y); |
||
1525 | vertices.Add(new double[] { x, y }); |
||
1526 | } |
||
1527 | |||
1528 | for (int i = 0; i < vertices.Count; i++) |
||
1529 | { |
||
1530 | double[] points = vertices[i]; |
||
1531 | if (i == 0) |
||
1532 | { |
||
1533 | if (targetLMConnector.ConnectItem1SymbolObject != null) |
||
1534 | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]); |
||
1535 | else |
||
1536 | placeRunInputs.AddPoint(points[0], points[1]); |
||
1537 | b9e9f4c8 | gaqhf | } |
1538 | 2a4872ec | gaqhf | else if (i == vertices.Count - 1) |
1539 | { |
||
1540 | if (targetLMConnector.ConnectItem2SymbolObject != null) |
||
1541 | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]); |
||
1542 | else |
||
1543 | placeRunInputs.AddPoint(points[0], points[1]); |
||
1544 | } |
||
1545 | else |
||
1546 | placeRunInputs.AddPoint(points[0], points[1]); |
||
1547 | 10c7195c | gaqhf | } |
1548 | 2a4872ec | gaqhf | |
1549 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID); |
||
1550 | b9e9f4c8 | gaqhf | |
1551 | 2a4872ec | gaqhf | _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1552 | _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
1553 | |||
1554 | array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
||
1555 | _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
||
1556 | 3939eebf | gaqhf | |
1557 | AutoJoinPipeRun(_LMConnector.ModelItemID); |
||
1558 | foreach (var line in lines) |
||
1559 | line.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
1560 | 10c7195c | gaqhf | } |
1561 | 2a4872ec | gaqhf | |
1562 | |||
1563 | if (_LMLabelPersist != null) |
||
1564 | { |
||
1565 | _LMLabelPersist.Commit(); |
||
1566 | ReleaseCOMObjects(_LMLabelPersist); |
||
1567 | } |
||
1568 | else |
||
1569 | { |
||
1570 | |||
1571 | } |
||
1572 | |||
1573 | ReleaseCOMObjects(_LMConnector); |
||
1574 | ReleaseCOMObjects(placeRunInputs); |
||
1575 | ReleaseCOMObjects(_LMAItem); |
||
1576 | 3165c259 | gaqhf | } |
1577 | 10872260 | gaqhf | |
1578 | 74752074 | gaqhf | /// <summary> |
1579 | /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드 |
||
1580 | /// </summary> |
||
1581 | /// <param name="fromModelItemId"></param> |
||
1582 | /// <param name="toModelItemId"></param> |
||
1583 | 335b7a24 | gaqhf | private void JoinPipeRun(string fromModelItemId, string toModelItemId) |
1584 | { |
||
1585 | 310aeb31 | gaqhf | LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId); |
1586 | _LMAItem item1 = modelItem1.AsLMAItem(); |
||
1587 | LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId); |
||
1588 | _LMAItem item2 = modelItem2.AsLMAItem(); |
||
1589 | |||
1590 | 335b7a24 | gaqhf | // item2가 item1으로 조인 |
1591 | try |
||
1592 | { |
||
1593 | _placement.PIDJoinRuns(ref item1, ref item2); |
||
1594 | 65a1ed4b | gaqhf | item1.Commit(); |
1595 | item2.Commit(); |
||
1596 | 3939eebf | gaqhf | |
1597 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId); |
||
1598 | foreach (var line in lines) |
||
1599 | line.SPPID.ModelItemId = toModelItemId; |
||
1600 | 335b7a24 | gaqhf | } |
1601 | catch (Exception ex) |
||
1602 | { |
||
1603 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
1604 | } |
||
1605 | finally |
||
1606 | { |
||
1607 | 310aeb31 | gaqhf | ReleaseCOMObjects(modelItem1); |
1608 | ReleaseCOMObjects(item1); |
||
1609 | ReleaseCOMObjects(modelItem2); |
||
1610 | ReleaseCOMObjects(item2); |
||
1611 | 335b7a24 | gaqhf | } |
1612 | } |
||
1613 | |||
1614 | 74752074 | gaqhf | /// <summary> |
1615 | /// PipeRun을 자동으로 Join하는 메서드 |
||
1616 | /// </summary> |
||
1617 | /// <param name="modelItemId"></param> |
||
1618 | 335b7a24 | gaqhf | private void AutoJoinPipeRun(string modelItemId) |
1619 | { |
||
1620 | 310aeb31 | gaqhf | LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
1621 | _LMAItem item = modelItem.AsLMAItem(); |
||
1622 | 65a1ed4b | gaqhf | try |
1623 | { |
||
1624 | string modelitemID = item.Id; |
||
1625 | _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
||
1626 | string afterModelItemID = item.Id; |
||
1627 | 5a83fda2 | gaqhf | |
1628 | 65a1ed4b | gaqhf | if (modelitemID != afterModelItemID) |
1629 | { |
||
1630 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID); |
||
1631 | foreach (var line in lines) |
||
1632 | line.SPPID.ModelItemId = afterModelItemID; |
||
1633 | } |
||
1634 | item.Commit(); |
||
1635 | } |
||
1636 | catch (Exception ex) |
||
1637 | { |
||
1638 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
1639 | } |
||
1640 | finally |
||
1641 | { |
||
1642 | 310aeb31 | gaqhf | ReleaseCOMObjects(modelItem); |
1643 | ReleaseCOMObjects(item); |
||
1644 | 65a1ed4b | gaqhf | } |
1645 | 335b7a24 | gaqhf | } |
1646 | |||
1647 | 74752074 | gaqhf | /// <summary> |
1648 | /// LineRun에 있는 Line들을 Join하는 진입 메서드 |
||
1649 | /// </summary> |
||
1650 | /// <param name="run"></param> |
||
1651 | 335b7a24 | gaqhf | private void JoinRunLine(LineRun run) |
1652 | { |
||
1653 | string modelItemId = string.Empty; |
||
1654 | foreach (var item in run.RUNITEMS) |
||
1655 | { |
||
1656 | if (item.GetType() == typeof(Line)) |
||
1657 | { |
||
1658 | Line line = item as Line; |
||
1659 | 1ba9c671 | gaqhf | AutoJoinPipeRun(line.SPPID.ModelItemId); |
1660 | modelItemId = line.SPPID.ModelItemId; |
||
1661 | f31645b6 | gaqhf | |
1662 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1663 | 335b7a24 | gaqhf | } |
1664 | } |
||
1665 | } |
||
1666 | |||
1667 | 74752074 | gaqhf | /// <summary> |
1668 | /// PipeRun의 좌표를 가져오는 메서드 |
||
1669 | /// </summary> |
||
1670 | /// <param name="modelId"></param> |
||
1671 | /// <returns></returns> |
||
1672 | 5e6ecf05 | gaqhf | private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
1673 | { |
||
1674 | Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
||
1675 | 310aeb31 | gaqhf | LMModelItem modelItem = dataSource.GetModelItem(modelId); |
1676 | |||
1677 | if (modelItem != null) |
||
1678 | 5e6ecf05 | gaqhf | { |
1679 | 310aeb31 | gaqhf | foreach (LMRepresentation rep in modelItem.Representations) |
1680 | 5e6ecf05 | gaqhf | { |
1681 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
1682 | { |
||
1683 | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
||
1684 | connectorVertices.Add(_LMConnector, new List<double[]>()); |
||
1685 | dynamic OID = rep.get_GraphicOID(); |
||
1686 | 335b7a24 | gaqhf | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1687 | 5e6ecf05 | gaqhf | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1688 | int verticesCount = lineStringGeometry.VertexCount; |
||
1689 | double[] vertices = null; |
||
1690 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1691 | for (int i = 0; i < verticesCount; i++) |
||
1692 | { |
||
1693 | double x = 0; |
||
1694 | double y = 0; |
||
1695 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
1696 | 335b7a24 | gaqhf | connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) }); |
1697 | 5e6ecf05 | gaqhf | } |
1698 | } |
||
1699 | } |
||
1700 | |||
1701 | 310aeb31 | gaqhf | ReleaseCOMObjects(modelItem); |
1702 | 5e6ecf05 | gaqhf | } |
1703 | |||
1704 | return connectorVertices; |
||
1705 | } |
||
1706 | |||
1707 | 74752074 | gaqhf | /// <summary> |
1708 | /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함 |
||
1709 | /// </summary> |
||
1710 | /// <param name="connectorVertices"></param> |
||
1711 | /// <param name="connX"></param> |
||
1712 | /// <param name="connY"></param> |
||
1713 | /// <param name="x2"></param> |
||
1714 | /// <param name="y2"></param> |
||
1715 | /// <returns></returns> |
||
1716 | 56bc67e1 | gaqhf | private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2) |
1717 | 5e6ecf05 | gaqhf | { |
1718 | double length = double.MaxValue; |
||
1719 | LMConnector targetConnector = null; |
||
1720 | foreach (var item in connectorVertices) |
||
1721 | { |
||
1722 | List<double[]> points = item.Value; |
||
1723 | for (int i = 0; i < points.Count - 1; i++) |
||
1724 | { |
||
1725 | double[] point1 = points[i]; |
||
1726 | double[] point2 = points[i + 1]; |
||
1727 | |||
1728 | 335b7a24 | gaqhf | double maxLineX = Math.Max(point1[0], point2[0]); |
1729 | double minLineX = Math.Min(point1[0], point2[0]); |
||
1730 | double maxLineY = Math.Max(point1[1], point2[1]); |
||
1731 | double minLineY = Math.Min(point1[1], point2[1]); |
||
1732 | |||
1733 | SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
||
1734 | |||
1735 | 56bc67e1 | gaqhf | // 두직선의 교차점 |
1736 | double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
||
1737 | if (crossingPoint != null) |
||
1738 | 5e6ecf05 | gaqhf | { |
1739 | 30a9ffce | gaqhf | double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]); |
1740 | 335b7a24 | gaqhf | if (length >= distance) |
1741 | 30a9ffce | gaqhf | { |
1742 | 335b7a24 | gaqhf | if (slope == SlopeType.Slope && |
1743 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
||
1744 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
1745 | { |
||
1746 | targetConnector = item.Key; |
||
1747 | length = distance; |
||
1748 | } |
||
1749 | else if (slope == SlopeType.HORIZONTAL && |
||
1750 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
||
1751 | { |
||
1752 | targetConnector = item.Key; |
||
1753 | length = distance; |
||
1754 | } |
||
1755 | else if (slope == SlopeType.VERTICAL && |
||
1756 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
1757 | { |
||
1758 | targetConnector = item.Key; |
||
1759 | length = distance; |
||
1760 | } |
||
1761 | 30a9ffce | gaqhf | } |
1762 | 5e6ecf05 | gaqhf | } |
1763 | } |
||
1764 | c3d2e266 | gaqhf | |
1765 | |||
1766 | } |
||
1767 | |||
1768 | if (targetConnector == null) |
||
1769 | { |
||
1770 | foreach (var item in connectorVertices) |
||
1771 | { |
||
1772 | List<double[]> points = item.Value; |
||
1773 | foreach (var point in points) |
||
1774 | { |
||
1775 | double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]); |
||
1776 | if (length >= distance) |
||
1777 | { |
||
1778 | targetConnector = item.Key; |
||
1779 | length = distance; |
||
1780 | } |
||
1781 | } |
||
1782 | } |
||
1783 | |||
1784 | 5e6ecf05 | gaqhf | } |
1785 | |||
1786 | return targetConnector; |
||
1787 | } |
||
1788 | |||
1789 | 74752074 | gaqhf | /// <summary> |
1790 | /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순) |
||
1791 | /// </summary> |
||
1792 | /// <param name="connectorVertices"></param> |
||
1793 | /// <param name="connX"></param> |
||
1794 | /// <param name="connY"></param> |
||
1795 | /// <returns></returns> |
||
1796 | ac78b508 | gaqhf | private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
1797 | { |
||
1798 | double length = double.MaxValue; |
||
1799 | LMConnector targetConnector = null; |
||
1800 | foreach (var item in connectorVertices) |
||
1801 | { |
||
1802 | List<double[]> points = item.Value; |
||
1803 | |||
1804 | foreach (double[] point in points) |
||
1805 | { |
||
1806 | double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
||
1807 | if (length >= distance) |
||
1808 | { |
||
1809 | targetConnector = item.Key; |
||
1810 | length = distance; |
||
1811 | } |
||
1812 | } |
||
1813 | } |
||
1814 | |||
1815 | return targetConnector; |
||
1816 | } |
||
1817 | |||
1818 | 74752074 | gaqhf | /// <summary> |
1819 | /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식 |
||
1820 | /// </summary> |
||
1821 | /// <param name="connectorVertices"></param> |
||
1822 | /// <param name="connX"></param> |
||
1823 | /// <param name="connY"></param> |
||
1824 | /// <returns></returns> |
||
1825 | 68464385 | gaqhf | private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
1826 | { |
||
1827 | double length = double.MaxValue; |
||
1828 | LMConnector targetConnector = null; |
||
1829 | foreach (var item in connectorVertices) |
||
1830 | { |
||
1831 | List<double[]> points = item.Value; |
||
1832 | for (int i = 0; i < points.Count - 1; i++) |
||
1833 | { |
||
1834 | double[] point1 = points[i]; |
||
1835 | double[] point2 = points[i + 1]; |
||
1836 | double x1 = Math.Min(point1[0], point2[0]); |
||
1837 | double y1 = Math.Min(point1[1], point2[1]); |
||
1838 | double x2 = Math.Max(point1[0], point2[0]); |
||
1839 | double y2 = Math.Max(point1[1], point2[1]); |
||
1840 | |||
1841 | if ((x1 <= connX && x2 >= connX) || |
||
1842 | (y1 <= connY && y2 >= connY)) |
||
1843 | { |
||
1844 | double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
||
1845 | if (length >= distance) |
||
1846 | { |
||
1847 | targetConnector = item.Key; |
||
1848 | length = distance; |
||
1849 | } |
||
1850 | |||
1851 | distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
||
1852 | if (length >= distance) |
||
1853 | { |
||
1854 | targetConnector = item.Key; |
||
1855 | length = distance; |
||
1856 | } |
||
1857 | } |
||
1858 | } |
||
1859 | } |
||
1860 | |||
1861 | // 못찾았을때. |
||
1862 | length = double.MaxValue; |
||
1863 | if (targetConnector == null) |
||
1864 | { |
||
1865 | foreach (var item in connectorVertices) |
||
1866 | { |
||
1867 | List<double[]> points = item.Value; |
||
1868 | |||
1869 | foreach (double[] point in points) |
||
1870 | { |
||
1871 | double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
||
1872 | if (length >= distance) |
||
1873 | { |
||
1874 | targetConnector = item.Key; |
||
1875 | length = distance; |
||
1876 | } |
||
1877 | } |
||
1878 | } |
||
1879 | } |
||
1880 | |||
1881 | return targetConnector; |
||
1882 | } |
||
1883 | |||
1884 | 74752074 | gaqhf | /// <summary> |
1885 | /// Line Number Symbol을 실제로 Modeling하는 메서드 |
||
1886 | /// </summary> |
||
1887 | /// <param name="lineNumber"></param> |
||
1888 | cfda1fed | gaqhf | private void LineNumberModeling(LineNumber lineNumber) |
1889 | { |
||
1890 | f4880c6a | gaqhf | Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
1891 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
||
1892 | 68464385 | gaqhf | LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y); |
1893 | f4880c6a | gaqhf | if (connectedLMConnector != null) |
1894 | 10872260 | gaqhf | { |
1895 | b65a7e32 | gaqhf | double x = 0; |
1896 | double y = 0; |
||
1897 | CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation); |
||
1898 | |||
1899 | Array points = new double[] { 0, x, y }; |
||
1900 | f4880c6a | gaqhf | LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false); |
1901 | cfda1fed | gaqhf | |
1902 | f4880c6a | gaqhf | foreach (var item in connectorVertices) |
1903 | ReleaseCOMObjects(item.Key); |
||
1904 | if (_LmLabelPresist != null) |
||
1905 | { |
||
1906 | c3d2e266 | gaqhf | _LmLabelPresist.Commit(); |
1907 | f4880c6a | gaqhf | lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
1908 | ReleaseCOMObjects(_LmLabelPresist); |
||
1909 | 10872260 | gaqhf | } |
1910 | c3d2e266 | gaqhf | else |
1911 | { |
||
1912 | |||
1913 | } |
||
1914 | 10872260 | gaqhf | } |
1915 | f31645b6 | gaqhf | |
1916 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1917 | cfda1fed | gaqhf | } |
1918 | |||
1919 | 74752074 | gaqhf | /// <summary> |
1920 | /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input |
||
1921 | /// </summary> |
||
1922 | /// <param name="lineNumber"></param> |
||
1923 | a7e9beec | gaqhf | private void InputLineNumberAttribute(LineNumber lineNumber) |
1924 | { |
||
1925 | 8634af60 | gaqhf | foreach (LineRun run in lineNumber.RUNS) |
1926 | a7e9beec | gaqhf | { |
1927 | 8634af60 | gaqhf | foreach (var item in run.RUNITEMS) |
1928 | a7e9beec | gaqhf | { |
1929 | 8634af60 | gaqhf | if (item.GetType() == typeof(Symbol)) |
1930 | a7e9beec | gaqhf | { |
1931 | 8634af60 | gaqhf | Symbol symbol = item as Symbol; |
1932 | LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1933 | LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
||
1934 | |||
1935 | if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
||
1936 | { |
||
1937 | foreach (var attribute in lineNumber.ATTRIBUTES) |
||
1938 | { |
||
1939 | LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
||
1940 | if (mapping != null) |
||
1941 | { |
||
1942 | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
1943 | if (_LMAAttribute != null) |
||
1944 | { |
||
1945 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
1946 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1947 | else if (_LMAAttribute.get_Value() != attribute.VALUE) |
||
1948 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1949 | } |
||
1950 | } |
||
1951 | } |
||
1952 | _LMModelItem.Commit(); |
||
1953 | } |
||
1954 | if (_LMModelItem != null) |
||
1955 | ReleaseCOMObjects(_LMModelItem); |
||
1956 | if (_LMSymbol != null) |
||
1957 | ReleaseCOMObjects(_LMSymbol); |
||
1958 | } |
||
1959 | else if (item.GetType() == typeof(Line)) |
||
1960 | { |
||
1961 | Line line = item as Line; |
||
1962 | if (line != null) |
||
1963 | a7e9beec | gaqhf | { |
1964 | 8634af60 | gaqhf | LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
1965 | if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
||
1966 | a7e9beec | gaqhf | { |
1967 | 8634af60 | gaqhf | foreach (var attribute in lineNumber.ATTRIBUTES) |
1968 | { |
||
1969 | LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
||
1970 | if (mapping != null) |
||
1971 | { |
||
1972 | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
1973 | if (_LMAAttribute != null) |
||
1974 | { |
||
1975 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
1976 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1977 | else if (_LMAAttribute.get_Value() != attribute.VALUE) |
||
1978 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1979 | |||
1980 | } |
||
1981 | } |
||
1982 | } |
||
1983 | 68464385 | gaqhf | _LMModelItem.Commit(); |
1984 | a7e9beec | gaqhf | } |
1985 | 8634af60 | gaqhf | if (_LMModelItem != null) |
1986 | ReleaseCOMObjects(_LMModelItem); |
||
1987 | a7e9beec | gaqhf | } |
1988 | } |
||
1989 | } |
||
1990 | } |
||
1991 | f31645b6 | gaqhf | |
1992 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1993 | a7e9beec | gaqhf | } |
1994 | |||
1995 | 74752074 | gaqhf | /// <summary> |
1996 | /// Symbol Attribute 입력 메서드 |
||
1997 | /// </summary> |
||
1998 | 73415441 | gaqhf | /// <param name="item"></param> |
1999 | private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes) |
||
2000 | 1efc25a3 | gaqhf | { |
2001 | ac78b508 | gaqhf | try |
2002 | 1efc25a3 | gaqhf | { |
2003 | 73415441 | gaqhf | // Object 아이템이 Symbol일 경우 Equipment일 경우 |
2004 | string sRep = null; |
||
2005 | if (targetItem.GetType() == typeof(Symbol)) |
||
2006 | sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
||
2007 | else if (targetItem.GetType() == typeof(Equipment)) |
||
2008 | sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
||
2009 | |||
2010 | if (!string.IsNullOrEmpty(sRep)) |
||
2011 | 402ef5b1 | gaqhf | { |
2012 | 73415441 | gaqhf | LMSymbol _LMSymbol = dataSource.GetSymbol(sRep); |
2013 | 310aeb31 | gaqhf | LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
2014 | ea80efaa | gaqhf | LMAAttributes _Attributes = _LMModelItem.Attributes; |
2015 | 402ef5b1 | gaqhf | |
2016 | 73415441 | gaqhf | foreach (var item in targetAttributes) |
2017 | 65a1ed4b | gaqhf | { |
2018 | ac78b508 | gaqhf | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
2019 | 26c6f818 | gaqhf | if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
2020 | ac78b508 | gaqhf | { |
2021 | LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
2022 | if (_Attribute != null) |
||
2023 | 73415441 | gaqhf | _Attribute.set_Value(item.VALUE); |
2024 | ac78b508 | gaqhf | } |
2025 | 65a1ed4b | gaqhf | } |
2026 | 73415441 | gaqhf | _LMModelItem.Commit(); |
2027 | |||
2028 | ea80efaa | gaqhf | ReleaseCOMObjects(_Attributes); |
2029 | ReleaseCOMObjects(_LMModelItem); |
||
2030 | 73415441 | gaqhf | ReleaseCOMObjects(_LMSymbol); |
2031 | ac78b508 | gaqhf | } |
2032 | } |
||
2033 | catch (Exception ex) |
||
2034 | { |
||
2035 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
2036 | 1efc25a3 | gaqhf | } |
2037 | f31645b6 | gaqhf | |
2038 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
2039 | 1efc25a3 | gaqhf | } |
2040 | |||
2041 | 74752074 | gaqhf | /// <summary> |
2042 | /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링 |
||
2043 | /// </summary> |
||
2044 | /// <param name="text"></param> |
||
2045 | cfda1fed | gaqhf | private void TextModeling(Text text) |
2046 | { |
||
2047 | 6b298450 | gaqhf | LMSymbol _LMSymbol = null; |
2048 | try |
||
2049 | { |
||
2050 | 8b069d9f | gaqhf | //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None") |
2051 | if (text.ASSOCIATION) |
||
2052 | ea80efaa | gaqhf | { |
2053 | object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
||
2054 | if (owner.GetType() == typeof(Symbol)) |
||
2055 | { |
||
2056 | Symbol symbol = owner as Symbol; |
||
2057 | _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
2058 | if (_LMSymbol != null) |
||
2059 | { |
||
2060 | Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID); |
||
2061 | List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE); |
||
2062 | AttributeMapping mapping = null; |
||
2063 | foreach (var attribute in attributes) |
||
2064 | { |
||
2065 | 26c6f818 | gaqhf | if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None") |
2066 | continue; |
||
2067 | |||
2068 | ea80efaa | gaqhf | mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
2069 | if (mapping != null) |
||
2070 | break; |
||
2071 | } |
||
2072 | |||
2073 | if (mapping != null) |
||
2074 | { |
||
2075 | 1a3a74a8 | gaqhf | double x = 0; |
2076 | double y = 0; |
||
2077 | |||
2078 | b65a7e32 | gaqhf | CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
2079 | Array array = new double[] { 0, x, y }; |
||
2080 | 1a3a74a8 | gaqhf | |
2081 | 1ba9c671 | gaqhf | LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
2082 | ea80efaa | gaqhf | if (_LMLabelPersist!=null) |
2083 | { |
||
2084 | f9125a54 | gaqhf | _LMLabelPersist.Commit(); |
2085 | ea80efaa | gaqhf | ReleaseCOMObjects(_LMLabelPersist); |
2086 | } |
||
2087 | } |
||
2088 | } |
||
2089 | } |
||
2090 | else if (owner.GetType() == typeof(Line)) |
||
2091 | { |
||
2092 | |||
2093 | } |
||
2094 | } |
||
2095 | else |
||
2096 | { |
||
2097 | LMItemNote _LMItemNote = null; |
||
2098 | LMAAttribute _LMAAttribute = null; |
||
2099 | |||
2100 | b65a7e32 | gaqhf | double x = 0; |
2101 | double y = 0; |
||
2102 | |||
2103 | CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation); |
||
2104 | |||
2105 | _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y); |
||
2106 | ea80efaa | gaqhf | _LMSymbol.Commit(); |
2107 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
2108 | _LMItemNote.Commit(); |
||
2109 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
2110 | _LMAAttribute.set_Value(text.VALUE); |
||
2111 | _LMItemNote.Commit(); |
||
2112 | |||
2113 | if (_LMAAttribute != null) |
||
2114 | ReleaseCOMObjects(_LMAAttribute); |
||
2115 | if (_LMItemNote != null) |
||
2116 | ReleaseCOMObjects(_LMItemNote); |
||
2117 | } |
||
2118 | 6b298450 | gaqhf | } |
2119 | catch (Exception ex) |
||
2120 | { |
||
2121 | cfda1fed | gaqhf | |
2122 | 6b298450 | gaqhf | } |
2123 | finally |
||
2124 | { |
||
2125 | if (_LMSymbol != null) |
||
2126 | ReleaseCOMObjects(_LMSymbol); |
||
2127 | } |
||
2128 | f31645b6 | gaqhf | |
2129 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
2130 | cfda1fed | gaqhf | } |
2131 | |||
2132 | 74752074 | gaqhf | /// <summary> |
2133 | /// Note Modeling |
||
2134 | /// </summary> |
||
2135 | /// <param name="note"></param> |
||
2136 | cfda1fed | gaqhf | private void NoteModeling(Note note) |
2137 | { |
||
2138 | 6b298450 | gaqhf | LMSymbol _LMSymbol = null; |
2139 | LMItemNote _LMItemNote = null; |
||
2140 | LMAAttribute _LMAAttribute = null; |
||
2141 | |||
2142 | try |
||
2143 | { |
||
2144 | b65a7e32 | gaqhf | double x = 0; |
2145 | double y = 0; |
||
2146 | |||
2147 | CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation); |
||
2148 | |||
2149 | _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y); |
||
2150 | 6b298450 | gaqhf | _LMSymbol.Commit(); |
2151 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
2152 | _LMItemNote.Commit(); |
||
2153 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
2154 | _LMAAttribute.set_Value(note.VALUE); |
||
2155 | _LMItemNote.Commit(); |
||
2156 | } |
||
2157 | catch (Exception ex) |
||
2158 | { |
||
2159 | cfda1fed | gaqhf | |
2160 | 6b298450 | gaqhf | } |
2161 | finally |
||
2162 | { |
||
2163 | if (_LMAAttribute != null) |
||
2164 | ReleaseCOMObjects(_LMAAttribute); |
||
2165 | if (_LMItemNote != null) |
||
2166 | ReleaseCOMObjects(_LMItemNote); |
||
2167 | if (_LMSymbol != null) |
||
2168 | ReleaseCOMObjects(_LMSymbol); |
||
2169 | } |
||
2170 | f31645b6 | gaqhf | |
2171 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
2172 | cfda1fed | gaqhf | } |
2173 | |||
2174 | 74752074 | gaqhf | /// <summary> |
2175 | /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표) |
||
2176 | /// </summary> |
||
2177 | /// <param name="x"></param> |
||
2178 | /// <param name="y"></param> |
||
2179 | /// <param name="originX"></param> |
||
2180 | /// <param name="originY"></param> |
||
2181 | /// <param name="SPPIDLabelLocation"></param> |
||
2182 | /// <param name="location"></param> |
||
2183 | b65a7e32 | gaqhf | private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location) |
2184 | { |
||
2185 | if (location == Location.None) |
||
2186 | { |
||
2187 | x = originX; |
||
2188 | y = originY; |
||
2189 | } |
||
2190 | else |
||
2191 | { |
||
2192 | if (location.HasFlag(Location.Center)) |
||
2193 | { |
||
2194 | x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2; |
||
2195 | y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2; |
||
2196 | } |
||
2197 | |||
2198 | if (location.HasFlag(Location.Left)) |
||
2199 | x = SPPIDLabelLocation.X1; |
||
2200 | else if (location.HasFlag(Location.Right)) |
||
2201 | x = SPPIDLabelLocation.X2; |
||
2202 | |||
2203 | if (location.HasFlag(Location.Down)) |
||
2204 | y = SPPIDLabelLocation.Y1; |
||
2205 | else if (location.HasFlag(Location.Up)) |
||
2206 | y = SPPIDLabelLocation.Y2; |
||
2207 | } |
||
2208 | } |
||
2209 | 5a4b8f32 | gaqhf | |
2210 | 74752074 | gaqhf | /// <summary> |
2211 | /// ComObject를 Release |
||
2212 | /// </summary> |
||
2213 | /// <param name="objVars"></param> |
||
2214 | 5a4b8f32 | gaqhf | public void ReleaseCOMObjects(params object[] objVars) |
2215 | { |
||
2216 | int intNewRefCount = 0; |
||
2217 | foreach (object obj in objVars) |
||
2218 | { |
||
2219 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
2220 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
2221 | } |
||
2222 | } |
||
2223 | cfda1fed | gaqhf | } |
2224 | } |