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