hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ eaa41534
이력 | 보기 | 이력해설 | 다운로드 (298 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 | 4d2571ab | gaqhf | using System.Data; |
7 | cfda1fed | gaqhf | using Llama; |
8 | using Plaice; |
||
9 | 8aa6f2db | gaqhf | using Ingr.RAD2D.Interop.RAD2D; |
10 | using Ingr.RAD2D.Internal; |
||
11 | using Ingr.RAD2D.Helper; |
||
12 | cfda1fed | gaqhf | using Converter.BaseModel; |
13 | using Converter.SPPID.Model; |
||
14 | using Converter.SPPID.Properties; |
||
15 | using Converter.SPPID.Util; |
||
16 | using Converter.SPPID.DB; |
||
17 | 5e6ecf05 | gaqhf | using Ingr.RAD2D.MacroControls.CmdCtrl; |
18 | using Ingr.RAD2D; |
||
19 | 5dfb8a24 | gaqhf | using System.Windows; |
20 | cfda1fed | gaqhf | using System.Threading; |
21 | 5dfb8a24 | gaqhf | using System.Drawing; |
22 | cfda1fed | gaqhf | using Microsoft.VisualBasic; |
23 | using Newtonsoft.Json; |
||
24 | ca214bc3 | gaqhf | using DevExpress.XtraSplashScreen; |
25 | cfda1fed | gaqhf | namespace Converter.SPPID |
26 | { |
||
27 | 69222bff | gaqhf | [Flags] |
28 | public enum SegmentLocation |
||
29 | { |
||
30 | None = 0, |
||
31 | Right = 1, |
||
32 | Left = 2, |
||
33 | Down = 4, |
||
34 | Up = 8 |
||
35 | } |
||
36 | 5a9396ae | humkyung | public class AutoModeling : IDisposable |
37 | cfda1fed | gaqhf | { |
38 | 809a7640 | gaqhf | Placement _placement; |
39 | LMADataSource dataSource; |
||
40 | 4941f5fe | gaqhf | string drawingID; |
41 | 1ba9c671 | gaqhf | dynamic newDrawing; |
42 | d19ae675 | gaqhf | dynamic application; |
43 | 442bd51e | gaqhf | bool closeDocument; |
44 | 5e6ecf05 | gaqhf | Ingr.RAD2D.Application radApp; |
45 | cfda1fed | gaqhf | SPPID_Document document; |
46 | b65a7e32 | gaqhf | ETCSetting _ETCSetting; |
47 | 52599bc7 | gaqhf | DataTable nominalDiameterTable = null; |
48 | d5ec4d0f | gaqhf | public string DocumentLabelText { get; set; } |
49 | |||
50 | f3e2693f | gaqhf | List<Line> BranchLines = new List<Line>(); |
51 | 644f40b3 | gaqhf | List<string> ZeroLengthSymbolToSymbolModelItemID = new List<string>(); |
52 | 87f02fc0 | gaqhf | List<string> ZeroLengthModelItemID = new List<string>(); |
53 | 1ff0105e | gaqhf | List<string> ZeroLengthModelItemIDReverse = new List<string>(); |
54 | f1a7faf9 | gaqhf | List<Symbol> prioritySymbols; |
55 | c5b2c7ff | gaqhf | List<string> FlowMarkRepIds = new List<string>(); |
56 | 47ad9a46 | gaqhf | |
57 | 4941f5fe | gaqhf | public AutoModeling(SPPID_Document document, bool closeDocument) |
58 | cfda1fed | gaqhf | { |
59 | 4941f5fe | gaqhf | application = Interaction.GetObject("", "PIDAutomation.Application"); |
60 | WrapperApplication wApp = new WrapperApplication(application.Application); |
||
61 | radApp = wApp.RADApplication; |
||
62 | |||
63 | 442bd51e | gaqhf | this.closeDocument = closeDocument; |
64 | cfda1fed | gaqhf | this.document = document; |
65 | b65a7e32 | gaqhf | this._ETCSetting = ETCSetting.GetInstance(); |
66 | cfda1fed | gaqhf | } |
67 | |||
68 | 02480ac1 | gaqhf | private void SetSystemEditingCommand(bool value) |
69 | { |
||
70 | foreach (var item in radApp.Commands) |
||
71 | { |
||
72 | if (item.Argument == "SystemEditingCmd.SystemEditing") |
||
73 | { |
||
74 | if (item.Checked != value) |
||
75 | { |
||
76 | radApp.RunMacro("systemeditingcmd.dll"); |
||
77 | break; |
||
78 | } |
||
79 | |||
80 | } |
||
81 | } |
||
82 | } |
||
83 | |||
84 | 74752074 | gaqhf | /// <summary> |
85 | /// 도면 단위당 실행되는 메서드 |
||
86 | /// </summary> |
||
87 | 1ba9c671 | gaqhf | public void Run() |
88 | c2fef4ca | gaqhf | { |
89 | 2e69e97c | gaqhf | string drawingNumber = document.DrawingNumber; |
90 | string drawingName = document.DrawingName; |
||
91 | 1ba9c671 | gaqhf | try |
92 | c2fef4ca | gaqhf | { |
93 | 52599bc7 | gaqhf | nominalDiameterTable = Project_DB.SelectProjectNominalDiameter(); |
94 | bccacd6c | gaqhf | _placement = new Placement(); |
95 | dataSource = _placement.PIDDataSource; |
||
96 | 7881ec8f | gaqhf | |
97 | 2e69e97c | gaqhf | if (CreateDocument(ref drawingNumber, ref drawingName) && DocumentCoordinateCorrection()) |
98 | 310aeb31 | gaqhf | { |
99 | 3734dcc5 | gaqhf | Log.Write("Start Modeling"); |
100 | 965eb728 | gaqhf | SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
101 | 9628f54b | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd); |
102 | 86c0a45e | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 25); |
103 | 20972c61 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText); |
104 | f9cc5190 | gaqhf | |
105 | fb2d9638 | gaqhf | // VendorPackage Modeling |
106 | 7881ec8f | gaqhf | // ID2에서 VendorPackage로 된 Symbol을 SPPID에서 그림 |
107 | fb2d9638 | gaqhf | RunVendorPackageModeling(); |
108 | 6db30942 | gaqhf | // Equipment Modeling |
109 | 7881ec8f | gaqhf | // Id2에서 인식한 Equipment일 경우 SPPID에 Draft |
110 | b01e7456 | gaqhf | RunEquipmentModeling(); |
111 | // Symbol Modeling |
||
112 | 7881ec8f | gaqhf | // ID2의 Symbol Draft |
113 | // 단 Symbol draft할 때 붙어 있는 symbol도 draft함 |
||
114 | b01e7456 | gaqhf | RunSymbolModeling(); |
115 | 3939eebf | gaqhf | // LineRun Line Modeling |
116 | 7881ec8f | gaqhf | // Line 그리는 우선 순위 |
117 | // 1. Branch 없는 것 |
||
118 | // 2. Symbol 연결 개수 |
||
119 | // 3. Symbol 제외 Item 연결 개수 |
||
120 | // 4. ConnectedItem이 없는것 |
||
121 | b01e7456 | gaqhf | RunLineModeling(); |
122 | f14b4e3b | gaqhf | // Vent Drain Modeling |
123 | 7881ec8f | gaqhf | // Vent/Drain으로 인식한 Item draft |
124 | // 인식 조건 |
||
125 | // 1. ID2에서 Line이 하나며 Branch된 Line이 있고 |
||
126 | // 2. Valve가 line에 붙어있다. |
||
127 | f14b4e3b | gaqhf | RunVentDrainModeling(); |
128 | e2876f87 | gaqhf | // Clear Attribute |
129 | 7881ec8f | gaqhf | // SPPID에서 Line 생성 시 자동으로 Nominal Diameter가 입력되는 경우가 있음 |
130 | // 모든 Item의 Nominal Diameter 속성값 초기화 |
||
131 | e2876f87 | gaqhf | RunClearNominalDiameter(); |
132 | d23fe61b | gaqhf | // Join SameConnector |
133 | 7881ec8f | gaqhf | // 기존 Line을 그릴때 SPPID에서는 같은 Run으로 생성되지 않고 각각 PipeRun이 생성됨 |
134 | // ID2의 EndBreak등 segmentbreak가 없으면 Line을 합침 |
||
135 | dfac4553 | gaqhf | RunJoinRunForSameConnector(); |
136 | d77973b3 | gaqhf | // Join Run |
137 | 7881ec8f | gaqhf | // 같은 Type의 Line일 경우 Join함 |
138 | d77973b3 | gaqhf | RunJoinRun(); |
139 | 7881ec8f | gaqhf | |
140 | fae4f386 | gaqhf | // EndBreak Modeling |
141 | RunEndBreakModeling(); |
||
142 | // SpecBreak Modeling |
||
143 | RunSpecBreakModeling(); |
||
144 | 8701de36 | gaqhf | //Line Number Modeling |
145 | 7881ec8f | gaqhf | // Label만 draft |
146 | 8701de36 | gaqhf | RunLineNumberModeling(); |
147 | 32205389 | gaqhf | // Note Modeling |
148 | RunNoteModeling(); |
||
149 | // Text Modeling |
||
150 | RunTextModeling(); |
||
151 | // Input LineNumber Attribute |
||
152 | RunInputLineNumberAttribute(); |
||
153 | // Input Symbol Attribute |
||
154 | RunInputSymbolAttribute(); |
||
155 | // Input SpecBreak Attribute |
||
156 | RunInputSpecBreakAttribute(); |
||
157 | d8afa58b | gaqhf | // Input EndBreak Attribute |
158 | RunInputEndBreakAttribute(); |
||
159 | 32205389 | gaqhf | // Label Symbol Modeling |
160 | RunLabelSymbolModeling(); |
||
161 | 7881ec8f | gaqhf | |
162 | 4e865771 | gaqhf | // Correct Text |
163 | 7881ec8f | gaqhf | // LabelPersist 정렬 로직 |
164 | // 예) Valve Size label 등 |
||
165 | 4e865771 | gaqhf | RunCorrectAssociationText(); |
166 | c5b2c7ff | gaqhf | // ETC |
167 | 7881ec8f | gaqhf | // Label을 Front로 옮김 |
168 | c5b2c7ff | gaqhf | RunETC(); |
169 | 7881ec8f | gaqhf | // input bulk attribute |
170 | 86c0a45e | gaqhf | RunBulkAttribute(); |
171 | 7881ec8f | gaqhf | // log file 생성 |
172 | 30ba9ae0 | gaqhf | document.CheckModelingResult(); |
173 | 310aeb31 | gaqhf | } |
174 | 809a7640 | gaqhf | } |
175 | 5e6ecf05 | gaqhf | catch (Exception ex) |
176 | { |
||
177 | 4941f5fe | gaqhf | if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible) |
178 | { |
||
179 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
||
180 | SplashScreenManager.CloseForm(false); |
||
181 | Log.Write("\r\n"); |
||
182 | } |
||
183 | 5e6ecf05 | gaqhf | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
184 | } |
||
185 | finally |
||
186 | { |
||
187 | 2e69e97c | gaqhf | Project_DB.InsertDrawingInfoAndOPCInfo(document.PATH, drawingNumber, drawingName, document); |
188 | 82ab5276 | gaqhf | //Project_DB.InsertLineNumberInfo(document.PATH, drawingNumber, drawingName, document); |
189 | da1aeb27 | gaqhf | |
190 | 4941f5fe | gaqhf | if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible) |
191 | { |
||
192 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
||
193 | SplashScreenManager.CloseForm(false); |
||
194 | Log.Write("\r\n"); |
||
195 | } |
||
196 | Thread.Sleep(1000); |
||
197 | b2d1c1aa | gaqhf | |
198 | 4941f5fe | gaqhf | Log.Write("End Modeling"); |
199 | radApp.ActiveWindow.Fit(); |
||
200 | 7aee331b | gaqhf | |
201 | 4941f5fe | gaqhf | ReleaseCOMObjects(application); |
202 | application = null; |
||
203 | b66a2996 | gaqhf | if (radApp.ActiveDocument != null) |
204 | 3939eebf | gaqhf | { |
205 | 2e69e97c | gaqhf | if (closeDocument && newDrawing != null) |
206 | { |
||
207 | newDrawing.Save(); |
||
208 | newDrawing.CloseDrawing(true); |
||
209 | 61878df9 | gaqhf | ReleaseCOMObjects(newDrawing); |
210 | 2e69e97c | gaqhf | newDrawing = null; |
211 | } |
||
212 | else if (newDrawing == null) |
||
213 | { |
||
214 | Log.Write("error document"); |
||
215 | } |
||
216 | 3939eebf | gaqhf | } |
217 | 1ba9c671 | gaqhf | |
218 | 5e6ecf05 | gaqhf | ReleaseCOMObjects(dataSource); |
219 | 4941f5fe | gaqhf | dataSource = null; |
220 | 5e6ecf05 | gaqhf | ReleaseCOMObjects(_placement); |
221 | 4941f5fe | gaqhf | _placement = null; |
222 | 965eb728 | gaqhf | |
223 | 4941f5fe | gaqhf | Thread.Sleep(1000); |
224 | 5e6ecf05 | gaqhf | } |
225 | 65a1ed4b | gaqhf | } |
226 | 5a9396ae | humkyung | |
227 | fb2d9638 | gaqhf | private void RunVendorPackageModeling() |
228 | { |
||
229 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.VendorPackages.Count); |
||
230 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "VendorPackages Modeling"); |
||
231 | foreach (VendorPackage item in document.VendorPackages) |
||
232 | { |
||
233 | try |
||
234 | { |
||
235 | VendorPackageModeling(item); |
||
236 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
237 | } |
||
238 | catch (Exception ex) |
||
239 | { |
||
240 | Log.Write("Error in RunVendorPackageModeling"); |
||
241 | Log.Write("UID : " + item.UID); |
||
242 | Log.Write(ex.Message); |
||
243 | Log.Write(ex.StackTrace); |
||
244 | } |
||
245 | } |
||
246 | } |
||
247 | b01e7456 | gaqhf | private void RunEquipmentModeling() |
248 | { |
||
249 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count); |
||
250 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling"); |
251 | 1bbfaabb | gaqhf | for (int i = 0; i < document.Equipments.Count; i++) |
252 | b01e7456 | gaqhf | { |
253 | 1bbfaabb | gaqhf | Equipment item = document.Equipments[i]; |
254 | b01e7456 | gaqhf | try |
255 | { |
||
256 | 1bbfaabb | gaqhf | if (!string.IsNullOrEmpty(item.SPPID.RepresentationId)) |
257 | continue; |
||
258 | b01e7456 | gaqhf | EquipmentModeling(item); |
259 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
||
260 | 1bbfaabb | gaqhf | if (!string.IsNullOrEmpty(item.SPPID.RepresentationId)) |
261 | i = -1; |
||
262 | b01e7456 | gaqhf | } |
263 | catch (Exception ex) |
||
264 | { |
||
265 | Log.Write("Error in EquipmentModeling"); |
||
266 | Log.Write("UID : " + item.UID); |
||
267 | Log.Write(ex.Message); |
||
268 | Log.Write(ex.StackTrace); |
||
269 | } |
||
270 | } |
||
271 | } |
||
272 | private void RunSymbolModeling() |
||
273 | { |
||
274 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
||
275 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling"); |
276 | b01e7456 | gaqhf | prioritySymbols = GetPrioritySymbol(); |
277 | foreach (var item in prioritySymbols) |
||
278 | { |
||
279 | try |
||
280 | { |
||
281 | f14b4e3b | gaqhf | if (document.VentDrainSymbol.Contains(item)) |
282 | continue; |
||
283 | b01e7456 | gaqhf | SymbolModelingBySymbol(item); |
284 | } |
||
285 | catch (Exception ex) |
||
286 | { |
||
287 | Log.Write("Error in SymbolModelingByPriority"); |
||
288 | Log.Write("UID : " + item.UID); |
||
289 | Log.Write(ex.Message); |
||
290 | Log.Write(ex.StackTrace); |
||
291 | } |
||
292 | } |
||
293 | } |
||
294 | private void RunLineModeling() |
||
295 | { |
||
296 | cf210438 | gaqhf | List<Line> AllLine = document.LINES.ToList(); |
297 | List<Line> stepLast_Line = document.LINES.FindAll(x => x.CONNECTORS.FindAll(y => y.ConnectedObject != null && y.ConnectedObject.GetType() == typeof(Symbol)).Count == 2 && |
||
298 | !SPPIDUtil.IsBranchedLine(document, x)); |
||
299 | List<Line> step1_Line = AllLine.FindAll(x => !stepLast_Line.Contains(x)); |
||
300 | |||
301 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, step1_Line.Count); |
||
302 | 02a45794 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 1"); |
303 | cf210438 | gaqhf | |
304 | SetPriorityLine(step1_Line); |
||
305 | foreach (var item in step1_Line) |
||
306 | b01e7456 | gaqhf | { |
307 | try |
||
308 | { |
||
309 | f14b4e3b | gaqhf | if (document.VentDrainLine.Contains(item)) |
310 | continue; |
||
311 | b01e7456 | gaqhf | NewLineModeling(item); |
312 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
313 | } |
||
314 | catch (Exception ex) |
||
315 | { |
||
316 | Log.Write("Error in NewLineModeling"); |
||
317 | Log.Write("UID : " + item.UID); |
||
318 | Log.Write(ex.Message); |
||
319 | Log.Write(ex.StackTrace); |
||
320 | } |
||
321 | } |
||
322 | cf210438 | gaqhf | |
323 | f3e2693f | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, BranchLines.Count); |
324 | 02a45794 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 2"); |
325 | f3e2693f | gaqhf | int branchCount = BranchLines.Count; |
326 | while (BranchLines.Count > 0) |
||
327 | b01e7456 | gaqhf | { |
328 | try |
||
329 | { |
||
330 | SortBranchLines(); |
||
331 | f3e2693f | gaqhf | Line item = BranchLines[0]; |
332 | d4c3e39f | gaqhf | NewLineModeling(item, true); |
333 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
334 | b01e7456 | gaqhf | } |
335 | catch (Exception ex) |
||
336 | { |
||
337 | Log.Write("Error in NewLineModeling"); |
||
338 | f3e2693f | gaqhf | Log.Write("UID : " + BranchLines[0].UID); |
339 | b01e7456 | gaqhf | Log.Write(ex.Message); |
340 | Log.Write(ex.StackTrace); |
||
341 | a1a55823 | gaqhf | BranchLines.Remove(BranchLines[0]); |
342 | b01e7456 | gaqhf | } |
343 | } |
||
344 | a31a512e | gaqhf | |
345 | cf210438 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, stepLast_Line.Count); |
346 | 02a45794 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 3"); |
347 | cf210438 | gaqhf | foreach (var item in stepLast_Line) |
348 | a31a512e | gaqhf | { |
349 | cf210438 | gaqhf | try |
350 | { |
||
351 | f14b4e3b | gaqhf | if (document.VentDrainLine.Contains(item)) |
352 | continue; |
||
353 | cf210438 | gaqhf | NewLineModeling(item); |
354 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
355 | } |
||
356 | catch (Exception ex) |
||
357 | { |
||
358 | Log.Write("Error in NewLineModeling"); |
||
359 | Log.Write("UID : " + item.UID); |
||
360 | Log.Write(ex.Message); |
||
361 | Log.Write(ex.StackTrace); |
||
362 | } |
||
363 | a31a512e | gaqhf | } |
364 | b01e7456 | gaqhf | } |
365 | f14b4e3b | gaqhf | private void RunVentDrainModeling() |
366 | { |
||
367 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.VentDrainLine.Count); |
||
368 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Vent Drain Modeling"); |
||
369 | foreach (var item in document.VentDrainLine) |
||
370 | { |
||
371 | try |
||
372 | { |
||
373 | Connector connector = item.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol)); |
||
374 | if (connector != null) |
||
375 | { |
||
376 | SetCoordinate(); |
||
377 | f676f99a | gaqhf | Symbol connSymbol = connector.ConnectedObject as Symbol; |
378 | SymbolModeling(connSymbol, null); |
||
379 | a2727dce | gaqhf | NewLineModeling(item, true); |
380 | f676f99a | gaqhf | |
381 | GridSetting grid = GridSetting.GetInstance(); |
||
382 | int count = grid.DrainValveCellCount; |
||
383 | double length = grid.Length; |
||
384 | |||
385 | // 길이 확인 |
||
386 | if (!string.IsNullOrEmpty(item.SPPID.ModelItemId)) |
||
387 | { |
||
388 | LMConnector _LMConnector = GetLMConnectorOnlyOne(item.SPPID.ModelItemId); |
||
389 | if (_LMConnector != null) |
||
390 | { |
||
391 | double[] connectorRange = GetConnectorRange(_LMConnector); |
||
392 | double connectorLength = double.NaN; |
||
393 | if (item.SlopeType == SlopeType.HORIZONTAL) |
||
394 | connectorLength = connectorRange[2] - connectorRange[0]; |
||
395 | else if (item.SlopeType == SlopeType.VERTICAL) |
||
396 | connectorLength = connectorRange[3] - connectorRange[1]; |
||
397 | |||
398 | if (!double.IsNaN(connectorLength) && connectorLength != count * length) |
||
399 | { |
||
400 | double move = count * length - connectorLength; |
||
401 | List<Symbol> group = new List<Symbol>(); |
||
402 | SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group); |
||
403 | foreach (var symbol in group) |
||
404 | { |
||
405 | int connSymbolIndex = item.CONNECTORS.IndexOf(item.CONNECTORS.Find(x => x.ConnectedObject == connSymbol)); |
||
406 | if (item.SlopeType == SlopeType.HORIZONTAL) |
||
407 | { |
||
408 | if (connSymbolIndex == 0) |
||
409 | { |
||
410 | if (item.SPPID.START_X > item.SPPID.END_X) |
||
411 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + move; |
||
412 | else |
||
413 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - move; |
||
414 | } |
||
415 | else |
||
416 | { |
||
417 | if (item.SPPID.START_X < item.SPPID.END_X) |
||
418 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + move; |
||
419 | else |
||
420 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - move; |
||
421 | } |
||
422 | } |
||
423 | else if (item.SlopeType == SlopeType.VERTICAL) |
||
424 | { |
||
425 | if (connSymbolIndex == 0) |
||
426 | { |
||
427 | if (item.SPPID.START_Y > item.SPPID.END_Y) |
||
428 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + move; |
||
429 | else |
||
430 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - move; |
||
431 | } |
||
432 | else |
||
433 | { |
||
434 | if (item.SPPID.START_Y < item.SPPID.END_Y) |
||
435 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + move; |
||
436 | else |
||
437 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - move; |
||
438 | } |
||
439 | } |
||
440 | } |
||
441 | |||
442 | // 제거 |
||
443 | RemoveSymbol(connSymbol); |
||
444 | RemoveLine(item); |
||
445 | |||
446 | // 재생성 |
||
447 | SymbolModelingBySymbol(connSymbol); |
||
448 | NewLineModeling(item, true); |
||
449 | } |
||
450 | } |
||
451 | |||
452 | ReleaseCOMObjects(_LMConnector); |
||
453 | _LMConnector = null; |
||
454 | } |
||
455 | f14b4e3b | gaqhf | } |
456 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
457 | } |
||
458 | catch (Exception ex) |
||
459 | { |
||
460 | Log.Write("Error in NewLineModeling"); |
||
461 | Log.Write("UID : " + item.UID); |
||
462 | Log.Write(ex.Message); |
||
463 | Log.Write(ex.StackTrace); |
||
464 | } |
||
465 | |||
466 | void SetCoordinate() |
||
467 | { |
||
468 | Connector branchConnector = item.CONNECTORS.Find(loop => loop.ConnectedObject != null && loop.ConnectedObject.GetType() == typeof(Line)); |
||
469 | if (branchConnector != null) |
||
470 | { |
||
471 | Line connLine = branchConnector.ConnectedObject as Line; |
||
472 | double x = 0; |
||
473 | double y = 0; |
||
474 | GetTargetLineConnectorPoint(branchConnector, item, ref x, ref y); |
||
475 | LMConnector targetConnector = FindTargetLMConnectorForBranch(item, connLine, ref x, ref y); |
||
476 | if (targetConnector != null) |
||
477 | { |
||
478 | List<Symbol> group = new List<Symbol>(); |
||
479 | SPPIDUtil.FindConnectedSymbolGroup(document, item.CONNECTORS.Find(loop => loop != branchConnector).ConnectedObject as Symbol, group); |
||
480 | if (item.SlopeType == SlopeType.HORIZONTAL) |
||
481 | { |
||
482 | item.SPPID.START_Y = y; |
||
483 | item.SPPID.END_Y = y; |
||
484 | foreach (var symbol in group) |
||
485 | { |
||
486 | symbol.SPPID.ORIGINAL_Y = y; |
||
487 | symbol.SPPID.SPPID_Y = y; |
||
488 | } |
||
489 | } |
||
490 | else if (item.SlopeType == SlopeType.VERTICAL) |
||
491 | { |
||
492 | item.SPPID.START_X = x; |
||
493 | item.SPPID.END_X = x; |
||
494 | foreach (var symbol in group) |
||
495 | { |
||
496 | symbol.SPPID.ORIGINAL_X = x; |
||
497 | symbol.SPPID.SPPID_X = x; |
||
498 | } |
||
499 | } |
||
500 | } |
||
501 | ReleaseCOMObjects(targetConnector); |
||
502 | targetConnector = null; |
||
503 | } |
||
504 | } |
||
505 | } |
||
506 | } |
||
507 | 9157c1b8 | gaqhf | private void RunClearNominalDiameter() |
508 | { |
||
509 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count + document.LINES.Count); |
||
510 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Attribute"); |
||
511 | 6dccfc55 | gaqhf | return; |
512 | |||
513 | 9157c1b8 | gaqhf | List<string> endClearModelItemID = new List<string>(); |
514 | for (int i = 0; i < document.LINES.Count; i++) |
||
515 | { |
||
516 | Line item = document.LINES[i]; |
||
517 | string modelItemID = item.SPPID.ModelItemId; |
||
518 | if (!string.IsNullOrEmpty(modelItemID)) |
||
519 | { |
||
520 | LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
||
521 | if (modelItem != null) |
||
522 | { |
||
523 | LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
||
524 | if (attribute != null) |
||
525 | attribute.set_Value(DBNull.Value); |
||
526 | |||
527 | modelItem.Commit(); |
||
528 | ReleaseCOMObjects(modelItem); |
||
529 | modelItem = null; |
||
530 | } |
||
531 | } |
||
532 | if (!endClearModelItemID.Contains(modelItemID)) |
||
533 | endClearModelItemID.Add(modelItemID); |
||
534 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
535 | } |
||
536 | for (int i = 0; i < document.SYMBOLS.Count; i++) |
||
537 | { |
||
538 | Symbol item = document.SYMBOLS[i]; |
||
539 | string repID = item.SPPID.RepresentationId; |
||
540 | string modelItemID = item.SPPID.ModelItemID; |
||
541 | if (!string.IsNullOrEmpty(modelItemID)) |
||
542 | { |
||
543 | LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
||
544 | if (modelItem != null) |
||
545 | { |
||
546 | LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
||
547 | if (attribute != null) |
||
548 | attribute.set_Value(DBNull.Value); |
||
549 | int index = 1; |
||
550 | while (true) |
||
551 | { |
||
552 | attribute = modelItem.Attributes[string.Format("PipingPoint{0}.NominalDiameter", index)]; |
||
553 | if (attribute != null) |
||
554 | attribute.set_Value(DBNull.Value); |
||
555 | else |
||
556 | break; |
||
557 | index++; |
||
558 | } |
||
559 | modelItem.Commit(); |
||
560 | ReleaseCOMObjects(modelItem); |
||
561 | modelItem = null; |
||
562 | } |
||
563 | } |
||
564 | if (!string.IsNullOrEmpty(repID)) |
||
565 | { |
||
566 | LMSymbol symbol = dataSource.GetSymbol(repID); |
||
567 | if (symbol != null) |
||
568 | { |
||
569 | foreach (LMConnector connector in symbol.Connect1Connectors) |
||
570 | { |
||
571 | if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID)) |
||
572 | { |
||
573 | endClearModelItemID.Add(connector.ModelItemID); |
||
574 | LMModelItem modelItem = connector.ModelItemObject; |
||
575 | if (modelItem != null) |
||
576 | { |
||
577 | LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
||
578 | if (attribute != null) |
||
579 | attribute.set_Value(DBNull.Value); |
||
580 | |||
581 | modelItem.Commit(); |
||
582 | ReleaseCOMObjects(modelItem); |
||
583 | modelItem = null; |
||
584 | } |
||
585 | } |
||
586 | } |
||
587 | foreach (LMConnector connector in symbol.Connect2Connectors) |
||
588 | { |
||
589 | if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID)) |
||
590 | { |
||
591 | endClearModelItemID.Add(connector.ModelItemID); |
||
592 | LMModelItem modelItem = connector.ModelItemObject; |
||
593 | if (modelItem != null) |
||
594 | { |
||
595 | LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
||
596 | if (attribute != null) |
||
597 | attribute.set_Value(DBNull.Value); |
||
598 | |||
599 | modelItem.Commit(); |
||
600 | ReleaseCOMObjects(modelItem); |
||
601 | modelItem = null; |
||
602 | } |
||
603 | } |
||
604 | } |
||
605 | } |
||
606 | ReleaseCOMObjects(symbol); |
||
607 | symbol = null; |
||
608 | } |
||
609 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
610 | } |
||
611 | } |
||
612 | 1ff0105e | gaqhf | private void RunClearValueInconsistancy() |
613 | b01e7456 | gaqhf | { |
614 | 32205389 | gaqhf | int count = 1; |
615 | 63fbf592 | gaqhf | bool loop = true; |
616 | while (loop) |
||
617 | b01e7456 | gaqhf | { |
618 | 63fbf592 | gaqhf | loop = false; |
619 | LMAFilter filter = new LMAFilter(); |
||
620 | LMACriterion criterion = new LMACriterion(); |
||
621 | filter.ItemType = "Relationship"; |
||
622 | criterion.SourceAttributeName = "SP_DRAWINGID"; |
||
623 | criterion.Operator = "="; |
||
624 | 4941f5fe | gaqhf | criterion.set_ValueAttribute(drawingID); |
625 | 63fbf592 | gaqhf | filter.get_Criteria().Add(criterion); |
626 | |||
627 | LMRelationships relationships = new LMRelationships(); |
||
628 | relationships.Collect(dataSource, Filter: filter); |
||
629 | |||
630 | d23fe61b | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, relationships.Count); |
631 | f9cc5190 | gaqhf | if (count > 1) |
632 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStepMinus, null); |
||
633 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Inconsistent Property Value - " + count); |
634 | 63fbf592 | gaqhf | foreach (LMRelationship relationship in relationships) |
635 | b01e7456 | gaqhf | { |
636 | 63fbf592 | gaqhf | foreach (LMInconsistency inconsistency in relationship.Inconsistencies) |
637 | b01e7456 | gaqhf | { |
638 | 63fbf592 | gaqhf | if (inconsistency.get_InconsistencyTypeIndex() == 1) |
639 | { |
||
640 | LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject; |
||
641 | LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject; |
||
642 | string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' }); |
||
643 | if (modelItem1 != null) |
||
644 | { |
||
645 | string attrName = array[0]; |
||
646 | if (attrName.Contains("PipingPoint")) |
||
647 | { |
||
648 | string originalAttr = attrName.Split(new char[] { '.' })[1]; |
||
649 | d23fe61b | gaqhf | int index = Convert.ToInt32(relationship.get_Item1Location()); |
650 | LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr]; |
||
651 | if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value())) |
||
652 | 63fbf592 | gaqhf | { |
653 | d23fe61b | gaqhf | loop = true; |
654 | attribute1.set_Value(DBNull.Value); |
||
655 | 63fbf592 | gaqhf | } |
656 | 4941f5fe | gaqhf | attribute1 = null; |
657 | 63fbf592 | gaqhf | } |
658 | else |
||
659 | { |
||
660 | LMAAttribute attribute1 = modelItem1.Attributes[attrName]; |
||
661 | if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value())) |
||
662 | { |
||
663 | loop = true; |
||
664 | attribute1.set_Value(DBNull.Value); |
||
665 | } |
||
666 | 4941f5fe | gaqhf | attribute1 = null; |
667 | 63fbf592 | gaqhf | } |
668 | modelItem1.Commit(); |
||
669 | } |
||
670 | if (modelItem2 != null) |
||
671 | { |
||
672 | string attrName = array[1]; |
||
673 | if (attrName.Contains("PipingPoint")) |
||
674 | { |
||
675 | string originalAttr = attrName.Split(new char[] { '.' })[1]; |
||
676 | d23fe61b | gaqhf | int index = Convert.ToInt32(relationship.get_Item2Location()); |
677 | LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr]; |
||
678 | if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value())) |
||
679 | 63fbf592 | gaqhf | { |
680 | d23fe61b | gaqhf | attribute2.set_Value(DBNull.Value); |
681 | loop = true; |
||
682 | 63fbf592 | gaqhf | } |
683 | 4941f5fe | gaqhf | attribute2 = null; |
684 | 63fbf592 | gaqhf | } |
685 | else |
||
686 | { |
||
687 | LMAAttribute attribute2 = modelItem2.Attributes[attrName]; |
||
688 | if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value())) |
||
689 | { |
||
690 | attribute2.set_Value(DBNull.Value); |
||
691 | loop = true; |
||
692 | } |
||
693 | 4941f5fe | gaqhf | attribute2 = null; |
694 | 63fbf592 | gaqhf | } |
695 | modelItem2.Commit(); |
||
696 | } |
||
697 | 4941f5fe | gaqhf | ReleaseCOMObjects(modelItem1); |
698 | modelItem1 = null; |
||
699 | ReleaseCOMObjects(modelItem2); |
||
700 | modelItem2 = null; |
||
701 | 63fbf592 | gaqhf | inconsistency.Commit(); |
702 | } |
||
703 | 4941f5fe | gaqhf | ReleaseCOMObjects(inconsistency); |
704 | b01e7456 | gaqhf | } |
705 | 63fbf592 | gaqhf | relationship.Commit(); |
706 | 4941f5fe | gaqhf | ReleaseCOMObjects(relationship); |
707 | d23fe61b | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
708 | b01e7456 | gaqhf | } |
709 | 63fbf592 | gaqhf | ReleaseCOMObjects(filter); |
710 | 4941f5fe | gaqhf | filter = null; |
711 | 63fbf592 | gaqhf | ReleaseCOMObjects(criterion); |
712 | 4941f5fe | gaqhf | criterion = null; |
713 | 63fbf592 | gaqhf | ReleaseCOMObjects(relationships); |
714 | 4941f5fe | gaqhf | relationships = null; |
715 | 32205389 | gaqhf | count++; |
716 | b01e7456 | gaqhf | } |
717 | } |
||
718 | private void RunEndBreakModeling() |
||
719 | { |
||
720 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count); |
||
721 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling"); |
||
722 | foreach (var item in document.EndBreaks) |
||
723 | try |
||
724 | { |
||
725 | EndBreakModeling(item); |
||
726 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
727 | } |
||
728 | catch (Exception ex) |
||
729 | { |
||
730 | Log.Write("Error in EndBreakModeling"); |
||
731 | Log.Write("UID : " + item.UID); |
||
732 | Log.Write(ex.Message); |
||
733 | Log.Write(ex.StackTrace); |
||
734 | } |
||
735 | } |
||
736 | private void RunSpecBreakModeling() |
||
737 | { |
||
738 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count); |
||
739 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling"); |
||
740 | foreach (var item in document.SpecBreaks) |
||
741 | try |
||
742 | { |
||
743 | SpecBreakModeling(item); |
||
744 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
745 | } |
||
746 | catch (Exception ex) |
||
747 | { |
||
748 | Log.Write("Error in SpecBreakModeling"); |
||
749 | Log.Write("UID : " + item.UID); |
||
750 | 9bcb092b | gaqhf | Log.Write(ex.Message); |
751 | Log.Write(ex.StackTrace); |
||
752 | } |
||
753 | } |
||
754 | dfac4553 | gaqhf | private void RunJoinRunForSameConnector() |
755 | { |
||
756 | d23fe61b | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count); |
757 | ca6e0f51 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 1"); |
758 | dfac4553 | gaqhf | foreach (var line in document.LINES) |
759 | { |
||
760 | 44087b23 | gaqhf | Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(line.SPPID.ModelItemId, false); |
761 | List<List<double[]>> result = new List<List<double[]>>(); |
||
762 | foreach (var item in vertices) |
||
763 | { |
||
764 | ReleaseCOMObjects(item.Key); |
||
765 | result.Add(item.Value); |
||
766 | } |
||
767 | line.SPPID.Vertices = result; |
||
768 | vertices = null; |
||
769 | } |
||
770 | |||
771 | foreach (var line in document.LINES) |
||
772 | { |
||
773 | d9fc7084 | gaqhf | foreach (var connector in line.CONNECTORS) |
774 | dfac4553 | gaqhf | { |
775 | d9fc7084 | gaqhf | if (connector.ConnectedObject != null && |
776 | connector.ConnectedObject.GetType() == typeof(Line) && |
||
777 | !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line)) |
||
778 | dfac4553 | gaqhf | { |
779 | d9fc7084 | gaqhf | Line connLine = connector.ConnectedObject as Line; |
780 | if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId && |
||
781 | !string.IsNullOrEmpty(line.SPPID.ModelItemId) && |
||
782 | !string.IsNullOrEmpty(connLine.SPPID.ModelItemId) && |
||
783 | !SPPIDUtil.IsSegment(document, line, connLine)) |
||
784 | dfac4553 | gaqhf | { |
785 | d9fc7084 | gaqhf | string survivorId = string.Empty; |
786 | JoinRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId, ref survivorId); |
||
787 | dfac4553 | gaqhf | } |
788 | d9fc7084 | gaqhf | |
789 | dfac4553 | gaqhf | } |
790 | } |
||
791 | d23fe61b | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
792 | } |
||
793 | fae4f386 | gaqhf | |
794 | foreach (var line in document.LINES) |
||
795 | line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId); |
||
796 | d23fe61b | gaqhf | } |
797 | ca6e0f51 | gaqhf | private void RunJoinRun() |
798 | { |
||
799 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count); |
||
800 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 2"); |
||
801 | a31a512e | gaqhf | List<string> endModelID = new List<string>(); |
802 | ca6e0f51 | gaqhf | foreach (var line in document.LINES) |
803 | { |
||
804 | a31a512e | gaqhf | if (!endModelID.Contains(line.SPPID.ModelItemId)) |
805 | { |
||
806 | while (!endModelID.Contains(line.SPPID.ModelItemId)) |
||
807 | { |
||
808 | string survivorId = string.Empty; |
||
809 | JoinRunBySameType(line.SPPID.ModelItemId, ref survivorId); |
||
810 | if (string.IsNullOrEmpty(survivorId)) |
||
811 | { |
||
812 | endModelID.Add(line.SPPID.ModelItemId); |
||
813 | } |
||
814 | } |
||
815 | } |
||
816 | ca6e0f51 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
817 | } |
||
818 | } |
||
819 | 8701de36 | gaqhf | private void RunLineNumberModeling() |
820 | { |
||
821 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count); |
||
822 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Number Modeling"); |
||
823 | foreach (var item in document.LINENUMBERS) |
||
824 | { |
||
825 | LMLabelPersist label = dataSource.GetLabelPersist(item.SPPID.RepresentationId); |
||
826 | if (label == null || (label != null && label.get_ItemStatus() != "Active")) |
||
827 | { |
||
828 | ReleaseCOMObjects(label); |
||
829 | item.SPPID.RepresentationId = null; |
||
830 | LineNumberModeling(item); |
||
831 | } |
||
832 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
833 | } |
||
834 | } |
||
835 | 32205389 | gaqhf | private void RunNoteModeling() |
836 | { |
||
837 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
||
838 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling"); |
||
839 | 1299077b | gaqhf | List<Note> correctList = new List<Note>(); |
840 | 32205389 | gaqhf | foreach (var item in document.NOTES) |
841 | try |
||
842 | { |
||
843 | 1299077b | gaqhf | NoteModeling(item, correctList); |
844 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
845 | } |
||
846 | catch (Exception ex) |
||
847 | { |
||
848 | Log.Write("Error in NoteModeling"); |
||
849 | Log.Write("UID : " + item.UID); |
||
850 | Log.Write(ex.Message); |
||
851 | Log.Write(ex.StackTrace); |
||
852 | } |
||
853 | |||
854 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count); |
||
855 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Note"); |
||
856 | SortNote(correctList); |
||
857 | List<Note> endList = new List<Note>(); |
||
858 | if (correctList.Count > 0) |
||
859 | endList.Add(correctList[0]); |
||
860 | ba25c427 | gaqhf | foreach (var item in correctList) |
861 | 1299077b | gaqhf | try |
862 | { |
||
863 | if (!endList.Contains(item)) |
||
864 | NoteCorrectModeling(item, endList); |
||
865 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
866 | } |
||
867 | catch (Exception ex) |
||
868 | { |
||
869 | Log.Write("Error in NoteModeling"); |
||
870 | Log.Write("UID : " + item.UID); |
||
871 | Log.Write(ex.Message); |
||
872 | Log.Write(ex.StackTrace); |
||
873 | } |
||
874 | } |
||
875 | private void RunTextModeling() |
||
876 | 9bcb092b | gaqhf | { |
877 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count); |
878 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling"); |
||
879 | e27329d6 | gaqhf | SortText(document.TEXTINFOS); |
880 | 32205389 | gaqhf | foreach (var item in document.TEXTINFOS) |
881 | try |
||
882 | { |
||
883 | e27329d6 | gaqhf | if (item.ASSOCIATION) |
884 | AssociationTextModeling(item); |
||
885 | else |
||
886 | NormalTextModeling(item); |
||
887 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
888 | } |
||
889 | catch (Exception ex) |
||
890 | { |
||
891 | Log.Write("Error in TextModeling"); |
||
892 | Log.Write("UID : " + item.UID); |
||
893 | Log.Write(ex.Message); |
||
894 | Log.Write(ex.StackTrace); |
||
895 | } |
||
896 | } |
||
897 | private void RunInputLineNumberAttribute() |
||
898 | { |
||
899 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count); |
||
900 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute"); |
||
901 | 82d6e5ea | gaqhf | List<string> endLine = new List<string>(); |
902 | 9bcb092b | gaqhf | foreach (var item in document.LINENUMBERS) |
903 | try |
||
904 | { |
||
905 | 82d6e5ea | gaqhf | InputLineNumberAttribute(item, endLine); |
906 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
907 | 9bcb092b | gaqhf | } |
908 | catch (Exception ex) |
||
909 | { |
||
910 | 32205389 | gaqhf | Log.Write("Error in InputLineNumberAttribute"); |
911 | Log.Write("UID : " + item.UID); |
||
912 | Log.Write(ex.Message); |
||
913 | Log.Write(ex.StackTrace); |
||
914 | } |
||
915 | } |
||
916 | private void RunInputSymbolAttribute() |
||
917 | { |
||
918 | 2e92b956 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count + document.Equipments.Count + document.LINES.Count); |
919 | 32205389 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute"); |
920 | foreach (var item in document.SYMBOLS) |
||
921 | try |
||
922 | { |
||
923 | InputSymbolAttribute(item, item.ATTRIBUTES); |
||
924 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
925 | } |
||
926 | catch (Exception ex) |
||
927 | { |
||
928 | Log.Write("Error in InputSymbolAttribute"); |
||
929 | Log.Write("UID : " + item.UID); |
||
930 | Log.Write(ex.Message); |
||
931 | Log.Write(ex.StackTrace); |
||
932 | } |
||
933 | 1ecaaba8 | gaqhf | |
934 | foreach (var item in document.Equipments) |
||
935 | try |
||
936 | { |
||
937 | InputSymbolAttribute(item, item.ATTRIBUTES); |
||
938 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
939 | } |
||
940 | catch (Exception ex) |
||
941 | { |
||
942 | Log.Write("Error in InputSymbolAttribute"); |
||
943 | Log.Write("UID : " + item.UID); |
||
944 | Log.Write(ex.Message); |
||
945 | Log.Write(ex.StackTrace); |
||
946 | } |
||
947 | 2e92b956 | gaqhf | foreach (var item in document.LINES) |
948 | try |
||
949 | { |
||
950 | InputSymbolAttribute(item, item.ATTRIBUTES); |
||
951 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
952 | } |
||
953 | catch (Exception ex) |
||
954 | { |
||
955 | Log.Write("Error in InputSymbolAttribute"); |
||
956 | Log.Write("UID : " + item.UID); |
||
957 | Log.Write(ex.Message); |
||
958 | Log.Write(ex.StackTrace); |
||
959 | } |
||
960 | 32205389 | gaqhf | } |
961 | private void RunInputSpecBreakAttribute() |
||
962 | { |
||
963 | d8afa58b | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count); |
964 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set SpecBreak Attribute"); |
||
965 | 32205389 | gaqhf | foreach (var item in document.SpecBreaks) |
966 | try |
||
967 | { |
||
968 | InputSpecBreakAttribute(item); |
||
969 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
970 | } |
||
971 | catch (Exception ex) |
||
972 | { |
||
973 | Log.Write("Error in InputSpecBreakAttribute"); |
||
974 | Log.Write("UID : " + item.UID); |
||
975 | Log.Write(ex.Message); |
||
976 | Log.Write(ex.StackTrace); |
||
977 | } |
||
978 | } |
||
979 | d8afa58b | gaqhf | private void RunInputEndBreakAttribute() |
980 | { |
||
981 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count); |
||
982 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set EndBreak Attribute"); |
||
983 | foreach (var item in document.EndBreaks) |
||
984 | try |
||
985 | { |
||
986 | InputEndBreakAttribute(item); |
||
987 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
988 | } |
||
989 | catch (Exception ex) |
||
990 | { |
||
991 | Log.Write("Error in RunInputEndBreakAttribute"); |
||
992 | Log.Write("UID : " + item.UID); |
||
993 | Log.Write(ex.Message); |
||
994 | Log.Write(ex.StackTrace); |
||
995 | } |
||
996 | } |
||
997 | 32205389 | gaqhf | private void RunLabelSymbolModeling() |
998 | { |
||
999 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
||
1000 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling"); |
||
1001 | foreach (var item in document.SYMBOLS) |
||
1002 | try |
||
1003 | { |
||
1004 | LabelSymbolModeling(item); |
||
1005 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
1006 | } |
||
1007 | catch (Exception ex) |
||
1008 | { |
||
1009 | Log.Write("Error in LabelSymbolModeling"); |
||
1010 | 9bcb092b | gaqhf | Log.Write("UID : " + item.UID); |
1011 | b01e7456 | gaqhf | Log.Write(ex.Message); |
1012 | Log.Write(ex.StackTrace); |
||
1013 | } |
||
1014 | b0d80571 | gaqhf | |
1015 | b01e7456 | gaqhf | } |
1016 | 4e865771 | gaqhf | private void RunCorrectAssociationText() |
1017 | { |
||
1018 | 44087b23 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count + document.LINENUMBERS.Count); |
1019 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Labels"); |
||
1020 | 4e865771 | gaqhf | List<Text> endTexts = new List<Text>(); |
1021 | foreach (var item in document.TEXTINFOS) |
||
1022 | { |
||
1023 | try |
||
1024 | { |
||
1025 | if (item.ASSOCIATION && !endTexts.Contains(item)) |
||
1026 | AssociationTextCorrectModeling(item, endTexts); |
||
1027 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
1028 | } |
||
1029 | catch (Exception ex) |
||
1030 | { |
||
1031 | 44087b23 | gaqhf | Log.Write("Error in RunCorrectAssociationText"); |
1032 | 4e865771 | gaqhf | Log.Write("UID : " + item.UID); |
1033 | Log.Write(ex.Message); |
||
1034 | Log.Write(ex.StackTrace); |
||
1035 | } |
||
1036 | 2e69e97c | gaqhf | |
1037 | 4e865771 | gaqhf | } |
1038 | 44087b23 | gaqhf | |
1039 | foreach (var item in document.LINENUMBERS) |
||
1040 | { |
||
1041 | try |
||
1042 | { |
||
1043 | LineNumberCorrectModeling(item); |
||
1044 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
1045 | } |
||
1046 | catch (Exception ex) |
||
1047 | { |
||
1048 | Log.Write("Error in RunCorrectAssociationText"); |
||
1049 | Log.Write("UID : " + item.UID); |
||
1050 | Log.Write(ex.Message); |
||
1051 | Log.Write(ex.StackTrace); |
||
1052 | } |
||
1053 | } |
||
1054 | 4e865771 | gaqhf | } |
1055 | c5b2c7ff | gaqhf | private void RunETC() |
1056 | { |
||
1057 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, FlowMarkRepIds.Count); |
||
1058 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "ETC"); |
||
1059 | foreach (var item in FlowMarkRepIds) |
||
1060 | { |
||
1061 | LMLabelPersist label = dataSource.GetLabelPersist(item); |
||
1062 | if (label != null) |
||
1063 | { |
||
1064 | label.get_GraphicOID(); |
||
1065 | DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[label.get_GraphicOID().ToString()] as DependencyObject; |
||
1066 | if (dependency != null) |
||
1067 | dependency.BringToFront(); |
||
1068 | } |
||
1069 | ReleaseCOMObjects(label); |
||
1070 | label = null; |
||
1071 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
1072 | } |
||
1073 | } |
||
1074 | 86c0a45e | gaqhf | private void RunBulkAttribute() |
1075 | { |
||
1076 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, 2); |
||
1077 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Bulk Attribute"); |
||
1078 | 4f0c0ed6 | gaqhf | |
1079 | List<SPPIDModel.BulkAttribute> select = _ETCSetting.BulkAttributes.FindAll(x => x.RuleName.Equals(document.BulkAttributeName)); |
||
1080 | if (select.Count > 0) |
||
1081 | SPPIDUtil.BulkAttribute(dataSource, select, BulkAttributeItemType.PipeRun); |
||
1082 | 86c0a45e | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1083 | 4f0c0ed6 | gaqhf | if (select.Count > 0) |
1084 | SPPIDUtil.BulkAttribute(dataSource, select, BulkAttributeItemType.Symbol); |
||
1085 | 86c0a45e | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1086 | } |
||
1087 | 74752074 | gaqhf | /// <summary> |
1088 | /// 도면 생성 메서드 |
||
1089 | /// </summary> |
||
1090 | 4941f5fe | gaqhf | private bool CreateDocument(ref string drawingNumber, ref string drawingName) |
1091 | 0e0edfad | gaqhf | { |
1092 | 3734dcc5 | gaqhf | Log.Write("------------------ Start create document ------------------"); |
1093 | 6d12a734 | gaqhf | GetDrawingNameAndNumber(ref drawingName, ref drawingNumber); |
1094 | 3734dcc5 | gaqhf | Log.Write("Drawing name : " + drawingName); |
1095 | Log.Write("Drawing number : " + drawingNumber); |
||
1096 | d4c3e39f | gaqhf | Thread.Sleep(1000); |
1097 | 4941f5fe | gaqhf | newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName); |
1098 | if (newDrawing != null) |
||
1099 | { |
||
1100 | document.SPPID_DrawingNumber = drawingNumber; |
||
1101 | document.SPPID_DrawingName = drawingName; |
||
1102 | Thread.Sleep(1000); |
||
1103 | radApp.ActiveWindow.Fit(); |
||
1104 | Thread.Sleep(1000); |
||
1105 | radApp.ActiveWindow.Zoom = 2000; |
||
1106 | Thread.Sleep(2000); |
||
1107 | 7aee331b | gaqhf | |
1108 | 4941f5fe | gaqhf | //current LMDrawing 가져오기 |
1109 | LMAFilter filter = new LMAFilter(); |
||
1110 | LMACriterion criterion = new LMACriterion(); |
||
1111 | filter.ItemType = "Drawing"; |
||
1112 | criterion.SourceAttributeName = "Name"; |
||
1113 | criterion.Operator = "="; |
||
1114 | criterion.set_ValueAttribute(drawingName); |
||
1115 | filter.get_Criteria().Add(criterion); |
||
1116 | 7aee331b | gaqhf | |
1117 | 4941f5fe | gaqhf | LMDrawings drawings = new LMDrawings(); |
1118 | drawings.Collect(dataSource, Filter: filter); |
||
1119 | |||
1120 | 519902b7 | gaqhf | // Input Drawing Attribute |
1121 | LMDrawing drawing = ((dynamic)drawings).Nth(1); |
||
1122 | if (drawing != null) |
||
1123 | { |
||
1124 | 306a0af9 | gaqhf | using (DataTable drawingAttributeDT = Project_DB.SelectDrawingProjectAttribute()) |
1125 | { |
||
1126 | foreach (DataRow row in drawingAttributeDT.Rows) |
||
1127 | { |
||
1128 | string mappingName = DBNull.Value.Equals(row["SPPID_ATTRIBUTE"]) ? string.Empty : row["SPPID_ATTRIBUTE"].ToString(); |
||
1129 | if (!string.IsNullOrEmpty(mappingName)) |
||
1130 | { |
||
1131 | string uid = row["UID"].ToString(); |
||
1132 | string name = row["NAME"].ToString(); |
||
1133 | Text text = document.TEXTINFOS.Find(x => x.AREA == uid); |
||
1134 | if (text != null) |
||
1135 | { |
||
1136 | string value = text.VALUE; |
||
1137 | LMAAttribute attribute = drawing.Attributes[mappingName]; |
||
1138 | if (attribute != null) |
||
1139 | attribute.set_Value(value); |
||
1140 | ReleaseCOMObjects(attribute); |
||
1141 | document.TEXTINFOS.Remove(text); |
||
1142 | } |
||
1143 | } |
||
1144 | } |
||
1145 | 519902b7 | gaqhf | |
1146 | 306a0af9 | gaqhf | drawingAttributeDT.Dispose(); |
1147 | } |
||
1148 | 519902b7 | gaqhf | |
1149 | ReleaseCOMObjects(drawing); |
||
1150 | } |
||
1151 | |||
1152 | 4941f5fe | gaqhf | drawingID = ((dynamic)drawings).Nth(1).Id; |
1153 | ReleaseCOMObjects(filter); |
||
1154 | ReleaseCOMObjects(criterion); |
||
1155 | ReleaseCOMObjects(drawings); |
||
1156 | filter = null; |
||
1157 | criterion = null; |
||
1158 | drawings = null; |
||
1159 | } |
||
1160 | else |
||
1161 | Log.Write("Fail Create Drawing"); |
||
1162 | |||
1163 | if (newDrawing != null) |
||
1164 | b7b123ba | gaqhf | { |
1165 | SetBorderFile(); |
||
1166 | 4941f5fe | gaqhf | return true; |
1167 | b7b123ba | gaqhf | } |
1168 | 4941f5fe | gaqhf | else |
1169 | return false; |
||
1170 | b66a2996 | gaqhf | } |
1171 | |||
1172 | b7b123ba | gaqhf | private void SetBorderFile() |
1173 | { |
||
1174 | ETCSetting setting = ETCSetting.GetInstance(); |
||
1175 | |||
1176 | if (!string.IsNullOrEmpty(setting.BorderFilePath) && System.IO.File.Exists(setting.BorderFilePath)) |
||
1177 | { |
||
1178 | foreach (Ingr.RAD2D.SmartFrame2d smartFrame in radApp.ActiveDocument.ActiveSheet.SmartFrames2d) |
||
1179 | { |
||
1180 | if (!string.IsNullOrEmpty(smartFrame.LinkMoniker) && smartFrame.LinkMoniker != setting.BorderFilePath) |
||
1181 | { |
||
1182 | smartFrame.ChangeSource(Ingr.RAD2D.OLEInsertionTypeConstant.igOLELinked, setting.BorderFilePath, true); |
||
1183 | smartFrame.Update(); |
||
1184 | } |
||
1185 | 2e69e97c | gaqhf | |
1186 | b7b123ba | gaqhf | } |
1187 | } |
||
1188 | } |
||
1189 | |||
1190 | 02480ac1 | gaqhf | /// <summary> |
1191 | /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다. |
||
1192 | /// </summary> |
||
1193 | /// <param name="drawingName"></param> |
||
1194 | /// <param name="drawingNumber"></param> |
||
1195 | b66a2996 | gaqhf | private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber) |
1196 | { |
||
1197 | LMDrawings drawings = new LMDrawings(); |
||
1198 | drawings.Collect(dataSource); |
||
1199 | 7f00b26c | gaqhf | |
1200 | b66a2996 | gaqhf | List<string> drawingNameList = new List<string>(); |
1201 | List<string> drawingNumberList = new List<string>(); |
||
1202 | |||
1203 | foreach (LMDrawing item in drawings) |
||
1204 | { |
||
1205 | drawingNameList.Add(item.Attributes["Name"].get_Value().ToString()); |
||
1206 | drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString()); |
||
1207 | } |
||
1208 | |||
1209 | int nameLength = drawingName.Length; |
||
1210 | while (drawingNameList.Contains(drawingName)) |
||
1211 | { |
||
1212 | if (nameLength == drawingName.Length) |
||
1213 | drawingName += "-1"; |
||
1214 | else |
||
1215 | { |
||
1216 | int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1)); |
||
1217 | drawingName = drawingName.Substring(0, nameLength + 1); |
||
1218 | drawingName += ++index; |
||
1219 | } |
||
1220 | } |
||
1221 | |||
1222 | int numberLength = drawingNumber.Length; |
||
1223 | while (drawingNameList.Contains(drawingNumber)) |
||
1224 | { |
||
1225 | if (numberLength == drawingNumber.Length) |
||
1226 | drawingNumber += "-1"; |
||
1227 | else |
||
1228 | { |
||
1229 | int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1)); |
||
1230 | drawingNumber = drawingNumber.Substring(0, numberLength + 1); |
||
1231 | drawingNumber += ++index; |
||
1232 | } |
||
1233 | } |
||
1234 | ReleaseCOMObjects(drawings); |
||
1235 | 4941f5fe | gaqhf | drawings = null; |
1236 | 0e0edfad | gaqhf | } |
1237 | |||
1238 | 74752074 | gaqhf | /// <summary> |
1239 | /// 도면 크기 구하는 메서드 |
||
1240 | /// </summary> |
||
1241 | /// <returns></returns> |
||
1242 | 0e0edfad | gaqhf | private bool DocumentCoordinateCorrection() |
1243 | { |
||
1244 | 27e624cd | gaqhf | //if (radApp.ActiveDocument.ActiveSheet.SmartFrames2d.Count > 0) |
1245 | //{ |
||
1246 | // double x = 0; |
||
1247 | // double y = 0; |
||
1248 | // foreach (Ingr.RAD2D.SmartFrame2d smartFrame in radApp.ActiveDocument.ActiveSheet.SmartFrames2d) |
||
1249 | // { |
||
1250 | // x = Math.Max(smartFrame.CropRight, x); |
||
1251 | // y = Math.Max(smartFrame.CropTop, y); |
||
1252 | // } |
||
1253 | // document.SetSPPIDLocation(x, y); |
||
1254 | // document.CoordinateCorrection(); |
||
1255 | // return true; |
||
1256 | //} |
||
1257 | //else |
||
1258 | //{ |
||
1259 | // Log.Write("Need Border!"); |
||
1260 | // return false; |
||
1261 | //} |
||
1262 | |||
1263 | if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0) |
||
1264 | 0e0edfad | gaqhf | { |
1265 | 27e624cd | gaqhf | Log.Write("Setting Drawing X, Drawing Y"); |
1266 | document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY); |
||
1267 | Log.Write("Start coordinate correction"); |
||
1268 | c01ce90b | gaqhf | document.CoordinateCorrection(); |
1269 | 0e0edfad | gaqhf | return true; |
1270 | } |
||
1271 | else |
||
1272 | 3734dcc5 | gaqhf | { |
1273 | 27e624cd | gaqhf | Log.Write("Need Drawing X, Y"); |
1274 | 0e0edfad | gaqhf | return false; |
1275 | 3734dcc5 | gaqhf | } |
1276 | 0e0edfad | gaqhf | } |
1277 | |||
1278 | 74752074 | gaqhf | /// <summary> |
1279 | /// 심볼을 실제로 Modeling 메서드 |
||
1280 | /// </summary> |
||
1281 | 5a9396ae | humkyung | /// <param name="symbol">생성할 심볼</param> |
1282 | /// <param name="targetSymbol">연결되어 있는 심볼</param> |
||
1283 | b2d1c1aa | gaqhf | private void SymbolModeling(Symbol symbol, Symbol targetSymbol) |
1284 | 809a7640 | gaqhf | { |
1285 | 7f00b26c | gaqhf | // OWNERSYMBOL Attribute, 값을 가지고 있을 경우 |
1286 | BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL"); |
||
1287 | if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None")) |
||
1288 | return; |
||
1289 | // 이미 모델링 됐을 경우 |
||
1290 | else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
||
1291 | return; |
||
1292 | 6a7573b0 | gaqhf | |
1293 | 7f00b26c | gaqhf | LMSymbol _LMSymbol = null; |
1294 | 809a7640 | gaqhf | |
1295 | 7f00b26c | gaqhf | string mappingPath = symbol.SPPID.MAPPINGNAME; |
1296 | double x = symbol.SPPID.ORIGINAL_X; |
||
1297 | double y = symbol.SPPID.ORIGINAL_Y; |
||
1298 | int mirror = 0; |
||
1299 | 55ab8c5d | gaqhf | double angle = symbol.ANGLE; |
1300 | 2fdb56bf | gaqhf | |
1301 | 7f00b26c | gaqhf | // OPC 일경우 180도 일때 Mirror |
1302 | if (mappingPath.Contains("Piping OPC's") && angle == Math.PI) |
||
1303 | mirror = 1; |
||
1304 | 1ab9a205 | gaqhf | |
1305 | 7f00b26c | gaqhf | // Mirror 계산 |
1306 | if (symbol.FLIP == 1) |
||
1307 | { |
||
1308 | mirror = 1; |
||
1309 | 617b1abc | gaqhf | if (angle == Math.PI || angle == 0) |
1310 | angle += Math.PI; |
||
1311 | 7f00b26c | gaqhf | } |
1312 | 1ab9a205 | gaqhf | |
1313 | 7f00b26c | gaqhf | if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
1314 | { |
||
1315 | 5a9396ae | humkyung | LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); /// RepresentationId로 SPPID 심볼을 찾음 |
1316 | 7f00b26c | gaqhf | Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol); |
1317 | if (connector != null) |
||
1318 | GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y); |
||
1319 | 809a7640 | gaqhf | |
1320 | 147c80c4 | gaqhf | LMConnector temp = LineModelingForSymbolZeroLength(symbol, _TargetItem, x, y); |
1321 | 7f00b26c | gaqhf | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
1322 | 147c80c4 | gaqhf | if (temp != null) |
1323 | _placement.PIDRemovePlacement(temp.AsLMRepresentation()); |
||
1324 | ReleaseCOMObjects(temp); |
||
1325 | temp = null; |
||
1326 | 809a7640 | gaqhf | |
1327 | 7f00b26c | gaqhf | if (_LMSymbol != null && _TargetItem != null) |
1328 | 6a7573b0 | gaqhf | symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
1329 | ac78b508 | gaqhf | |
1330 | 7f00b26c | gaqhf | ReleaseCOMObjects(_TargetItem); |
1331 | 4d2571ab | gaqhf | } |
1332 | 7f00b26c | gaqhf | else |
1333 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
1334 | |||
1335 | if (_LMSymbol != null) |
||
1336 | 4d2571ab | gaqhf | { |
1337 | 7f00b26c | gaqhf | _LMSymbol.Commit(); |
1338 | 60f4405d | gaqhf | |
1339 | // ConnCheck |
||
1340 | List<string> ids = new List<string>(); |
||
1341 | foreach (LMConnector item in _LMSymbol.Connect1Connectors) |
||
1342 | { |
||
1343 | if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id)) |
||
1344 | ids.Add(item.Id); |
||
1345 | ReleaseCOMObjects(item); |
||
1346 | } |
||
1347 | foreach (LMConnector item in _LMSymbol.Connect2Connectors) |
||
1348 | { |
||
1349 | if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id)) |
||
1350 | ids.Add(item.Id); |
||
1351 | ReleaseCOMObjects(item); |
||
1352 | } |
||
1353 | |||
1354 | int createdSymbolCount = document.SYMBOLS.FindAll(i => i.CONNECTORS.Find(j => j.CONNECTEDITEM == symbol.UID) != null && !string.IsNullOrEmpty(i.SPPID.RepresentationId)).Count; |
||
1355 | if (targetSymbol == null && ids.Count != createdSymbolCount) |
||
1356 | { |
||
1357 | double currentX = _LMSymbol.get_XCoordinate(); |
||
1358 | double currentY = _LMSymbol.get_YCoordinate(); |
||
1359 | |||
1360 | |||
1361 | } |
||
1362 | |||
1363 | 7f00b26c | gaqhf | symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
1364 | symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID; |
||
1365 | 32205389 | gaqhf | symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString(); |
1366 | 7f00b26c | gaqhf | |
1367 | foreach (var item in symbol.ChildSymbols) |
||
1368 | 7e4a64a3 | gaqhf | CreateChildSymbol(item, _LMSymbol, symbol); |
1369 | 3734dcc5 | gaqhf | |
1370 | d9794a6c | gaqhf | symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate(); |
1371 | symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate(); |
||
1372 | |||
1373 | double[] range = null; |
||
1374 | GetSPPIDSymbolRange(symbol, ref range); |
||
1375 | symbol.SPPID.SPPID_Min_X = range[0]; |
||
1376 | symbol.SPPID.SPPID_Min_Y = range[1]; |
||
1377 | symbol.SPPID.SPPID_Max_X = range[2]; |
||
1378 | symbol.SPPID.SPPID_Max_Y = range[3]; |
||
1379 | |||
1380 | foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols) |
||
1381 | item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X; |
||
1382 | foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols) |
||
1383 | item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y; |
||
1384 | |||
1385 | 3734dcc5 | gaqhf | ReleaseCOMObjects(_LMSymbol); |
1386 | 4d2571ab | gaqhf | } |
1387 | 809a7640 | gaqhf | } |
1388 | 147c80c4 | gaqhf | /// <summary> |
1389 | /// targetX와 targetY 기준 제일 먼 PipingPoint에 TempLine Modeling |
||
1390 | /// Signal Point는 고려하지 않음 |
||
1391 | /// </summary> |
||
1392 | /// <param name="symbol"></param> |
||
1393 | /// <param name="_TargetItem"></param> |
||
1394 | /// <param name="targetX"></param> |
||
1395 | /// <param name="targetY"></param> |
||
1396 | /// <returns></returns> |
||
1397 | private LMConnector LineModelingForSymbolZeroLength(Symbol symbol, LMSymbol _TargetItem, double targetX, double targetY) |
||
1398 | { |
||
1399 | LMConnector tempConnector = null; |
||
1400 | |||
1401 | List<Symbol> group = new List<Symbol>(); |
||
1402 | SPPIDUtil.FindConnectedSymbolGroup(document, symbol, group); |
||
1403 | if (group.FindAll(loopX => !string.IsNullOrEmpty(loopX.SPPID.RepresentationId)).Count == 1) |
||
1404 | { |
||
1405 | List<Connector> connectors = new List<Connector>(); |
||
1406 | foreach (var item in group) |
||
1407 | connectors.AddRange(item.CONNECTORS.FindAll(loopX => loopX.ConnectedObject != null && loopX.ConnectedObject.GetType() == typeof(Line))); |
||
1408 | /// Primary or Secondary Type Line만 고려 |
||
1409 | Connector _connector = connectors.Find(loopX => loopX.ConnectedObject != null && loopX.ConnectedObject.GetType() == typeof(Line) && |
||
1410 | (((Line)loopX.ConnectedObject).TYPE == "Primary" || ((Line)loopX.ConnectedObject).TYPE == "Secondary")); |
||
1411 | if (_connector != null) |
||
1412 | { |
||
1413 | string sppidLine = ((Line)_connector.ConnectedObject).SPPID.MAPPINGNAME; |
||
1414 | List<double[]> pointInfos = getPipingPoints(_TargetItem); |
||
1415 | /// PipingPoint가 2개 이상만 |
||
1416 | if (pointInfos.Count >= 2) |
||
1417 | { |
||
1418 | double lineX = 0; |
||
1419 | double lineY = 0; |
||
1420 | double length = 0; |
||
1421 | foreach (var item in pointInfos) |
||
1422 | { |
||
1423 | double tempX = item[1]; |
||
1424 | double tempY = item[2]; |
||
1425 | |||
1426 | double calcDistance = SPPIDUtil.CalcPointToPointdDistance(targetX, targetY, tempX, tempY); |
||
1427 | if (calcDistance > length) |
||
1428 | { |
||
1429 | lineX = tempX; |
||
1430 | lineY = tempY; |
||
1431 | } |
||
1432 | } |
||
1433 | |||
1434 | _LMAItem _LMAItem = _placement.PIDCreateItem(sppidLine); |
||
1435 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
1436 | placeRunInputs.AddPoint(-1, -1); |
||
1437 | c9a4db3a | gaqhf | placeRunInputs.AddSymbolTarget(_TargetItem, lineX, lineY); |
1438 | 147c80c4 | gaqhf | tempConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1439 | if (tempConnector != null) |
||
1440 | tempConnector.Commit(); |
||
1441 | ReleaseCOMObjects(_LMAItem); |
||
1442 | _LMAItem = null; |
||
1443 | ReleaseCOMObjects(placeRunInputs); |
||
1444 | placeRunInputs = null; |
||
1445 | } |
||
1446 | } |
||
1447 | } |
||
1448 | |||
1449 | return tempConnector; |
||
1450 | } |
||
1451 | /// <summary> |
||
1452 | /// Symbol의 PipingPoints를 구함 |
||
1453 | /// SignalPoint는 고려하지 않음 |
||
1454 | /// </summary> |
||
1455 | /// <param name="symbol"></param> |
||
1456 | /// <returns></returns> |
||
1457 | private List<double[]> getPipingPoints(LMSymbol symbol) |
||
1458 | { |
||
1459 | LMModelItem modelItem = symbol.ModelItemObject; |
||
1460 | LMPipingPoints pipingPoints = null; |
||
1461 | if (modelItem.get_ItemTypeName() == "PipingComp") |
||
1462 | { |
||
1463 | LMPipingComp pipingComp = dataSource.GetPipingComp(modelItem.Id); |
||
1464 | pipingPoints = pipingComp.PipingPoints; |
||
1465 | ReleaseCOMObjects(pipingComp); |
||
1466 | pipingComp = null; |
||
1467 | } |
||
1468 | else if (modelItem.get_ItemTypeName() == "Instrument") |
||
1469 | { |
||
1470 | LMInstrument instrument = dataSource.GetInstrument(modelItem.Id); |
||
1471 | pipingPoints = instrument.PipingPoints; |
||
1472 | ReleaseCOMObjects(instrument); |
||
1473 | instrument = null; |
||
1474 | } |
||
1475 | else |
||
1476 | Log.Write("다른 Type"); |
||
1477 | |||
1478 | List<double[]> info = new List<double[]>(); |
||
1479 | if (pipingPoints != null) |
||
1480 | { |
||
1481 | foreach (LMPipingPoint pipingPoint in pipingPoints) |
||
1482 | { |
||
1483 | foreach (LMAAttribute attribute in pipingPoint.Attributes) |
||
1484 | { |
||
1485 | if (attribute.Name == "PipingPointNumber") |
||
1486 | { |
||
1487 | int index = Convert.ToInt32(attribute.get_Value()); |
||
1488 | if (info.Find(loopX => loopX[0] == index) == null) |
||
1489 | { |
||
1490 | double x = 0; |
||
1491 | double y = 0; |
||
1492 | if (_placement.PIDConnectPointLocation(symbol, index, ref x, ref y)) |
||
1493 | info.Add(new double[] { index, x, y }); |
||
1494 | } |
||
1495 | } |
||
1496 | } |
||
1497 | } |
||
1498 | } |
||
1499 | ReleaseCOMObjects(modelItem); |
||
1500 | modelItem = null; |
||
1501 | ReleaseCOMObjects(pipingPoints); |
||
1502 | pipingPoints = null; |
||
1503 | |||
1504 | return info; |
||
1505 | } |
||
1506 | 809a7640 | gaqhf | |
1507 | d9794a6c | gaqhf | private void RemoveSymbol(Symbol symbol) |
1508 | { |
||
1509 | if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
||
1510 | { |
||
1511 | LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1512 | if (_LMSymbol != null) |
||
1513 | { |
||
1514 | _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation()); |
||
1515 | ReleaseCOMObjects(_LMSymbol); |
||
1516 | } |
||
1517 | } |
||
1518 | |||
1519 | symbol.SPPID.RepresentationId = string.Empty; |
||
1520 | symbol.SPPID.ModelItemID = string.Empty; |
||
1521 | symbol.SPPID.SPPID_X = double.NaN; |
||
1522 | symbol.SPPID.SPPID_Y = double.NaN; |
||
1523 | symbol.SPPID.SPPID_Min_X = double.NaN; |
||
1524 | symbol.SPPID.SPPID_Min_Y = double.NaN; |
||
1525 | symbol.SPPID.SPPID_Max_X = double.NaN; |
||
1526 | symbol.SPPID.SPPID_Max_Y = double.NaN; |
||
1527 | } |
||
1528 | |||
1529 | private void RemoveSymbol(List<Symbol> symbols) |
||
1530 | { |
||
1531 | foreach (var symbol in symbols) |
||
1532 | { |
||
1533 | if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
||
1534 | { |
||
1535 | LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1536 | if (_LMSymbol != null) |
||
1537 | { |
||
1538 | _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation()); |
||
1539 | ReleaseCOMObjects(_LMSymbol); |
||
1540 | } |
||
1541 | } |
||
1542 | |||
1543 | symbol.SPPID.RepresentationId = string.Empty; |
||
1544 | symbol.SPPID.ModelItemID = string.Empty; |
||
1545 | symbol.SPPID.SPPID_X = double.NaN; |
||
1546 | symbol.SPPID.SPPID_Y = double.NaN; |
||
1547 | symbol.SPPID.SPPID_Min_X = double.NaN; |
||
1548 | symbol.SPPID.SPPID_Min_Y = double.NaN; |
||
1549 | symbol.SPPID.SPPID_Max_X = double.NaN; |
||
1550 | symbol.SPPID.SPPID_Max_Y = double.NaN; |
||
1551 | } |
||
1552 | } |
||
1553 | |||
1554 | d1eac84d | gaqhf | /// <summary> |
1555 | /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다. |
||
1556 | /// </summary> |
||
1557 | /// <param name="targetConnector"></param> |
||
1558 | /// <param name="targetSymbol"></param> |
||
1559 | /// <param name="x"></param> |
||
1560 | /// <param name="y"></param> |
||
1561 | private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y) |
||
1562 | { |
||
1563 | LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
||
1564 | 2fdb56bf | gaqhf | |
1565 | double[] range = null; |
||
1566 | d1eac84d | gaqhf | List<double[]> points = new List<double[]>(); |
1567 | 2fdb56bf | gaqhf | GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points); |
1568 | double x1 = range[0]; |
||
1569 | double y1 = range[1]; |
||
1570 | double x2 = range[2]; |
||
1571 | double y2 = range[3]; |
||
1572 | d1eac84d | gaqhf | |
1573 | // Origin 기준 Connector의 위치차이 |
||
1574 | double sceneX = 0; |
||
1575 | double sceneY = 0; |
||
1576 | SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY); |
||
1577 | double originX = 0; |
||
1578 | double originY = 0; |
||
1579 | SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY); |
||
1580 | double gapX = originX - sceneX; |
||
1581 | double gapY = originY - sceneY; |
||
1582 | |||
1583 | // SPPID Symbol과 ID2 심볼의 크기 차이 |
||
1584 | 026f394f | gaqhf | double sizeWidth = 0; |
1585 | double sizeHeight = 0; |
||
1586 | SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight); |
||
1587 | if (sizeWidth == 0 || sizeHeight == 0) |
||
1588 | throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID); |
||
1589 | |||
1590 | d1eac84d | gaqhf | double percentX = (x2 - x1) / sizeWidth; |
1591 | double percentY = (y2 - y1) / sizeHeight; |
||
1592 | |||
1593 | double SPPIDgapX = gapX * percentX; |
||
1594 | double SPPIDgapY = gapY * percentY; |
||
1595 | |||
1596 | double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY }; |
||
1597 | double distance = double.MaxValue; |
||
1598 | double[] resultPoint; |
||
1599 | foreach (var point in points) |
||
1600 | { |
||
1601 | double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]); |
||
1602 | if (distance > result) |
||
1603 | { |
||
1604 | distance = result; |
||
1605 | resultPoint = point; |
||
1606 | x = point[0]; |
||
1607 | y = point[1]; |
||
1608 | } |
||
1609 | } |
||
1610 | 2fdb56bf | gaqhf | |
1611 | ReleaseCOMObjects(_TargetItem); |
||
1612 | } |
||
1613 | |||
1614 | a0e3dca4 | gaqhf | private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y) |
1615 | { |
||
1616 | int index = targetLine.CONNECTORS.IndexOf(targetConnector); |
||
1617 | if (index == 0) |
||
1618 | { |
||
1619 | x = targetLine.SPPID.START_X; |
||
1620 | y = targetLine.SPPID.START_Y; |
||
1621 | } |
||
1622 | else |
||
1623 | { |
||
1624 | x = targetLine.SPPID.END_X; |
||
1625 | y = targetLine.SPPID.END_Y; |
||
1626 | } |
||
1627 | } |
||
1628 | |||
1629 | 2fdb56bf | gaqhf | /// <summary> |
1630 | /// SPPID Symbol의 Range를 구한다. |
||
1631 | /// </summary> |
||
1632 | /// <param name="symbol"></param> |
||
1633 | /// <param name="range"></param> |
||
1634 | private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points) |
||
1635 | { |
||
1636 | LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1637 | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
||
1638 | double x1 = 0; |
||
1639 | double y1 = 0; |
||
1640 | double x2 = 0; |
||
1641 | double y2 = 0; |
||
1642 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
1643 | range = new double[] { x1, y1, x2, y2 }; |
||
1644 | 2e69e97c | gaqhf | |
1645 | 14154713 | gaqhf | for (int i = 1; i < 30; i++) |
1646 | 2fdb56bf | gaqhf | { |
1647 | double connX = 0; |
||
1648 | double connY = 0; |
||
1649 | if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY)) |
||
1650 | points.Add(new double[] { connX, connY }); |
||
1651 | } |
||
1652 | |||
1653 | foreach (var childSymbol in symbol.ChildSymbols) |
||
1654 | GetSPPIDChildSymbolRange(childSymbol, ref range, points); |
||
1655 | |||
1656 | ReleaseCOMObjects(_TargetItem); |
||
1657 | } |
||
1658 | |||
1659 | 4e865771 | gaqhf | private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range, bool bOnlySymbol = false, bool bForGraphic = false) |
1660 | d9794a6c | gaqhf | { |
1661 | LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1662 | 7e4a64a3 | gaqhf | if (_TargetItem != null) |
1663 | { |
||
1664 | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
||
1665 | double x1 = 0; |
||
1666 | double y1 = 0; |
||
1667 | double x2 = 0; |
||
1668 | double y2 = 0; |
||
1669 | 4e865771 | gaqhf | if (!bForGraphic) |
1670 | { |
||
1671 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
1672 | range = new double[] { x1, y1, x2, y2 }; |
||
1673 | } |
||
1674 | else |
||
1675 | { |
||
1676 | x1 = double.MaxValue; |
||
1677 | y1 = double.MaxValue; |
||
1678 | x2 = double.MinValue; |
||
1679 | y2 = double.MinValue; |
||
1680 | range = new double[] { x1, y1, x2, y2 }; |
||
1681 | d9794a6c | gaqhf | |
1682 | 4e865771 | gaqhf | foreach (var item in symbol2d.DrawingObjects) |
1683 | { |
||
1684 | if (item.GetType() == typeof(Ingr.RAD2D.Line2d)) |
||
1685 | { |
||
1686 | Ingr.RAD2D.Line2d rangeObject = item as Ingr.RAD2D.Line2d; |
||
1687 | if (rangeObject.Layer == "Default") |
||
1688 | { |
||
1689 | rangeObject.Range(out x1, out y1, out x2, out y2); |
||
1690 | range = new double[] { |
||
1691 | Math.Min(x1, range[0]), |
||
1692 | Math.Min(y1, range[1]), |
||
1693 | Math.Max(x2, range[2]), |
||
1694 | Math.Max(y2, range[3]) |
||
1695 | }; |
||
1696 | } |
||
1697 | } |
||
1698 | else if (item.GetType() == typeof(Ingr.RAD2D.Circle2d)) |
||
1699 | { |
||
1700 | Ingr.RAD2D.Circle2d rangeObject = item as Ingr.RAD2D.Circle2d; |
||
1701 | if (rangeObject.Layer == "Default") |
||
1702 | { |
||
1703 | rangeObject.Range(out x1, out y1, out x2, out y2); |
||
1704 | range = new double[] { |
||
1705 | Math.Min(x1, range[0]), |
||
1706 | Math.Min(y1, range[1]), |
||
1707 | Math.Max(x2, range[2]), |
||
1708 | Math.Max(y2, range[3]) |
||
1709 | }; |
||
1710 | } |
||
1711 | } |
||
1712 | else if (item.GetType() == typeof(Ingr.RAD2D.Rectangle2d)) |
||
1713 | { |
||
1714 | Ingr.RAD2D.Rectangle2d rangeObject = item as Ingr.RAD2D.Rectangle2d; |
||
1715 | if (rangeObject.Layer == "Default") |
||
1716 | { |
||
1717 | rangeObject.Range(out x1, out y1, out x2, out y2); |
||
1718 | range = new double[] { |
||
1719 | Math.Min(x1, range[0]), |
||
1720 | Math.Min(y1, range[1]), |
||
1721 | Math.Max(x2, range[2]), |
||
1722 | Math.Max(y2, range[3]) |
||
1723 | }; |
||
1724 | } |
||
1725 | } |
||
1726 | else if (item.GetType() == typeof(Ingr.RAD2D.Arc2d)) |
||
1727 | { |
||
1728 | Ingr.RAD2D.Arc2d rangeObject = item as Ingr.RAD2D.Arc2d; |
||
1729 | if (rangeObject.Layer == "Default") |
||
1730 | { |
||
1731 | rangeObject.Range(out x1, out y1, out x2, out y2); |
||
1732 | range = new double[] { |
||
1733 | Math.Min(x1, range[0]), |
||
1734 | Math.Min(y1, range[1]), |
||
1735 | Math.Max(x2, range[2]), |
||
1736 | Math.Max(y2, range[3]) |
||
1737 | }; |
||
1738 | } |
||
1739 | } |
||
1740 | } |
||
1741 | } |
||
1742 | d9794a6c | gaqhf | |
1743 | 4e865771 | gaqhf | if (!bOnlySymbol) |
1744 | { |
||
1745 | foreach (var childSymbol in symbol.ChildSymbols) |
||
1746 | GetSPPIDChildSymbolRange(childSymbol, ref range); |
||
1747 | } |
||
1748 | 7e4a64a3 | gaqhf | ReleaseCOMObjects(_TargetItem); |
1749 | } |
||
1750 | d9794a6c | gaqhf | } |
1751 | |||
1752 | 1299077b | gaqhf | private void GetSPPIDSymbolRange(LMLabelPersist labelPersist, ref double[] range) |
1753 | { |
||
1754 | if (labelPersist != null) |
||
1755 | { |
||
1756 | 4e865771 | gaqhf | double x1 = double.MaxValue; |
1757 | double y1 = double.MaxValue; |
||
1758 | double x2 = double.MinValue; |
||
1759 | double y2 = double.MinValue; |
||
1760 | range = new double[] { x1, y1, x2, y2 }; |
||
1761 | |||
1762 | 1299077b | gaqhf | Ingr.RAD2D.DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject; |
1763 | 4e865771 | gaqhf | foreach (var item in dependency.DrawingObjects) |
1764 | 1299077b | gaqhf | { |
1765 | 4e865771 | gaqhf | Ingr.RAD2D.TextBox textBox = item as Ingr.RAD2D.TextBox; |
1766 | if (textBox != null) |
||
1767 | { |
||
1768 | if (dependency != null) |
||
1769 | { |
||
1770 | double tempX1; |
||
1771 | double tempY1; |
||
1772 | double tempX2; |
||
1773 | double tempY2; |
||
1774 | textBox.Range(out tempX1, out tempY1, out tempX2, out tempY2); |
||
1775 | x1 = Math.Min(x1, tempX1); |
||
1776 | y1 = Math.Min(y1, tempY1); |
||
1777 | x2 = Math.Max(x2, tempX2); |
||
1778 | y2 = Math.Max(y2, tempY2); |
||
1779 | |||
1780 | range = new double[] { x1, y1, x2, y2 }; |
||
1781 | } |
||
1782 | } |
||
1783 | 1299077b | gaqhf | } |
1784 | 2e69e97c | gaqhf | |
1785 | 1299077b | gaqhf | } |
1786 | } |
||
1787 | |||
1788 | 243668f5 | gaqhf | private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range, bool bOnlySymbol = false, bool bForGraphic = false) |
1789 | d9794a6c | gaqhf | { |
1790 | double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue }; |
||
1791 | foreach (var symbol in symbols) |
||
1792 | { |
||
1793 | 243668f5 | gaqhf | double[] symbolRange = null; |
1794 | GetSPPIDSymbolRange(symbol, ref symbolRange, bOnlySymbol, bForGraphic); |
||
1795 | d9794a6c | gaqhf | |
1796 | 243668f5 | gaqhf | tempRange[0] = Math.Min(tempRange[0], symbolRange[0]); |
1797 | tempRange[1] = Math.Min(tempRange[1], symbolRange[1]); |
||
1798 | tempRange[2] = Math.Max(tempRange[2], symbolRange[2]); |
||
1799 | tempRange[3] = Math.Max(tempRange[3], symbolRange[3]); |
||
1800 | d9794a6c | gaqhf | |
1801 | foreach (var childSymbol in symbol.ChildSymbols) |
||
1802 | f1a7faf9 | gaqhf | GetSPPIDChildSymbolRange(childSymbol, ref tempRange); |
1803 | d9794a6c | gaqhf | } |
1804 | |||
1805 | range = tempRange; |
||
1806 | } |
||
1807 | |||
1808 | 2fdb56bf | gaqhf | /// <summary> |
1809 | /// Child Modeling 된 Symbol의 Range를 구한다. |
||
1810 | /// </summary> |
||
1811 | /// <param name="childSymbol"></param> |
||
1812 | /// <param name="range"></param> |
||
1813 | private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points) |
||
1814 | { |
||
1815 | LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId); |
||
1816 | 3783c494 | gaqhf | if (_ChildSymbol != null) |
1817 | 2fdb56bf | gaqhf | { |
1818 | 3783c494 | gaqhf | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()]; |
1819 | double x1 = 0; |
||
1820 | double y1 = 0; |
||
1821 | double x2 = 0; |
||
1822 | double y2 = 0; |
||
1823 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
1824 | range[0] = Math.Min(range[0], x1); |
||
1825 | range[1] = Math.Min(range[1], y1); |
||
1826 | range[2] = Math.Max(range[2], x2); |
||
1827 | range[3] = Math.Max(range[3], y2); |
||
1828 | |||
1829 | for (int i = 1; i < int.MaxValue; i++) |
||
1830 | { |
||
1831 | double connX = 0; |
||
1832 | double connY = 0; |
||
1833 | if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY)) |
||
1834 | points.Add(new double[] { connX, connY }); |
||
1835 | else |
||
1836 | break; |
||
1837 | } |
||
1838 | 2fdb56bf | gaqhf | |
1839 | 3783c494 | gaqhf | foreach (var loopChildSymbol in childSymbol.ChildSymbols) |
1840 | GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points); |
||
1841 | 2fdb56bf | gaqhf | |
1842 | 3783c494 | gaqhf | ReleaseCOMObjects(_ChildSymbol); |
1843 | } |
||
1844 | d1eac84d | gaqhf | } |
1845 | |||
1846 | d9794a6c | gaqhf | private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range) |
1847 | { |
||
1848 | LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId); |
||
1849 | 7e4a64a3 | gaqhf | if (_ChildSymbol != null) |
1850 | { |
||
1851 | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()]; |
||
1852 | double x1 = 0; |
||
1853 | double y1 = 0; |
||
1854 | double x2 = 0; |
||
1855 | double y2 = 0; |
||
1856 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
1857 | range[0] = Math.Min(range[0], x1); |
||
1858 | range[1] = Math.Min(range[1], y1); |
||
1859 | range[2] = Math.Max(range[2], x2); |
||
1860 | range[3] = Math.Max(range[3], y2); |
||
1861 | d9794a6c | gaqhf | |
1862 | 7e4a64a3 | gaqhf | foreach (var loopChildSymbol in childSymbol.ChildSymbols) |
1863 | GetSPPIDChildSymbolRange(loopChildSymbol, ref range); |
||
1864 | ReleaseCOMObjects(_ChildSymbol); |
||
1865 | } |
||
1866 | d9794a6c | gaqhf | } |
1867 | |||
1868 | d1eac84d | gaqhf | /// <summary> |
1869 | /// Label Symbol Modeling |
||
1870 | /// </summary> |
||
1871 | /// <param name="symbol"></param> |
||
1872 | 73415441 | gaqhf | private void LabelSymbolModeling(Symbol symbol) |
1873 | { |
||
1874 | fb386b8c | gaqhf | if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
1875 | 73415441 | gaqhf | { |
1876 | fb386b8c | gaqhf | BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL"); |
1877 | if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None") |
||
1878 | return; |
||
1879 | Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y }; |
||
1880 | |||
1881 | string symbolUID = itemAttribute.VALUE; |
||
1882 | object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID); |
||
1883 | if (targetItem != null && |
||
1884 | (targetItem.GetType() == typeof(Symbol) || |
||
1885 | targetItem.GetType() == typeof(Equipment))) |
||
1886 | 73415441 | gaqhf | { |
1887 | fb386b8c | gaqhf | // Object 아이템이 Symbol일 경우 Equipment일 경우 |
1888 | string sRep = null; |
||
1889 | if (targetItem.GetType() == typeof(Symbol)) |
||
1890 | sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
||
1891 | else if (targetItem.GetType() == typeof(Equipment)) |
||
1892 | sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
||
1893 | if (!string.IsNullOrEmpty(sRep)) |
||
1894 | 73415441 | gaqhf | { |
1895 | fb386b8c | gaqhf | // LEADER Line 검사 |
1896 | bool leaderLine = false; |
||
1897 | SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID); |
||
1898 | if (symbolMapping != null) |
||
1899 | leaderLine = symbolMapping.LEADERLINE; |
||
1900 | |||
1901 | // Target Symbol Item 가져오고 Label Modeling |
||
1902 | LMSymbol _TargetItem = dataSource.GetSymbol(sRep); |
||
1903 | 33c7c928 | gaqhf | LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: symbol.ANGLE, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
1904 | fb386b8c | gaqhf | |
1905 | //Leader 선 센터로 |
||
1906 | if (_LMLabelPresist != null) |
||
1907 | 73415441 | gaqhf | { |
1908 | fb386b8c | gaqhf | // Target Item에 Label의 Attribute Input |
1909 | InputSymbolAttribute(targetItem, symbol.ATTRIBUTES); |
||
1910 | |||
1911 | 32205389 | gaqhf | string OID = _LMLabelPresist.get_GraphicOID().ToString(); |
1912 | fb386b8c | gaqhf | DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject; |
1913 | if (dependency != null) |
||
1914 | 73415441 | gaqhf | { |
1915 | fb386b8c | gaqhf | bool result = false; |
1916 | foreach (var attributes in dependency.AttributeSets) |
||
1917 | 73415441 | gaqhf | { |
1918 | fb386b8c | gaqhf | foreach (var attribute in attributes) |
1919 | 73415441 | gaqhf | { |
1920 | fb386b8c | gaqhf | string name = attribute.Name; |
1921 | string value = attribute.GetValue().ToString(); |
||
1922 | if (name == "DrawingItemType" && value == "LabelPersist") |
||
1923 | 73415441 | gaqhf | { |
1924 | fb386b8c | gaqhf | foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects) |
1925 | b2d1c1aa | gaqhf | { |
1926 | fb386b8c | gaqhf | if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d) |
1927 | { |
||
1928 | Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d; |
||
1929 | double prevX = _TargetItem.get_XCoordinate(); |
||
1930 | double prevY = _TargetItem.get_YCoordinate(); |
||
1931 | lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY); |
||
1932 | lineString2D.RemoveVertex(lineString2D.VertexCount); |
||
1933 | result = true; |
||
1934 | break; |
||
1935 | } |
||
1936 | b2d1c1aa | gaqhf | } |
1937 | 73415441 | gaqhf | } |
1938 | fb386b8c | gaqhf | |
1939 | if (result) |
||
1940 | break; |
||
1941 | 73415441 | gaqhf | } |
1942 | b2d1c1aa | gaqhf | |
1943 | if (result) |
||
1944 | break; |
||
1945 | 73415441 | gaqhf | } |
1946 | } |
||
1947 | fb386b8c | gaqhf | |
1948 | 30ba9ae0 | gaqhf | symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id; |
1949 | fb386b8c | gaqhf | _LMLabelPresist.Commit(); |
1950 | ReleaseCOMObjects(_LMLabelPresist); |
||
1951 | 73415441 | gaqhf | } |
1952 | |||
1953 | fb386b8c | gaqhf | ReleaseCOMObjects(_TargetItem); |
1954 | b2d1c1aa | gaqhf | } |
1955 | 73415441 | gaqhf | } |
1956 | fb386b8c | gaqhf | else if (targetItem != null && targetItem.GetType() == typeof(Line)) |
1957 | 0860c756 | gaqhf | { |
1958 | fb386b8c | gaqhf | Line targetLine = targetItem as Line; |
1959 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId); |
||
1960 | LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y); |
||
1961 | if (connectedLMConnector != null) |
||
1962 | 0860c756 | gaqhf | { |
1963 | 77a869a8 | gaqhf | // Target Item에 Label의 Attribute Input |
1964 | InputSymbolAttribute(targetItem, symbol.ATTRIBUTES); |
||
1965 | |||
1966 | fb386b8c | gaqhf | // LEADER Line 검사 |
1967 | bool leaderLine = false; |
||
1968 | SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID); |
||
1969 | if (symbolMapping != null) |
||
1970 | leaderLine = symbolMapping.LEADERLINE; |
||
1971 | |||
1972 | 98f64888 | gaqhf | LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: symbol.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
1973 | fb386b8c | gaqhf | if (_LMLabelPresist != null) |
1974 | { |
||
1975 | 6db0e733 | gaqhf | symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id; |
1976 | fb386b8c | gaqhf | _LMLabelPresist.Commit(); |
1977 | ReleaseCOMObjects(_LMLabelPresist); |
||
1978 | } |
||
1979 | ReleaseCOMObjects(connectedLMConnector); |
||
1980 | 0860c756 | gaqhf | } |
1981 | |||
1982 | fb386b8c | gaqhf | foreach (var item in connectorVertices) |
1983 | if (item.Key != null) |
||
1984 | ReleaseCOMObjects(item.Key); |
||
1985 | } |
||
1986 | 0860c756 | gaqhf | } |
1987 | 73415441 | gaqhf | } |
1988 | |||
1989 | 74752074 | gaqhf | /// <summary> |
1990 | /// Equipment를 실제로 Modeling 메서드 |
||
1991 | /// </summary> |
||
1992 | /// <param name="equipment"></param> |
||
1993 | b9e9f4c8 | gaqhf | private void EquipmentModeling(Equipment equipment) |
1994 | { |
||
1995 | if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId)) |
||
1996 | return; |
||
1997 | |||
1998 | LMSymbol _LMSymbol = null; |
||
1999 | LMSymbol targetItem = null; |
||
2000 | string mappingPath = equipment.SPPID.MAPPINGNAME; |
||
2001 | double x = equipment.SPPID.ORIGINAL_X; |
||
2002 | double y = equipment.SPPID.ORIGINAL_Y; |
||
2003 | int mirror = 0; |
||
2004 | double angle = equipment.ANGLE; |
||
2005 | |||
2006 | caef1a98 | gaqhf | // Mirror 계산 |
2007 | if (equipment.FLIP == 1) |
||
2008 | { |
||
2009 | mirror = 1; |
||
2010 | if (angle == Math.PI || angle == 0) |
||
2011 | angle += Math.PI; |
||
2012 | } |
||
2013 | |||
2014 | 20972c61 | gaqhf | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
2015 | |||
2016 | 1bbfaabb | gaqhf | Connector connector = equipment.CONNECTORS.Find(conn => |
2017 | !string.IsNullOrEmpty(conn.CONNECTEDITEM) && |
||
2018 | conn.CONNECTEDITEM != "None" && |
||
2019 | conn.ConnectedObject.GetType() == typeof(Equipment)); |
||
2020 | |||
2021 | b9e9f4c8 | gaqhf | if (connector != null) |
2022 | { |
||
2023 | Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment; |
||
2024 | fb2d9638 | gaqhf | VendorPackage connVendorPackage = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as VendorPackage; |
2025 | b9e9f4c8 | gaqhf | if (connEquipment != null) |
2026 | { |
||
2027 | 1bbfaabb | gaqhf | //if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
2028 | // EquipmentModeling(connEquipment); |
||
2029 | b9e9f4c8 | gaqhf | |
2030 | if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
||
2031 | { |
||
2032 | targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId); |
||
2033 | if (targetItem != null) |
||
2034 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
||
2035 | else |
||
2036 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
2037 | } |
||
2038 | else |
||
2039 | { |
||
2040 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
2041 | } |
||
2042 | } |
||
2043 | fb2d9638 | gaqhf | else if (connVendorPackage != null) |
2044 | { |
||
2045 | if (!string.IsNullOrEmpty(connVendorPackage.SPPID.RepresentationId)) |
||
2046 | { |
||
2047 | targetItem = dataSource.GetSymbol(connVendorPackage.SPPID.RepresentationId); |
||
2048 | if (targetItem != null) |
||
2049 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
||
2050 | else |
||
2051 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
2052 | } |
||
2053 | } |
||
2054 | b9e9f4c8 | gaqhf | else |
2055 | { |
||
2056 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
2057 | } |
||
2058 | } |
||
2059 | else |
||
2060 | { |
||
2061 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
2062 | } |
||
2063 | |||
2064 | if (_LMSymbol != null) |
||
2065 | { |
||
2066 | _LMSymbol.Commit(); |
||
2067 | equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
2068 | 32205389 | gaqhf | equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString(); |
2069 | b9e9f4c8 | gaqhf | ReleaseCOMObjects(_LMSymbol); |
2070 | } |
||
2071 | |||
2072 | if (targetItem != null) |
||
2073 | { |
||
2074 | ReleaseCOMObjects(targetItem); |
||
2075 | } |
||
2076 | 7f00b26c | gaqhf | |
2077 | b9e9f4c8 | gaqhf | ReleaseCOMObjects(_LMSymbol); |
2078 | } |
||
2079 | |||
2080 | fb2d9638 | gaqhf | private void VendorPackageModeling(VendorPackage vendorPackage) |
2081 | { |
||
2082 | ETCSetting setting = ETCSetting.GetInstance(); |
||
2083 | if (!string.IsNullOrEmpty(setting.VendorPackageSymbolPath)) |
||
2084 | { |
||
2085 | string symbolPath = setting.VendorPackageSymbolPath; |
||
2086 | double x = vendorPackage.SPPID.ORIGINAL_X; |
||
2087 | double y = vendorPackage.SPPID.ORIGINAL_Y; |
||
2088 | |||
2089 | LMSymbol symbol = _placement.PIDPlaceSymbol(symbolPath, x, y); |
||
2090 | if (symbol != null) |
||
2091 | { |
||
2092 | symbol.Commit(); |
||
2093 | vendorPackage.SPPID.RepresentationId = symbol.AsLMRepresentation().Id; |
||
2094 | } |
||
2095 | |||
2096 | ReleaseCOMObjects(symbol); |
||
2097 | symbol = null; |
||
2098 | } |
||
2099 | } |
||
2100 | |||
2101 | d9794a6c | gaqhf | /// <summary> |
2102 | /// 첫 진입점 |
||
2103 | /// </summary> |
||
2104 | /// <param name="symbol"></param> |
||
2105 | private void SymbolModelingBySymbol(Symbol symbol) |
||
2106 | { |
||
2107 | 5a9396ae | humkyung | SymbolModeling(symbol, null); /// 심볼을 생성한다 |
2108 | d9794a6c | gaqhf | List<object> endObjects = new List<object>(); |
2109 | endObjects.Add(symbol); |
||
2110 | f1a7faf9 | gaqhf | |
2111 | 5a9396ae | humkyung | /// 심볼에 연결되어 있는 항목들을 모델링한다 |
2112 | d9794a6c | gaqhf | foreach (var connector in symbol.CONNECTORS) |
2113 | 4d2571ab | gaqhf | { |
2114 | d9794a6c | gaqhf | object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
2115 | if (connItem != null && connItem.GetType() != typeof(Equipment)) |
||
2116 | d1eac84d | gaqhf | { |
2117 | d9794a6c | gaqhf | endObjects.Add(connItem); |
2118 | if (connItem.GetType() == typeof(Symbol)) |
||
2119 | 4d2571ab | gaqhf | { |
2120 | d9794a6c | gaqhf | Symbol connSymbol = connItem as Symbol; |
2121 | if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId)) |
||
2122 | 4d2571ab | gaqhf | { |
2123 | d9794a6c | gaqhf | SymbolModeling(connSymbol, symbol); |
2124 | } |
||
2125 | 6db30942 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
2126 | f1a7faf9 | gaqhf | SymbolModelingByNeerSymbolLoop(connSymbol, endObjects); |
2127 | d9794a6c | gaqhf | } |
2128 | else if (connItem.GetType() == typeof(Line)) |
||
2129 | { |
||
2130 | Line connLine = connItem as Line; |
||
2131 | f1a7faf9 | gaqhf | SymbolModelingByNeerLineLoop(connLine, endObjects, symbol); |
2132 | d9794a6c | gaqhf | } |
2133 | } |
||
2134 | } |
||
2135 | } |
||
2136 | 4d2571ab | gaqhf | |
2137 | f1a7faf9 | gaqhf | private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects) |
2138 | d9794a6c | gaqhf | { |
2139 | foreach (var connector in symbol.CONNECTORS) |
||
2140 | { |
||
2141 | object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
2142 | if (connItem != null && connItem.GetType() != typeof(Equipment)) |
||
2143 | { |
||
2144 | if (!endObjects.Contains(connItem)) |
||
2145 | { |
||
2146 | endObjects.Add(connItem); |
||
2147 | if (connItem.GetType() == typeof(Symbol)) |
||
2148 | { |
||
2149 | Symbol connSymbol = connItem as Symbol; |
||
2150 | if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId)) |
||
2151 | 4d2571ab | gaqhf | { |
2152 | d9794a6c | gaqhf | SymbolModeling(connSymbol, symbol); |
2153 | 4d2571ab | gaqhf | } |
2154 | 6db30942 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
2155 | f1a7faf9 | gaqhf | SymbolModelingByNeerSymbolLoop(connSymbol, endObjects); |
2156 | 4d2571ab | gaqhf | } |
2157 | d9794a6c | gaqhf | else if (connItem.GetType() == typeof(Line)) |
2158 | { |
||
2159 | Line connLine = connItem as Line; |
||
2160 | f1a7faf9 | gaqhf | SymbolModelingByNeerLineLoop(connLine, endObjects, symbol); |
2161 | d9794a6c | gaqhf | } |
2162 | } |
||
2163 | } |
||
2164 | } |
||
2165 | } |
||
2166 | 4d2571ab | gaqhf | |
2167 | f1a7faf9 | gaqhf | private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol) |
2168 | d9794a6c | gaqhf | { |
2169 | foreach (var connector in line.CONNECTORS) |
||
2170 | { |
||
2171 | object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
2172 | if (connItem != null && connItem.GetType() != typeof(Equipment)) |
||
2173 | { |
||
2174 | if (!endObjects.Contains(connItem)) |
||
2175 | { |
||
2176 | endObjects.Add(connItem); |
||
2177 | if (connItem.GetType() == typeof(Symbol)) |
||
2178 | { |
||
2179 | Symbol connSymbol = connItem as Symbol; |
||
2180 | if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId)) |
||
2181 | { |
||
2182 | b2064e69 | gaqhf | Line connLine = SPPIDUtil.GetConnectedLine(prevSymbol, connSymbol); |
2183 | int branchCount = 0; |
||
2184 | if (connLine != null) |
||
2185 | branchCount = SPPIDUtil.GetBranchLineCount(document, connLine); |
||
2186 | |||
2187 | d9794a6c | gaqhf | List<Symbol> group = new List<Symbol>(); |
2188 | SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group); |
||
2189 | f1a7faf9 | gaqhf | Symbol priority = prioritySymbols.Find(x => group.Contains(x)); |
2190 | List<Symbol> endModelingGroup = new List<Symbol>(); |
||
2191 | if (priority != null) |
||
2192 | d9794a6c | gaqhf | { |
2193 | f1a7faf9 | gaqhf | SymbolGroupModeling(priority, group); |
2194 | d9794a6c | gaqhf | |
2195 | // Range 겹치는지 확인해야함 |
||
2196 | double[] prevRange = null; |
||
2197 | 243668f5 | gaqhf | GetSPPIDSymbolRange(prevSymbol, ref prevRange, bForGraphic: true); |
2198 | d9794a6c | gaqhf | double[] groupRange = null; |
2199 | 243668f5 | gaqhf | GetSPPIDSymbolRange(group, ref groupRange, bForGraphic: true); |
2200 | d9794a6c | gaqhf | |
2201 | double distanceX = 0; |
||
2202 | double distanceY = 0; |
||
2203 | 6d12a734 | gaqhf | bool overlapX = false; |
2204 | bool overlapY = false; |
||
2205 | SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y); |
||
2206 | SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY); |
||
2207 | if ((slopeType == SlopeType.HORIZONTAL && overlapX) || |
||
2208 | (slopeType == SlopeType.VERTICAL && overlapY)) |
||
2209 | d9794a6c | gaqhf | { |
2210 | RemoveSymbol(group); |
||
2211 | foreach (var _temp in group) |
||
2212 | SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY); |
||
2213 | |||
2214 | f1a7faf9 | gaqhf | SymbolGroupModeling(priority, group); |
2215 | d9794a6c | gaqhf | } |
2216 | b2064e69 | gaqhf | else if (branchCount > 0) |
2217 | { |
||
2218 | LMConnector _connector = JustLineModeling(connLine); |
||
2219 | if (_connector != null) |
||
2220 | { |
||
2221 | double distance = GetConnectorDistance(_connector); |
||
2222 | int cellCount = (int)Math.Truncate(distance / GridSetting.GetInstance().Length); |
||
2223 | _placement.PIDRemovePlacement(_connector.AsLMRepresentation()); |
||
2224 | _connector.Commit(); |
||
2225 | ReleaseCOMObjects(_connector); |
||
2226 | _connector = null; |
||
2227 | if (cellCount < branchCount + 1) |
||
2228 | { |
||
2229 | int moveCount = branchCount - cellCount; |
||
2230 | RemoveSymbol(group); |
||
2231 | foreach (var _temp in group) |
||
2232 | SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, moveCount * GridSetting.GetInstance().Length, moveCount * GridSetting.GetInstance().Length); |
||
2233 | |||
2234 | SymbolGroupModeling(priority, group); |
||
2235 | } |
||
2236 | } |
||
2237 | } |
||
2238 | d9794a6c | gaqhf | } |
2239 | else |
||
2240 | { |
||
2241 | SymbolModeling(connSymbol, null); |
||
2242 | // Range 겹치는지 확인해야함 |
||
2243 | double[] prevRange = null; |
||
2244 | 243668f5 | gaqhf | GetSPPIDSymbolRange(prevSymbol, ref prevRange, bForGraphic: true); |
2245 | d9794a6c | gaqhf | double[] connRange = null; |
2246 | 243668f5 | gaqhf | GetSPPIDSymbolRange(connSymbol, ref connRange, bForGraphic: true); |
2247 | d9794a6c | gaqhf | |
2248 | double distanceX = 0; |
||
2249 | double distanceY = 0; |
||
2250 | 6d12a734 | gaqhf | bool overlapX = false; |
2251 | bool overlapY = false; |
||
2252 | SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y); |
||
2253 | SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY); |
||
2254 | if ((slopeType == SlopeType.HORIZONTAL && overlapX) || |
||
2255 | (slopeType == SlopeType.VERTICAL && overlapY)) |
||
2256 | d9794a6c | gaqhf | { |
2257 | RemoveSymbol(connSymbol); |
||
2258 | SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY); |
||
2259 | |||
2260 | SymbolModeling(connSymbol, null); |
||
2261 | } |
||
2262 | b2064e69 | gaqhf | else if (branchCount > 0) |
2263 | { |
||
2264 | LMConnector _connector = JustLineModeling(connLine); |
||
2265 | if (_connector != null) |
||
2266 | { |
||
2267 | double distance = GetConnectorDistance(_connector); |
||
2268 | int cellCount = (int)Math.Truncate(distance / GridSetting.GetInstance().Length); |
||
2269 | _placement.PIDRemovePlacement(_connector.AsLMRepresentation()); |
||
2270 | _connector.Commit(); |
||
2271 | ReleaseCOMObjects(_connector); |
||
2272 | _connector = null; |
||
2273 | if (cellCount < branchCount + 1) |
||
2274 | { |
||
2275 | int moveCount = branchCount - cellCount; |
||
2276 | RemoveSymbol(group); |
||
2277 | foreach (var _temp in group) |
||
2278 | SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, moveCount * GridSetting.GetInstance().Length, moveCount * GridSetting.GetInstance().Length); |
||
2279 | |||
2280 | SymbolGroupModeling(priority, group); |
||
2281 | } |
||
2282 | } |
||
2283 | } |
||
2284 | d9794a6c | gaqhf | } |
2285 | } |
||
2286 | 6db30942 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
2287 | f1a7faf9 | gaqhf | SymbolModelingByNeerSymbolLoop(connSymbol, endObjects); |
2288 | d9794a6c | gaqhf | } |
2289 | else if (connItem.GetType() == typeof(Line)) |
||
2290 | { |
||
2291 | Line connLine = connItem as Line; |
||
2292 | if (!SPPIDUtil.IsBranchLine(connLine, line)) |
||
2293 | f1a7faf9 | gaqhf | SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol); |
2294 | d9794a6c | gaqhf | } |
2295 | 4d2571ab | gaqhf | } |
2296 | d1eac84d | gaqhf | } |
2297 | } |
||
2298 | } |
||
2299 | |||
2300 | f1a7faf9 | gaqhf | private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group) |
2301 | { |
||
2302 | List<Symbol> endModelingGroup = new List<Symbol>(); |
||
2303 | SymbolModeling(firstSymbol, null); |
||
2304 | endModelingGroup.Add(firstSymbol); |
||
2305 | while (endModelingGroup.Count != group.Count) |
||
2306 | { |
||
2307 | foreach (var _symbol in group) |
||
2308 | { |
||
2309 | if (!endModelingGroup.Contains(_symbol)) |
||
2310 | { |
||
2311 | foreach (var _connector in _symbol.CONNECTORS) |
||
2312 | { |
||
2313 | Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol; |
||
2314 | if (_connSymbol != null && endModelingGroup.Contains(_connSymbol)) |
||
2315 | { |
||
2316 | SymbolModeling(_symbol, _connSymbol); |
||
2317 | endModelingGroup.Add(_symbol); |
||
2318 | break; |
||
2319 | } |
||
2320 | } |
||
2321 | } |
||
2322 | } |
||
2323 | } |
||
2324 | } |
||
2325 | d9794a6c | gaqhf | |
2326 | d1eac84d | gaqhf | /// <summary> |
2327 | 74752074 | gaqhf | /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드 |
2328 | /// </summary> |
||
2329 | /// <param name="childSymbol"></param> |
||
2330 | /// <param name="parentSymbol"></param> |
||
2331 | 7e4a64a3 | gaqhf | private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol, Symbol parent) |
2332 | ac78b508 | gaqhf | { |
2333 | 4b4dbca9 | gaqhf | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()]; |
2334 | double x1 = 0; |
||
2335 | double x2 = 0; |
||
2336 | double y1 = 0; |
||
2337 | double y2 = 0; |
||
2338 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
2339 | |||
2340 | LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol); |
||
2341 | if (_LMSymbol != null) |
||
2342 | { |
||
2343 | 04fcadf1 | gaqhf | _LMSymbol.Commit(); |
2344 | 4b4dbca9 | gaqhf | childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
2345 | foreach (var item in childSymbol.ChildSymbols) |
||
2346 | 7e4a64a3 | gaqhf | CreateChildSymbol(item, _LMSymbol, parent); |
2347 | 4b4dbca9 | gaqhf | } |
2348 | 7f00b26c | gaqhf | |
2349 | ac78b508 | gaqhf | |
2350 | ReleaseCOMObjects(_LMSymbol); |
||
2351 | } |
||
2352 | dec9ecfd | gaqhf | double index = 0; |
2353 | 32205389 | gaqhf | private void NewLineModeling(Line line, bool isBranchModeling = false) |
2354 | 809a7640 | gaqhf | { |
2355 | f3e2693f | gaqhf | if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (BranchLines.Contains(line) && !isBranchModeling)) |
2356 | a0e3dca4 | gaqhf | return; |
2357 | |||
2358 | List<Line> group = new List<Line>(); |
||
2359 | GetConnectedLineGroup(line, group); |
||
2360 | LineCoordinateCorrection(group); |
||
2361 | |||
2362 | foreach (var groupLine in group) |
||
2363 | 809a7640 | gaqhf | { |
2364 | e283d483 | gaqhf | if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine)) |
2365 | 5173ba5d | gaqhf | { |
2366 | f3e2693f | gaqhf | BranchLines.Add(groupLine); |
2367 | 5173ba5d | gaqhf | continue; |
2368 | } |
||
2369 | f9cc5190 | gaqhf | |
2370 | 24b5276c | gaqhf | bool diagonal = false; |
2371 | if (groupLine.SlopeType != SlopeType.HORIZONTAL && groupLine.SlopeType != SlopeType.VERTICAL) |
||
2372 | diagonal = true; |
||
2373 | 5173ba5d | gaqhf | _LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME); |
2374 | LMSymbol _LMSymbolStart = null; |
||
2375 | LMSymbol _LMSymbolEnd = null; |
||
2376 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
2377 | foreach (var connector in groupLine.CONNECTORS) |
||
2378 | 809a7640 | gaqhf | { |
2379 | 5173ba5d | gaqhf | double x = 0; |
2380 | double y = 0; |
||
2381 | GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y); |
||
2382 | if (connector.ConnectedObject == null) |
||
2383 | placeRunInputs.AddPoint(x, y); |
||
2384 | else if (connector.ConnectedObject.GetType() == typeof(Symbol)) |
||
2385 | a0e3dca4 | gaqhf | { |
2386 | 5173ba5d | gaqhf | Symbol targetSymbol = connector.ConnectedObject as Symbol; |
2387 | f9cc5190 | gaqhf | GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == groupLine), targetSymbol, ref x, ref y); |
2388 | 5173ba5d | gaqhf | if (groupLine.CONNECTORS.IndexOf(connector) == 0) |
2389 | a0e3dca4 | gaqhf | { |
2390 | 5173ba5d | gaqhf | _LMSymbolStart = GetTargetSymbol(targetSymbol, groupLine); |
2391 | 3783c494 | gaqhf | if (_LMSymbolStart != null) |
2392 | 24b5276c | gaqhf | placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y, diagonal); |
2393 | 3783c494 | gaqhf | else |
2394 | placeRunInputs.AddPoint(x, y); |
||
2395 | 5173ba5d | gaqhf | } |
2396 | else |
||
2397 | { |
||
2398 | _LMSymbolEnd = GetTargetSymbol(targetSymbol, groupLine); |
||
2399 | 3783c494 | gaqhf | if (_LMSymbolEnd != null) |
2400 | 24b5276c | gaqhf | placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y, diagonal); |
2401 | 3783c494 | gaqhf | else |
2402 | placeRunInputs.AddPoint(x, y); |
||
2403 | a0e3dca4 | gaqhf | } |
2404 | 5173ba5d | gaqhf | } |
2405 | else if (connector.ConnectedObject.GetType() == typeof(Line)) |
||
2406 | { |
||
2407 | Line targetLine = connector.ConnectedObject as Line; |
||
2408 | if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId)) |
||
2409 | a0e3dca4 | gaqhf | { |
2410 | 5173ba5d | gaqhf | LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y); |
2411 | 1c944b34 | gaqhf | if (targetConnector != null) |
2412 | 0ff6e67f | gaqhf | { |
2413 | placeRunInputs.AddConnectorTarget(targetConnector, x, y, diagonal); |
||
2414 | ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false); |
||
2415 | } |
||
2416 | else |
||
2417 | { |
||
2418 | 2e69e97c | gaqhf | placeRunInputs.AddPoint(x, y); |
2419 | 0ff6e67f | gaqhf | ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false); |
2420 | } |
||
2421 | a0e3dca4 | gaqhf | } |
2422 | 5173ba5d | gaqhf | else |
2423 | 809a7640 | gaqhf | { |
2424 | 5173ba5d | gaqhf | if (groupLine.CONNECTORS.IndexOf(connector) == 0) |
2425 | a0e3dca4 | gaqhf | { |
2426 | dec9ecfd | gaqhf | index += 0.01; |
2427 | 5173ba5d | gaqhf | if (groupLine.SlopeType == SlopeType.HORIZONTAL) |
2428 | dec9ecfd | gaqhf | placeRunInputs.AddPoint(x, -0.1 - index); |
2429 | 5173ba5d | gaqhf | else if (groupLine.SlopeType == SlopeType.VERTICAL) |
2430 | dec9ecfd | gaqhf | placeRunInputs.AddPoint(-0.1 - index, y); |
2431 | 5173ba5d | gaqhf | else |
2432 | ca6e0f51 | gaqhf | { |
2433 | 60f4405d | gaqhf | Line nextLine = groupLine.CONNECTORS[0].ConnectedObject as Line; |
2434 | if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45) |
||
2435 | dec9ecfd | gaqhf | placeRunInputs.AddPoint(-0.1 - index, y); |
2436 | 60f4405d | gaqhf | else |
2437 | placeRunInputs.AddPoint(x, -0.1 - index); |
||
2438 | ca6e0f51 | gaqhf | } |
2439 | a0e3dca4 | gaqhf | } |
2440 | 809a7640 | gaqhf | |
2441 | 5173ba5d | gaqhf | placeRunInputs.AddPoint(x, y); |
2442 | 809a7640 | gaqhf | |
2443 | 5173ba5d | gaqhf | if (groupLine.CONNECTORS.IndexOf(connector) == 1) |
2444 | { |
||
2445 | dec9ecfd | gaqhf | index += 0.01; |
2446 | 5173ba5d | gaqhf | if (groupLine.SlopeType == SlopeType.HORIZONTAL) |
2447 | dec9ecfd | gaqhf | placeRunInputs.AddPoint(x, -0.1 - index); |
2448 | 5173ba5d | gaqhf | else if (groupLine.SlopeType == SlopeType.VERTICAL) |
2449 | dec9ecfd | gaqhf | placeRunInputs.AddPoint(-0.1 - index, y); |
2450 | 5173ba5d | gaqhf | else |
2451 | ca6e0f51 | gaqhf | { |
2452 | 60f4405d | gaqhf | Line nextLine = groupLine.CONNECTORS[1].ConnectedObject as Line; |
2453 | if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45) |
||
2454 | dec9ecfd | gaqhf | placeRunInputs.AddPoint(-0.1 - index, y); |
2455 | 60f4405d | gaqhf | else |
2456 | placeRunInputs.AddPoint(x, -0.1 - index); |
||
2457 | ca6e0f51 | gaqhf | } |
2458 | a0e3dca4 | gaqhf | } |
2459 | 809a7640 | gaqhf | } |
2460 | } |
||
2461 | b0fda6ee | gaqhf | else |
2462 | placeRunInputs.AddPoint(x, y); |
||
2463 | 5173ba5d | gaqhf | } |
2464 | 809a7640 | gaqhf | |
2465 | 5173ba5d | gaqhf | LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
2466 | if (_lMConnector != null) |
||
2467 | { |
||
2468 | 04fcadf1 | gaqhf | _lMConnector.Commit(); |
2469 | 5173ba5d | gaqhf | groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID; |
2470 | fae4f386 | gaqhf | |
2471 | 5173ba5d | gaqhf | bool bRemodelingStart = false; |
2472 | if (_LMSymbolStart != null) |
||
2473 | NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart); |
||
2474 | bool bRemodelingEnd = false; |
||
2475 | if (_LMSymbolEnd != null) |
||
2476 | NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd); |
||
2477 | |||
2478 | if (bRemodelingStart || bRemodelingEnd) |
||
2479 | ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd); |
||
2480 | 32205389 | gaqhf | |
2481 | FlowMarkModeling(groupLine); |
||
2482 | |||
2483 | 5173ba5d | gaqhf | ReleaseCOMObjects(_lMConnector); |
2484 | 63a112d9 | gaqhf | |
2485 | LMModelItem modelItem = dataSource.GetModelItem(groupLine.SPPID.ModelItemId); |
||
2486 | if (modelItem != null) |
||
2487 | { |
||
2488 | LMAAttribute attribute = modelItem.Attributes["FlowDirection"]; |
||
2489 | 4c7a4484 | gaqhf | if (attribute != null) |
2490 | attribute.set_Value("End 1 is upstream (Inlet)"); |
||
2491 | 63a112d9 | gaqhf | modelItem.Commit(); |
2492 | } |
||
2493 | ReleaseCOMObjects(modelItem); |
||
2494 | modelItem = null; |
||
2495 | 5173ba5d | gaqhf | } |
2496 | dec9ecfd | gaqhf | else if (!isBranchModeling) |
2497 | { |
||
2498 | Log.Write("Main Line Modeling : " + groupLine.UID); |
||
2499 | } |
||
2500 | 809a7640 | gaqhf | |
2501 | 5173ba5d | gaqhf | List<object> removeLines = groupLine.CONNECTORS.FindAll(x => |
2502 | x.ConnectedObject != null && |
||
2503 | x.ConnectedObject.GetType() == typeof(Line) && |
||
2504 | !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)) |
||
2505 | .Select(x => x.ConnectedObject) |
||
2506 | .ToList(); |
||
2507 | 2fdb56bf | gaqhf | |
2508 | 5173ba5d | gaqhf | foreach (var item in removeLines) |
2509 | RemoveLineForModeling(item as Line); |
||
2510 | 5e6ecf05 | gaqhf | |
2511 | b2064e69 | gaqhf | ReleaseCOMObjects(_LMAItem); |
2512 | _LMAItem = null; |
||
2513 | ReleaseCOMObjects(placeRunInputs); |
||
2514 | placeRunInputs = null; |
||
2515 | ReleaseCOMObjects(_LMSymbolStart); |
||
2516 | _LMSymbolStart = null; |
||
2517 | ReleaseCOMObjects(_LMSymbolEnd); |
||
2518 | _LMSymbolEnd = null; |
||
2519 | 5e6ecf05 | gaqhf | |
2520 | f3e2693f | gaqhf | if (isBranchModeling && BranchLines.Contains(groupLine)) |
2521 | BranchLines.Remove(groupLine); |
||
2522 | a0e3dca4 | gaqhf | } |
2523 | } |
||
2524 | 5e6ecf05 | gaqhf | |
2525 | b2064e69 | gaqhf | private LMConnector JustLineModeling(Line line) |
2526 | { |
||
2527 | bool diagonal = false; |
||
2528 | if (line.SlopeType != SlopeType.HORIZONTAL && line.SlopeType != SlopeType.VERTICAL) |
||
2529 | diagonal = true; |
||
2530 | _LMAItem _LMAItem = _placement.PIDCreateItem(line.SPPID.MAPPINGNAME); |
||
2531 | LMSymbol _LMSymbolStart = null; |
||
2532 | LMSymbol _LMSymbolEnd = null; |
||
2533 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
2534 | foreach (var connector in line.CONNECTORS) |
||
2535 | { |
||
2536 | double x = 0; |
||
2537 | double y = 0; |
||
2538 | GetTargetLineConnectorPoint(connector, line, ref x, ref y); |
||
2539 | if (connector.ConnectedObject == null) |
||
2540 | { |
||
2541 | placeRunInputs.AddPoint(x, y); |
||
2542 | } |
||
2543 | else if (connector.ConnectedObject.GetType() == typeof(Symbol)) |
||
2544 | { |
||
2545 | Symbol targetSymbol = connector.ConnectedObject as Symbol; |
||
2546 | GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line), targetSymbol, ref x, ref y); |
||
2547 | if (line.CONNECTORS.IndexOf(connector) == 0) |
||
2548 | { |
||
2549 | _LMSymbolStart = GetTargetSymbol(targetSymbol, line); |
||
2550 | if (_LMSymbolStart != null) |
||
2551 | placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y, diagonal); |
||
2552 | else |
||
2553 | placeRunInputs.AddPoint(x, y); |
||
2554 | } |
||
2555 | else |
||
2556 | { |
||
2557 | _LMSymbolEnd = GetTargetSymbol(targetSymbol, line); |
||
2558 | if (_LMSymbolEnd != null) |
||
2559 | placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y, diagonal); |
||
2560 | else |
||
2561 | placeRunInputs.AddPoint(x, y); |
||
2562 | } |
||
2563 | } |
||
2564 | else if (connector.ConnectedObject.GetType() == typeof(Line)) |
||
2565 | { |
||
2566 | Line targetLine = connector.ConnectedObject as Line; |
||
2567 | if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId)) |
||
2568 | { |
||
2569 | LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y); |
||
2570 | if (targetConnector != null) |
||
2571 | { |
||
2572 | placeRunInputs.AddConnectorTarget(targetConnector, x, y, diagonal); |
||
2573 | ChangeLineSPPIDCoordinateByConnector(line, targetLine, x, y, false); |
||
2574 | } |
||
2575 | else |
||
2576 | { |
||
2577 | placeRunInputs.AddPoint(x, y); |
||
2578 | ChangeLineSPPIDCoordinateByConnector(line, targetLine, x, y, false); |
||
2579 | } |
||
2580 | } |
||
2581 | else |
||
2582 | placeRunInputs.AddPoint(x, y); |
||
2583 | } |
||
2584 | } |
||
2585 | |||
2586 | LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
2587 | if (_lMConnector != null) |
||
2588 | _lMConnector.Commit(); |
||
2589 | |||
2590 | ReleaseCOMObjects(_LMAItem); |
||
2591 | _LMAItem = null; |
||
2592 | ReleaseCOMObjects(placeRunInputs); |
||
2593 | placeRunInputs = null; |
||
2594 | ReleaseCOMObjects(_LMSymbolStart); |
||
2595 | _LMSymbolStart = null; |
||
2596 | ReleaseCOMObjects(_LMSymbolEnd); |
||
2597 | _LMSymbolEnd = null; |
||
2598 | |||
2599 | return _lMConnector; |
||
2600 | } |
||
2601 | |||
2602 | a0e3dca4 | gaqhf | private void RemoveLineForModeling(Line line) |
2603 | { |
||
2604 | LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
||
2605 | if (modelItem != null) |
||
2606 | { |
||
2607 | foreach (LMRepresentation rep in modelItem.Representations) |
||
2608 | { |
||
2609 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
2610 | 7f00b26c | gaqhf | { |
2611 | a0e3dca4 | gaqhf | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
2612 | 32205389 | gaqhf | dynamic OID = rep.get_GraphicOID().ToString(); |
2613 | a0e3dca4 | gaqhf | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
2614 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
2615 | int verticesCount = lineStringGeometry.VertexCount; |
||
2616 | double[] vertices = null; |
||
2617 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
2618 | for (int i = 0; i < verticesCount; i++) |
||
2619 | 7f00b26c | gaqhf | { |
2620 | a0e3dca4 | gaqhf | double x = 0; |
2621 | double y = 0; |
||
2622 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
2623 | 6924abc6 | gaqhf | if (verticesCount == 2 && (x < 0 || y < 0)) |
2624 | a0e3dca4 | gaqhf | _placement.PIDRemovePlacement(rep); |
2625 | c2ec33f5 | gaqhf | } |
2626 | a0e3dca4 | gaqhf | ReleaseCOMObjects(_LMConnector); |
2627 | 5e6ecf05 | gaqhf | } |
2628 | a0e3dca4 | gaqhf | } |
2629 | 7f00b26c | gaqhf | |
2630 | a0e3dca4 | gaqhf | ReleaseCOMObjects(modelItem); |
2631 | } |
||
2632 | } |
||
2633 | |||
2634 | f676f99a | gaqhf | private void RemoveLine(Line line) |
2635 | { |
||
2636 | LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
||
2637 | if (modelItem != null) |
||
2638 | { |
||
2639 | foreach (LMRepresentation rep in modelItem.Representations) |
||
2640 | { |
||
2641 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
2642 | _placement.PIDRemovePlacement(rep); |
||
2643 | } |
||
2644 | ReleaseCOMObjects(modelItem); |
||
2645 | } |
||
2646 | line.SPPID.ModelItemId = null; |
||
2647 | } |
||
2648 | |||
2649 | a0e3dca4 | gaqhf | private void GetConnectedLineGroup(Line line, List<Line> group) |
2650 | { |
||
2651 | if (!group.Contains(line)) |
||
2652 | group.Add(line); |
||
2653 | foreach (var connector in line.CONNECTORS) |
||
2654 | { |
||
2655 | if (connector.ConnectedObject != null && |
||
2656 | connector.ConnectedObject.GetType() == typeof(Line) && |
||
2657 | !group.Contains(connector.ConnectedObject) && |
||
2658 | string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId)) |
||
2659 | { |
||
2660 | Line connLine = connector.ConnectedObject as Line; |
||
2661 | if (!SPPIDUtil.IsBranchLine(connLine, line)) |
||
2662 | 24515a3a | gaqhf | { |
2663 | if (line.CONNECTORS.IndexOf(connector) == 0) |
||
2664 | group.Insert(0, connLine); |
||
2665 | else |
||
2666 | group.Add(connLine); |
||
2667 | a0e3dca4 | gaqhf | GetConnectedLineGroup(connLine, group); |
2668 | 24515a3a | gaqhf | } |
2669 | 7f00b26c | gaqhf | } |
2670 | } |
||
2671 | a0e3dca4 | gaqhf | } |
2672 | 7f00b26c | gaqhf | |
2673 | a0e3dca4 | gaqhf | private void LineCoordinateCorrection(List<Line> group) |
2674 | { |
||
2675 | // 순서대로 전 Item 기준 정렬 |
||
2676 | LineCoordinateCorrectionByStart(group); |
||
2677 | |||
2678 | // 역으로 심볼이 있을 경우 좌표 보정 |
||
2679 | LineCoordinateCorrectionForLastLine(group); |
||
2680 | } |
||
2681 | |||
2682 | private void LineCoordinateCorrectionByStart(List<Line> group) |
||
2683 | { |
||
2684 | for (int i = 0; i < group.Count; i++) |
||
2685 | 7f00b26c | gaqhf | { |
2686 | a0e3dca4 | gaqhf | Line line = group[i]; |
2687 | if (i == 0) |
||
2688 | 7f00b26c | gaqhf | { |
2689 | a0e3dca4 | gaqhf | Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol)); |
2690 | if (symbolConnector != null) |
||
2691 | LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject); |
||
2692 | 7f00b26c | gaqhf | } |
2693 | a0e3dca4 | gaqhf | else if (i != 0) |
2694 | 7f00b26c | gaqhf | { |
2695 | a0e3dca4 | gaqhf | LineCoordinateCorrectionByConnItem(line, group[i - 1]); |
2696 | } |
||
2697 | } |
||
2698 | } |
||
2699 | b66a2996 | gaqhf | |
2700 | a0e3dca4 | gaqhf | private void LineCoordinateCorrectionForLastLine(List<Line> group) |
2701 | { |
||
2702 | Line checkLine = group[group.Count - 1]; |
||
2703 | Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol)); |
||
2704 | if (lastSymbolConnector != null) |
||
2705 | { |
||
2706 | LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject); |
||
2707 | for (int i = group.Count - 2; i >= 0; i--) |
||
2708 | { |
||
2709 | Line line = group[i + 1]; |
||
2710 | Line prevLine = group[i]; |
||
2711 | 0bbd73b5 | gaqhf | |
2712 | a0e3dca4 | gaqhf | // 같으면 보정 |
2713 | if (line.SlopeType == prevLine.SlopeType) |
||
2714 | LineCoordinateCorrectionByConnItem(prevLine, line); |
||
2715 | else |
||
2716 | c2ec33f5 | gaqhf | { |
2717 | a0e3dca4 | gaqhf | if (line.SlopeType == SlopeType.HORIZONTAL) |
2718 | d63050d6 | gaqhf | { |
2719 | a0e3dca4 | gaqhf | double prevX = 0; |
2720 | double prevY = 0; |
||
2721 | GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY); |
||
2722 | ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX); |
||
2723 | d63050d6 | gaqhf | |
2724 | a0e3dca4 | gaqhf | double x = 0; |
2725 | double y = 0; |
||
2726 | GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y); |
||
2727 | ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y); |
||
2728 | d63050d6 | gaqhf | } |
2729 | a0e3dca4 | gaqhf | else if (line.SlopeType == SlopeType.VERTICAL) |
2730 | d63050d6 | gaqhf | { |
2731 | a0e3dca4 | gaqhf | double prevX = 0; |
2732 | double prevY = 0; |
||
2733 | GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY); |
||
2734 | ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY); |
||
2735 | d63050d6 | gaqhf | |
2736 | a0e3dca4 | gaqhf | double x = 0; |
2737 | double y = 0; |
||
2738 | GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y); |
||
2739 | ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x); |
||
2740 | d63050d6 | gaqhf | } |
2741 | a0e3dca4 | gaqhf | break; |
2742 | c2ec33f5 | gaqhf | } |
2743 | 1ab9a205 | gaqhf | } |
2744 | c2ec33f5 | gaqhf | } |
2745 | a0e3dca4 | gaqhf | } |
2746 | 7f00b26c | gaqhf | |
2747 | a0e3dca4 | gaqhf | private void LineCoordinateCorrectionByConnItem(Line line, object connItem) |
2748 | { |
||
2749 | double x = 0; |
||
2750 | double y = 0; |
||
2751 | if (connItem.GetType() == typeof(Symbol)) |
||
2752 | { |
||
2753 | Symbol targetSymbol = connItem as Symbol; |
||
2754 | Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line); |
||
2755 | if (targetConnector != null) |
||
2756 | GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y); |
||
2757 | else |
||
2758 | throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID); |
||
2759 | } |
||
2760 | else if (connItem.GetType() == typeof(Line)) |
||
2761 | c2ec33f5 | gaqhf | { |
2762 | a0e3dca4 | gaqhf | Line targetLine = connItem as Line; |
2763 | GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y); |
||
2764 | } |
||
2765 | 7f00b26c | gaqhf | |
2766 | a0e3dca4 | gaqhf | ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y); |
2767 | } |
||
2768 | 7f00b26c | gaqhf | |
2769 | a0e3dca4 | gaqhf | private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true) |
2770 | { |
||
2771 | Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
||
2772 | int index = line.CONNECTORS.IndexOf(connector); |
||
2773 | if (index == 0) |
||
2774 | { |
||
2775 | line.SPPID.START_X = x; |
||
2776 | line.SPPID.START_Y = y; |
||
2777 | if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate) |
||
2778 | line.SPPID.END_Y = y; |
||
2779 | else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate) |
||
2780 | line.SPPID.END_X = x; |
||
2781 | } |
||
2782 | else |
||
2783 | { |
||
2784 | line.SPPID.END_X = x; |
||
2785 | line.SPPID.END_Y = y; |
||
2786 | if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate) |
||
2787 | line.SPPID.START_Y = y; |
||
2788 | else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate) |
||
2789 | line.SPPID.START_X = x; |
||
2790 | c2ec33f5 | gaqhf | } |
2791 | a0e3dca4 | gaqhf | } |
2792 | 7f00b26c | gaqhf | |
2793 | a0e3dca4 | gaqhf | private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x) |
2794 | { |
||
2795 | Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
||
2796 | int index = line.CONNECTORS.IndexOf(connector); |
||
2797 | if (index == 0) |
||
2798 | { |
||
2799 | line.SPPID.START_X = x; |
||
2800 | if (line.SlopeType == SlopeType.VERTICAL) |
||
2801 | line.SPPID.END_X = x; |
||
2802 | } |
||
2803 | else |
||
2804 | { |
||
2805 | line.SPPID.END_X = x; |
||
2806 | if (line.SlopeType == SlopeType.VERTICAL) |
||
2807 | line.SPPID.START_X = x; |
||
2808 | } |
||
2809 | } |
||
2810 | 7f00b26c | gaqhf | |
2811 | a0e3dca4 | gaqhf | private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y) |
2812 | { |
||
2813 | Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
||
2814 | int index = line.CONNECTORS.IndexOf(connector); |
||
2815 | if (index == 0) |
||
2816 | { |
||
2817 | line.SPPID.START_Y = y; |
||
2818 | if (line.SlopeType == SlopeType.HORIZONTAL) |
||
2819 | line.SPPID.END_Y = y; |
||
2820 | } |
||
2821 | else |
||
2822 | { |
||
2823 | line.SPPID.END_Y = y; |
||
2824 | if (line.SlopeType == SlopeType.HORIZONTAL) |
||
2825 | line.SPPID.START_Y = y; |
||
2826 | } |
||
2827 | 1b261371 | gaqhf | } |
2828 | |||
2829 | 0860c756 | gaqhf | private void NeedReModeling(Line line, LMSymbol symbol, ref bool result) |
2830 | ac82b020 | gaqhf | { |
2831 | 0860c756 | gaqhf | if (symbol != null) |
2832 | ac82b020 | gaqhf | { |
2833 | fb386b8c | gaqhf | string repID = symbol.AsLMRepresentation().Id; |
2834 | string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID; |
||
2835 | string lineUID = line.UID; |
||
2836 | ac82b020 | gaqhf | |
2837 | fb386b8c | gaqhf | SpecBreak startSpecBreak = document.SpecBreaks.Find(x => |
2838 | (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) && |
||
2839 | (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID)); |
||
2840 | 71ba1ca3 | gaqhf | |
2841 | fb386b8c | gaqhf | EndBreak startEndBreak = document.EndBreaks.Find(x => |
2842 | (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) && |
||
2843 | (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID)); |
||
2844 | ac82b020 | gaqhf | |
2845 | fb386b8c | gaqhf | if (startSpecBreak != null || startEndBreak != null) |
2846 | result = true; |
||
2847 | ac82b020 | gaqhf | } |
2848 | } |
||
2849 | 7f00b26c | gaqhf | |
2850 | 74752074 | gaqhf | /// <summary> |
2851 | 1ab9a205 | gaqhf | /// Symbol에 붙을 경우 Line을 Remodeling 한다. |
2852 | /// </summary> |
||
2853 | /// <param name="lines"></param> |
||
2854 | /// <param name="prevLMConnector"></param> |
||
2855 | /// <param name="startSymbol"></param> |
||
2856 | /// <param name="endSymbol"></param> |
||
2857 | 5173ba5d | gaqhf | private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd) |
2858 | 1ab9a205 | gaqhf | { |
2859 | string symbolPath = string.Empty; |
||
2860 | #region get symbol path |
||
2861 | LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID); |
||
2862 | a31a512e | gaqhf | symbolPath = GetSPPIDFileName(modelItem); |
2863 | d77973b3 | gaqhf | ReleaseCOMObjects(modelItem); |
2864 | 1ab9a205 | gaqhf | #endregion |
2865 | 24b5276c | gaqhf | bool diagonal = false; |
2866 | if (line.SlopeType != SlopeType.HORIZONTAL && line.SlopeType != SlopeType.VERTICAL) |
||
2867 | diagonal = true; |
||
2868 | 1ab9a205 | gaqhf | _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath); |
2869 | LMConnector newConnector = null; |
||
2870 | 32205389 | gaqhf | dynamic OID = prevLMConnector.get_GraphicOID().ToString(); |
2871 | 1ab9a205 | gaqhf | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
2872 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
2873 | int verticesCount = lineStringGeometry.VertexCount; |
||
2874 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
2875 | 7f00b26c | gaqhf | |
2876 | 1ab9a205 | gaqhf | List<double[]> vertices = new List<double[]>(); |
2877 | for (int i = 1; i <= verticesCount; i++) |
||
2878 | { |
||
2879 | double x = 0; |
||
2880 | double y = 0; |
||
2881 | lineStringGeometry.GetVertex(i, ref x, ref y); |
||
2882 | vertices.Add(new double[] { x, y }); |
||
2883 | } |
||
2884 | |||
2885 | for (int i = 0; i < vertices.Count; i++) |
||
2886 | { |
||
2887 | double[] points = vertices[i]; |
||
2888 | // 시작 심볼이 있고 첫번째 좌표일 때 |
||
2889 | if (startSymbol != null && i == 0) |
||
2890 | { |
||
2891 | ac82b020 | gaqhf | if (bStart) |
2892 | { |
||
2893 | SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]); |
||
2894 | if (slopeType == SlopeType.HORIZONTAL) |
||
2895 | placeRunInputs.AddPoint(points[0], -0.1); |
||
2896 | else if (slopeType == SlopeType.VERTICAL) |
||
2897 | placeRunInputs.AddPoint(-0.1, points[1]); |
||
2898 | else |
||
2899 | placeRunInputs.AddPoint(points[0], -0.1); |
||
2900 | 1ab9a205 | gaqhf | |
2901 | ac82b020 | gaqhf | placeRunInputs.AddPoint(points[0], points[1]); |
2902 | } |
||
2903 | else |
||
2904 | { |
||
2905 | 24b5276c | gaqhf | placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1], diagonal); |
2906 | ac82b020 | gaqhf | } |
2907 | 1ab9a205 | gaqhf | } |
2908 | // 마지막 심볼이 있고 마지막 좌표일 때 |
||
2909 | else if (endSymbol != null && i == vertices.Count - 1) |
||
2910 | { |
||
2911 | ac82b020 | gaqhf | if (bEnd) |
2912 | { |
||
2913 | placeRunInputs.AddPoint(points[0], points[1]); |
||
2914 | 1ab9a205 | gaqhf | |
2915 | ac82b020 | gaqhf | SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]); |
2916 | if (slopeType == SlopeType.HORIZONTAL) |
||
2917 | placeRunInputs.AddPoint(points[0], -0.1); |
||
2918 | else if (slopeType == SlopeType.VERTICAL) |
||
2919 | placeRunInputs.AddPoint(-0.1, points[1]); |
||
2920 | else |
||
2921 | placeRunInputs.AddPoint(points[0], -0.1); |
||
2922 | } |
||
2923 | 1ab9a205 | gaqhf | else |
2924 | ac82b020 | gaqhf | { |
2925 | 24b5276c | gaqhf | placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1], diagonal); |
2926 | ac82b020 | gaqhf | } |
2927 | 1ab9a205 | gaqhf | } |
2928 | // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우 |
||
2929 | else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null) |
||
2930 | 24b5276c | gaqhf | placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1], diagonal); |
2931 | 1ab9a205 | gaqhf | // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우 |
2932 | else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null) |
||
2933 | 24b5276c | gaqhf | placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1], diagonal); |
2934 | 1ab9a205 | gaqhf | else |
2935 | placeRunInputs.AddPoint(points[0], points[1]); |
||
2936 | } |
||
2937 | |||
2938 | _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation()); |
||
2939 | newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
2940 | |||
2941 | ReleaseCOMObjects(placeRunInputs); |
||
2942 | ReleaseCOMObjects(_LMAItem); |
||
2943 | ReleaseCOMObjects(modelItem); |
||
2944 | |||
2945 | if (newConnector != null) |
||
2946 | { |
||
2947 | 04fcadf1 | gaqhf | newConnector.Commit(); |
2948 | ac82b020 | gaqhf | if (startSymbol != null && bStart) |
2949 | 1ab9a205 | gaqhf | { |
2950 | _LMAItem = _placement.PIDCreateItem(symbolPath); |
||
2951 | placeRunInputs = new PlaceRunInputs(); |
||
2952 | f1a7faf9 | gaqhf | placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]); |
2953 | placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]); |
||
2954 | 1ab9a205 | gaqhf | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
2955 | if (_LMConnector != null) |
||
2956 | { |
||
2957 | 04fcadf1 | gaqhf | _LMConnector.Commit(); |
2958 | 1ab9a205 | gaqhf | RemoveConnectorForReModelingLine(newConnector); |
2959 | 87f02fc0 | gaqhf | ZeroLengthModelItemID.Add(_LMConnector.ModelItemID); |
2960 | 1ab9a205 | gaqhf | ReleaseCOMObjects(_LMConnector); |
2961 | } |
||
2962 | ReleaseCOMObjects(placeRunInputs); |
||
2963 | ReleaseCOMObjects(_LMAItem); |
||
2964 | } |
||
2965 | |||
2966 | ac82b020 | gaqhf | if (endSymbol != null && bEnd) |
2967 | 1ab9a205 | gaqhf | { |
2968 | if (startSymbol != null) |
||
2969 | { |
||
2970 | Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID); |
||
2971 | newConnector = dicVertices.First().Key; |
||
2972 | } |
||
2973 | |||
2974 | _LMAItem = _placement.PIDCreateItem(symbolPath); |
||
2975 | placeRunInputs = new PlaceRunInputs(); |
||
2976 | f1a7faf9 | gaqhf | placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]); |
2977 | placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]); |
||
2978 | 1ab9a205 | gaqhf | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
2979 | if (_LMConnector != null) |
||
2980 | { |
||
2981 | 04fcadf1 | gaqhf | _LMConnector.Commit(); |
2982 | 1ab9a205 | gaqhf | RemoveConnectorForReModelingLine(newConnector); |
2983 | 1ff0105e | gaqhf | ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID); |
2984 | 1ab9a205 | gaqhf | ReleaseCOMObjects(_LMConnector); |
2985 | } |
||
2986 | ReleaseCOMObjects(placeRunInputs); |
||
2987 | ReleaseCOMObjects(_LMAItem); |
||
2988 | } |
||
2989 | |||
2990 | 5173ba5d | gaqhf | line.SPPID.ModelItemId = newConnector.ModelItemID; |
2991 | 1ab9a205 | gaqhf | ReleaseCOMObjects(newConnector); |
2992 | } |
||
2993 | |||
2994 | ReleaseCOMObjects(modelItem); |
||
2995 | } |
||
2996 | |||
2997 | /// <summary> |
||
2998 | /// Remodeling 과정에서 생긴 불필요한 Connector 제거 |
||
2999 | /// </summary> |
||
3000 | /// <param name="connector"></param> |
||
3001 | private void RemoveConnectorForReModelingLine(LMConnector connector) |
||
3002 | { |
||
3003 | Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID); |
||
3004 | foreach (var item in dicVertices) |
||
3005 | { |
||
3006 | 1805d3b7 | gaqhf | if (item.Value.Count == 2) |
3007 | 1ab9a205 | gaqhf | { |
3008 | 1805d3b7 | gaqhf | bool result = false; |
3009 | foreach (var point in item.Value) |
||
3010 | 1ab9a205 | gaqhf | { |
3011 | 1805d3b7 | gaqhf | if (point[0] < 0 || point[1] < 0) |
3012 | { |
||
3013 | result = true; |
||
3014 | _placement.PIDRemovePlacement(item.Key.AsLMRepresentation()); |
||
3015 | break; |
||
3016 | } |
||
3017 | 1ab9a205 | gaqhf | } |
3018 | |||
3019 | 1805d3b7 | gaqhf | if (result) |
3020 | break; |
||
3021 | } |
||
3022 | 1ab9a205 | gaqhf | } |
3023 | foreach (var item in dicVertices) |
||
3024 | ReleaseCOMObjects(item.Key); |
||
3025 | } |
||
3026 | |||
3027 | /// <summary> |
||
3028 | 74752074 | gaqhf | /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발 |
3029 | /// </summary> |
||
3030 | /// <param name="symbol"></param> |
||
3031 | /// <param name="line"></param> |
||
3032 | /// <returns></returns> |
||
3033 | f2baa6a3 | gaqhf | private LMSymbol GetTargetSymbol(Symbol symbol, Line line) |
3034 | { |
||
3035 | LMSymbol _LMSymbol = null; |
||
3036 | foreach (var connector in symbol.CONNECTORS) |
||
3037 | { |
||
3038 | a0e3dca4 | gaqhf | if (connector.CONNECTEDITEM == line.UID) |
3039 | 6b298450 | gaqhf | { |
3040 | a0e3dca4 | gaqhf | if (connector.Index == 0) |
3041 | _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
3042 | else |
||
3043 | 0860c756 | gaqhf | { |
3044 | a0e3dca4 | gaqhf | ChildSymbol child = null; |
3045 | foreach (var childSymbol in symbol.ChildSymbols) |
||
3046 | 0860c756 | gaqhf | { |
3047 | a0e3dca4 | gaqhf | if (childSymbol.Connectors.Contains(connector)) |
3048 | child = childSymbol; |
||
3049 | else |
||
3050 | child = GetChildSymbolByConnector(childSymbol, connector); |
||
3051 | |||
3052 | if (child != null) |
||
3053 | 0860c756 | gaqhf | break; |
3054 | } |
||
3055 | |||
3056 | a0e3dca4 | gaqhf | if (child != null) |
3057 | _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
||
3058 | 0860c756 | gaqhf | } |
3059 | |||
3060 | a0e3dca4 | gaqhf | break; |
3061 | 335b7a24 | gaqhf | } |
3062 | a0e3dca4 | gaqhf | } |
3063 | 335b7a24 | gaqhf | |
3064 | a0e3dca4 | gaqhf | return _LMSymbol; |
3065 | } |
||
3066 | |||
3067 | /// <summary> |
||
3068 | /// Connector를 가지고 있는 ChildSymbol Object 반환 |
||
3069 | /// </summary> |
||
3070 | /// <param name="item"></param> |
||
3071 | /// <param name="connector"></param> |
||
3072 | /// <returns></returns> |
||
3073 | private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
||
3074 | { |
||
3075 | foreach (var childSymbol in item.ChildSymbols) |
||
3076 | { |
||
3077 | if (childSymbol.Connectors.Contains(connector)) |
||
3078 | return childSymbol; |
||
3079 | else |
||
3080 | return GetChildSymbolByConnector(childSymbol, connector); |
||
3081 | 335b7a24 | gaqhf | } |
3082 | |||
3083 | a0e3dca4 | gaqhf | return null; |
3084 | 335b7a24 | gaqhf | } |
3085 | |||
3086 | 74752074 | gaqhf | /// <summary> |
3087 | /// EndBreak 모델링 메서드 |
||
3088 | /// </summary> |
||
3089 | /// <param name="endBreak"></param> |
||
3090 | 3165c259 | gaqhf | private void EndBreakModeling(EndBreak endBreak) |
3091 | 335b7a24 | gaqhf | { |
3092 | 10c7195c | gaqhf | object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
3093 | 1ab9a205 | gaqhf | object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE); |
3094 | fae4f386 | gaqhf | |
3095 | 1ab9a205 | gaqhf | LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem); |
3096 | fae4f386 | gaqhf | if (ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Symbol) && targetLMConnector != null) |
3097 | targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector); |
||
3098 | 3165c259 | gaqhf | |
3099 | 1ab9a205 | gaqhf | if (targetLMConnector != null) |
3100 | 10c7195c | gaqhf | { |
3101 | e0828ff4 | gaqhf | // LEADER Line 검사 |
3102 | bool leaderLine = false; |
||
3103 | SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == endBreak.DBUID); |
||
3104 | if (symbolMapping != null) |
||
3105 | leaderLine = symbolMapping.LEADERLINE; |
||
3106 | |||
3107 | 69222bff | gaqhf | SegmentLocation location; |
3108 | double[] point = GetSegmentPoint(ownerObj, connectedItem, targetLMConnector, out location); |
||
3109 | 02a45794 | gaqhf | Array array = null; |
3110 | if (point != null) |
||
3111 | array = new double[] { 0, point[0], point[1] }; |
||
3112 | else |
||
3113 | array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
||
3114 | e0828ff4 | gaqhf | LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
3115 | 5173ba5d | gaqhf | if (_LmLabelPersist != null) |
3116 | { |
||
3117 | 04fcadf1 | gaqhf | _LmLabelPersist.Commit(); |
3118 | 5173ba5d | gaqhf | endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id; |
3119 | d23fe61b | gaqhf | if (_LmLabelPersist.ModelItemObject != null) |
3120 | endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID; |
||
3121 | 32205389 | gaqhf | endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString(); |
3122 | 69222bff | gaqhf | |
3123 | MoveDependencyObject(endBreak.SPPID.GraphicOID, location); |
||
3124 | |||
3125 | 5173ba5d | gaqhf | ReleaseCOMObjects(_LmLabelPersist); |
3126 | } |
||
3127 | ReleaseCOMObjects(targetLMConnector); |
||
3128 | 2a4872ec | gaqhf | } |
3129 | f9eba687 | gaqhf | else |
3130 | { |
||
3131 | Log.Write("End Break UID : " + endBreak.UID); |
||
3132 | Log.Write("Can't find targetLMConnector"); |
||
3133 | } |
||
3134 | 2a4872ec | gaqhf | } |
3135 | b9e9f4c8 | gaqhf | |
3136 | 69222bff | gaqhf | private void MoveDependencyObject(string graphicOID, SegmentLocation location) |
3137 | { |
||
3138 | double x = 0, y = 0; |
||
3139 | if (location.HasFlag(SegmentLocation.Up)) |
||
3140 | y = GridSetting.GetInstance().Length * 3; |
||
3141 | else if (location.HasFlag(SegmentLocation.Down)) |
||
3142 | y = -GridSetting.GetInstance().Length * 3; |
||
3143 | |||
3144 | if (location.HasFlag(SegmentLocation.Right)) |
||
3145 | x = GridSetting.GetInstance().Length * 3; |
||
3146 | else if (location.HasFlag(SegmentLocation.Left)) |
||
3147 | x = -GridSetting.GetInstance().Length * 3; |
||
3148 | |||
3149 | if (x != 0 || y != 0) |
||
3150 | { |
||
3151 | radApp.ActiveSelectSet.RemoveAll(); |
||
3152 | DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] as DependencyObject; |
||
3153 | if (dependency != null) |
||
3154 | { |
||
3155 | radApp.ActiveSelectSet.Add(dependency); |
||
3156 | Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
||
3157 | transform.DefineByMove2d(x, y); |
||
3158 | radApp.ActiveSelectSet.Transform(transform, true); |
||
3159 | radApp.ActiveSelectSet.RemoveAll(); |
||
3160 | } |
||
3161 | } |
||
3162 | } |
||
3163 | |||
3164 | fae4f386 | gaqhf | private LMConnector ReModelingZeroLengthLMConnectorForSegment(LMConnector connector, string changeSymbolPath = null) |
3165 | 02480ac1 | gaqhf | { |
3166 | de97eaaa | gaqhf | string symbolPath = string.Empty; |
3167 | #region get symbol path |
||
3168 | d77973b3 | gaqhf | if (string.IsNullOrEmpty(changeSymbolPath)) |
3169 | { |
||
3170 | LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID); |
||
3171 | symbolPath = GetSPPIDFileName(modelItem); |
||
3172 | ReleaseCOMObjects(modelItem); |
||
3173 | } |
||
3174 | else |
||
3175 | symbolPath = changeSymbolPath; |
||
3176 | 2e69e97c | gaqhf | |
3177 | de97eaaa | gaqhf | #endregion |
3178 | |||
3179 | 02480ac1 | gaqhf | LMConnector newConnector = null; |
3180 | 32205389 | gaqhf | dynamic OID = connector.get_GraphicOID().ToString(); |
3181 | 02480ac1 | gaqhf | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
3182 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
3183 | int verticesCount = lineStringGeometry.VertexCount; |
||
3184 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
3185 | de97eaaa | gaqhf | _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath); |
3186 | 02480ac1 | gaqhf | |
3187 | if (Convert.ToBoolean(connector.get_IsZeroLength())) |
||
3188 | { |
||
3189 | double[] vertices = null; |
||
3190 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
3191 | double x = 0; |
||
3192 | double y = 0; |
||
3193 | lineStringGeometry.GetVertex(1, ref x, ref y); |
||
3194 | |||
3195 | 32205389 | gaqhf | string flowDirection = string.Empty; |
3196 | LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"]; |
||
3197 | if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value())) |
||
3198 | flowDirection = flowAttribute.get_Value().ToString(); |
||
3199 | |||
3200 | 3fdf052a | gaqhf | if (flowDirection == "End 1 is downstream (Outlet)") |
3201 | { |
||
3202 | placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y); |
||
3203 | placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y); |
||
3204 | flowDirection = "End 1 is upstream (Inlet)"; |
||
3205 | } |
||
3206 | else |
||
3207 | { |
||
3208 | placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y); |
||
3209 | placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y); |
||
3210 | } |
||
3211 | fae4f386 | gaqhf | string oldModelItemId = connector.ModelItemID; |
3212 | 02480ac1 | gaqhf | _placement.PIDRemovePlacement(connector.AsLMRepresentation()); |
3213 | newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
3214 | 04fcadf1 | gaqhf | newConnector.Commit(); |
3215 | 644f40b3 | gaqhf | ZeroLengthSymbolToSymbolModelItemID.Add(newConnector.ModelItemID); |
3216 | 32205389 | gaqhf | if (!string.IsNullOrEmpty(flowDirection)) |
3217 | newConnector.ModelItemObject.Attributes["FlowDirection"].set_Value(flowDirection); |
||
3218 | fae4f386 | gaqhf | ReleaseCOMObjects(connector); |
3219 | 02480ac1 | gaqhf | |
3220 | fae4f386 | gaqhf | foreach (var line in document.LINES.FindAll(z => z.SPPID.ModelItemId == oldModelItemId)) |
3221 | 02480ac1 | gaqhf | { |
3222 | fae4f386 | gaqhf | foreach (var repId in line.SPPID.Representations) |
3223 | 02480ac1 | gaqhf | { |
3224 | fae4f386 | gaqhf | LMConnector _connector = dataSource.GetConnector(repId); |
3225 | if (_connector != null && _connector.get_ItemStatus() == "Active") |
||
3226 | { |
||
3227 | if (line.SPPID.ModelItemId != _connector.ModelItemID) |
||
3228 | { |
||
3229 | line.SPPID.ModelItemId = _connector.ModelItemID; |
||
3230 | line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId); |
||
3231 | } |
||
3232 | } |
||
3233 | ReleaseCOMObjects(_connector); |
||
3234 | _connector = null; |
||
3235 | 02480ac1 | gaqhf | } |
3236 | } |
||
3237 | } |
||
3238 | |||
3239 | return newConnector; |
||
3240 | } |
||
3241 | |||
3242 | 74752074 | gaqhf | /// <summary> |
3243 | 53c81765 | gaqhf | /// SpecBreak Modeling 메서드 |
3244 | /// </summary> |
||
3245 | /// <param name="specBreak"></param> |
||
3246 | private void SpecBreakModeling(SpecBreak specBreak) |
||
3247 | { |
||
3248 | object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID); |
||
3249 | object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID); |
||
3250 | |||
3251 | if (upStreamObj != null && |
||
3252 | downStreamObj != null) |
||
3253 | { |
||
3254 | 1ab9a205 | gaqhf | LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj); |
3255 | 2e69e97c | gaqhf | if (upStreamObj.GetType() == typeof(Symbol) && downStreamObj.GetType() == typeof(Symbol) && |
3256 | targetLMConnector != null && |
||
3257 | 2b8c256c | gaqhf | !IsModelingEndBreak(upStreamObj as Symbol, downStreamObj as Symbol)) |
3258 | fae4f386 | gaqhf | targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector); |
3259 | |||
3260 | 1ab9a205 | gaqhf | if (targetLMConnector != null) |
3261 | 53c81765 | gaqhf | { |
3262 | 16584d30 | gaqhf | foreach (var attribute in specBreak.ATTRIBUTES) |
3263 | 53c81765 | gaqhf | { |
3264 | 16584d30 | gaqhf | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID); |
3265 | if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None") |
||
3266 | { |
||
3267 | string MappingPath = mapping.SPPIDSYMBOLNAME; |
||
3268 | 69222bff | gaqhf | SegmentLocation location; |
3269 | double[] point = GetSegmentPoint(upStreamObj, downStreamObj, targetLMConnector, out location); |
||
3270 | 02a45794 | gaqhf | Array array = null; |
3271 | if (point != null) |
||
3272 | array = new double[] { 0, point[0], point[1] }; |
||
3273 | else |
||
3274 | array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y }; |
||
3275 | LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
||
3276 | 53c81765 | gaqhf | |
3277 | 16584d30 | gaqhf | if (_LmLabelPersist != null) |
3278 | { |
||
3279 | 04fcadf1 | gaqhf | _LmLabelPersist.Commit(); |
3280 | 5173ba5d | gaqhf | specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id; |
3281 | d23fe61b | gaqhf | if (_LmLabelPersist.ModelItemObject != null) |
3282 | specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID; |
||
3283 | 32205389 | gaqhf | specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString(); |
3284 | 69222bff | gaqhf | |
3285 | MoveDependencyObject(specBreak.SPPID.GraphicOID, location); |
||
3286 | |||
3287 | 16584d30 | gaqhf | ReleaseCOMObjects(_LmLabelPersist); |
3288 | } |
||
3289 | } |
||
3290 | } |
||
3291 | d932245d | gaqhf | |
3292 | Property property = specBreak.PROPERTIES.Find(loop => loop.ATTRIBUTE == "Show"); |
||
3293 | if (property != null && !string.IsNullOrEmpty(property.VALUE) && property.VALUE.Equals("True")) |
||
3294 | { |
||
3295 | // temp |
||
3296 | ReleaseCOMObjects(_placement.PIDPlaceSymbol(@"\Design\Annotation\Graphics\Break.sym", specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y, Rotation: specBreak.ANGLE)); |
||
3297 | } |
||
3298 | 1ab9a205 | gaqhf | ReleaseCOMObjects(targetLMConnector); |
3299 | } |
||
3300 | f9eba687 | gaqhf | else |
3301 | { |
||
3302 | Log.Write("Spec Break UID : " + specBreak.UID); |
||
3303 | Log.Write("Can't find targetLMConnector"); |
||
3304 | } |
||
3305 | 1ab9a205 | gaqhf | } |
3306 | } |
||
3307 | 53c81765 | gaqhf | |
3308 | 1ab9a205 | gaqhf | private LMConnector FindBreakLineTarget(object targetObj, object connectedObj) |
3309 | { |
||
3310 | LMConnector targetConnector = null; |
||
3311 | Symbol targetSymbol = targetObj as Symbol; |
||
3312 | Symbol connectedSymbol = connectedObj as Symbol; |
||
3313 | Line targetLine = targetObj as Line; |
||
3314 | Line connectedLine = connectedObj as Line; |
||
3315 | if (targetSymbol != null && connectedSymbol != null) |
||
3316 | { |
||
3317 | LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
||
3318 | LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId); |
||
3319 | |||
3320 | foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors) |
||
3321 | { |
||
3322 | if (connector.get_ItemStatus() != "Active") |
||
3323 | continue; |
||
3324 | |||
3325 | if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id) |
||
3326 | { |
||
3327 | targetConnector = connector; |
||
3328 | break; |
||
3329 | } |
||
3330 | else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id) |
||
3331 | { |
||
3332 | targetConnector = connector; |
||
3333 | break; |
||
3334 | 53c81765 | gaqhf | } |
3335 | } |
||
3336 | 1ab9a205 | gaqhf | |
3337 | foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors) |
||
3338 | 53c81765 | gaqhf | { |
3339 | 1ab9a205 | gaqhf | if (connector.get_ItemStatus() != "Active") |
3340 | continue; |
||
3341 | 53c81765 | gaqhf | |
3342 | 1ab9a205 | gaqhf | if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id) |
3343 | { |
||
3344 | targetConnector = connector; |
||
3345 | break; |
||
3346 | } |
||
3347 | else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id) |
||
3348 | { |
||
3349 | targetConnector = connector; |
||
3350 | break; |
||
3351 | 53c81765 | gaqhf | } |
3352 | } |
||
3353 | 1ab9a205 | gaqhf | |
3354 | ReleaseCOMObjects(targetLMSymbol); |
||
3355 | ReleaseCOMObjects(connectedLMSymbol); |
||
3356 | } |
||
3357 | else if (targetLine != null && connectedLine != null) |
||
3358 | { |
||
3359 | LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId); |
||
3360 | LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId); |
||
3361 | |||
3362 | d77973b3 | gaqhf | if (targetModelItem != null && targetModelItem.get_ItemStatus() == "Active" && connectedModelItem != null && connectedModelItem.get_ItemStatus() == "Active") |
3363 | 53c81765 | gaqhf | { |
3364 | 1ab9a205 | gaqhf | foreach (LMRepresentation rep in targetModelItem.Representations) |
3365 | 53c81765 | gaqhf | { |
3366 | 1ab9a205 | gaqhf | if (targetConnector != null) |
3367 | break; |
||
3368 | 53c81765 | gaqhf | |
3369 | 1ab9a205 | gaqhf | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
3370 | 53c81765 | gaqhf | { |
3371 | 1ab9a205 | gaqhf | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
3372 | |||
3373 | if (IsConnected(_LMConnector, connectedModelItem)) |
||
3374 | targetConnector = _LMConnector; |
||
3375 | else |
||
3376 | ReleaseCOMObjects(_LMConnector); |
||
3377 | 53c81765 | gaqhf | } |
3378 | } |
||
3379 | 1ab9a205 | gaqhf | |
3380 | ReleaseCOMObjects(targetModelItem); |
||
3381 | 53c81765 | gaqhf | } |
3382 | 1ab9a205 | gaqhf | } |
3383 | else |
||
3384 | { |
||
3385 | 340515a2 | gaqhf | LMSymbol connectedLMSymbol = null; |
3386 | if (connectedSymbol != null) |
||
3387 | connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId); |
||
3388 | else if (targetSymbol != null) |
||
3389 | connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
||
3390 | else |
||
3391 | { |
||
3392 | |||
3393 | } |
||
3394 | LMModelItem targetModelItem = null; |
||
3395 | if (targetLine != null) |
||
3396 | targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId); |
||
3397 | else if (connectedLine != null) |
||
3398 | targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId); |
||
3399 | else |
||
3400 | { |
||
3401 | |||
3402 | } |
||
3403 | 1ab9a205 | gaqhf | if (connectedLMSymbol != null && targetModelItem != null) |
3404 | 53c81765 | gaqhf | { |
3405 | 1ab9a205 | gaqhf | foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors) |
3406 | { |
||
3407 | ac82b020 | gaqhf | if (connector.get_ItemStatus() != "Active") |
3408 | continue; |
||
3409 | |||
3410 | 1ab9a205 | gaqhf | if (IsConnected(connector, targetModelItem)) |
3411 | { |
||
3412 | targetConnector = connector; |
||
3413 | break; |
||
3414 | } |
||
3415 | } |
||
3416 | 53c81765 | gaqhf | |
3417 | 1ab9a205 | gaqhf | if (targetConnector == null) |
3418 | 53c81765 | gaqhf | { |
3419 | 1ab9a205 | gaqhf | foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors) |
3420 | 53c81765 | gaqhf | { |
3421 | ac82b020 | gaqhf | if (connector.get_ItemStatus() != "Active") |
3422 | continue; |
||
3423 | |||
3424 | 1ab9a205 | gaqhf | if (IsConnected(connector, targetModelItem)) |
3425 | 53c81765 | gaqhf | { |
3426 | 1ab9a205 | gaqhf | targetConnector = connector; |
3427 | break; |
||
3428 | 53c81765 | gaqhf | } |
3429 | } |
||
3430 | } |
||
3431 | } |
||
3432 | |||
3433 | 1ab9a205 | gaqhf | } |
3434 | 02480ac1 | gaqhf | |
3435 | 1ab9a205 | gaqhf | return targetConnector; |
3436 | } |
||
3437 | 53c81765 | gaqhf | |
3438 | 69222bff | gaqhf | private double[] GetSegmentPoint(object targetObj, object connObj, LMConnector targetConnector, out SegmentLocation location) |
3439 | 02a45794 | gaqhf | { |
3440 | double[] result = null; |
||
3441 | 28d05cc2 | gaqhf | Line targetLine = targetObj as Line; |
3442 | Symbol targetSymbol = targetObj as Symbol; |
||
3443 | Line connLine = connObj as Line; |
||
3444 | Symbol connSymbol = connObj as Symbol; |
||
3445 | 69222bff | gaqhf | location = SegmentLocation.None; |
3446 | 02a45794 | gaqhf | if (Convert.ToBoolean(targetConnector.get_IsZeroLength())) |
3447 | { |
||
3448 | 28d05cc2 | gaqhf | result = GetConnectorVertices(targetConnector)[0]; |
3449 | if (targetSymbol != null && connSymbol != null) |
||
3450 | { |
||
3451 | SlopeType slopeType = SPPIDUtil.CalcSlope(targetSymbol.SPPID.SPPID_X, targetSymbol.SPPID.SPPID_Y, connSymbol.SPPID.SPPID_X, connSymbol.SPPID.SPPID_Y); |
||
3452 | 69222bff | gaqhf | result = new double[] { result[0], result[1] }; |
3453 | 28d05cc2 | gaqhf | if (slopeType == SlopeType.HORIZONTAL) |
3454 | 69222bff | gaqhf | location = SegmentLocation.Up; |
3455 | 28d05cc2 | gaqhf | else if (slopeType == SlopeType.VERTICAL) |
3456 | 69222bff | gaqhf | location = SegmentLocation.Right; |
3457 | 28d05cc2 | gaqhf | } |
3458 | else if (targetLine != null) |
||
3459 | { |
||
3460 | 69222bff | gaqhf | result = new double[] { result[0], result[1] }; |
3461 | 28d05cc2 | gaqhf | if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
3462 | 69222bff | gaqhf | location = SegmentLocation.Up; |
3463 | 28d05cc2 | gaqhf | else if (targetLine.SlopeType == SlopeType.VERTICAL) |
3464 | 69222bff | gaqhf | location = SegmentLocation.Right; |
3465 | 28d05cc2 | gaqhf | } |
3466 | else if (connLine != null) |
||
3467 | { |
||
3468 | 69222bff | gaqhf | result = new double[] { result[0], result[1] }; |
3469 | 28d05cc2 | gaqhf | if (connLine.SlopeType == SlopeType.HORIZONTAL) |
3470 | 69222bff | gaqhf | location = SegmentLocation.Up; |
3471 | 28d05cc2 | gaqhf | else if (connLine.SlopeType == SlopeType.VERTICAL) |
3472 | 69222bff | gaqhf | location = SegmentLocation.Right; |
3473 | 28d05cc2 | gaqhf | } |
3474 | 02a45794 | gaqhf | } |
3475 | else |
||
3476 | { |
||
3477 | if (targetObj.GetType() == typeof(Line) && connObj.GetType() == typeof(Line)) |
||
3478 | { |
||
3479 | Line line = connObj as Line; |
||
3480 | LMConnector connectedConnector = null; |
||
3481 | int connIndex = 0; |
||
3482 | LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
||
3483 | FindConnectedConnector(targetConnector, modelItem, ref connectedConnector, ref connIndex); |
||
3484 | |||
3485 | List<double[]> vertices = GetConnectorVertices(targetConnector); |
||
3486 | |||
3487 | ReleaseCOMObjects(modelItem); |
||
3488 | ReleaseCOMObjects(connectedConnector); |
||
3489 | |||
3490 | if (vertices.Count > 0) |
||
3491 | { |
||
3492 | if (connIndex == 1) |
||
3493 | 28d05cc2 | gaqhf | result = vertices[0]; |
3494 | 02a45794 | gaqhf | else if (connIndex == 2) |
3495 | 28d05cc2 | gaqhf | result = vertices[vertices.Count - 1]; |
3496 | |||
3497 | if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
||
3498 | { |
||
3499 | 69222bff | gaqhf | result = new double[] { result[0], result[1] }; |
3500 | location = SegmentLocation.Up; |
||
3501 | 28d05cc2 | gaqhf | if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X) |
3502 | 69222bff | gaqhf | location = location | SegmentLocation.Right; |
3503 | 28d05cc2 | gaqhf | else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X) |
3504 | 69222bff | gaqhf | location = location | SegmentLocation.Left; |
3505 | 28d05cc2 | gaqhf | else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X) |
3506 | 69222bff | gaqhf | location = location | SegmentLocation.Left; |
3507 | 28d05cc2 | gaqhf | else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X) |
3508 | 69222bff | gaqhf | location = location | SegmentLocation.Right; |
3509 | 28d05cc2 | gaqhf | } |
3510 | else if (targetLine.SlopeType == SlopeType.VERTICAL) |
||
3511 | { |
||
3512 | 69222bff | gaqhf | result = new double[] { result[0], result[1] }; |
3513 | location = SegmentLocation.Right; |
||
3514 | 28d05cc2 | gaqhf | if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y) |
3515 | 69222bff | gaqhf | location = location | SegmentLocation.Up; |
3516 | 28d05cc2 | gaqhf | else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y) |
3517 | 69222bff | gaqhf | location = location | SegmentLocation.Down; |
3518 | 28d05cc2 | gaqhf | else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y) |
3519 | 69222bff | gaqhf | location = location | SegmentLocation.Down; |
3520 | 28d05cc2 | gaqhf | else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y) |
3521 | 69222bff | gaqhf | location = location | SegmentLocation.Up; |
3522 | 28d05cc2 | gaqhf | } |
3523 | 2e69e97c | gaqhf | |
3524 | 02a45794 | gaqhf | } |
3525 | } |
||
3526 | else |
||
3527 | { |
||
3528 | Log.Write("error in GetSegemtPoint"); |
||
3529 | } |
||
3530 | } |
||
3531 | |||
3532 | return result; |
||
3533 | } |
||
3534 | |||
3535 | 1ab9a205 | gaqhf | private bool IsConnected(LMConnector connector, LMModelItem modelItem) |
3536 | { |
||
3537 | bool result = false; |
||
3538 | |||
3539 | foreach (LMRepresentation rep in modelItem.Representations) |
||
3540 | { |
||
3541 | if (result) |
||
3542 | break; |
||
3543 | |||
3544 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
3545 | { |
||
3546 | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
||
3547 | |||
3548 | if (_LMConnector.ConnectItem1SymbolObject != null && |
||
3549 | connector.ConnectItem1SymbolObject != null && |
||
3550 | _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
||
3551 | 53c81765 | gaqhf | { |
3552 | 1ab9a205 | gaqhf | result = true; |
3553 | ReleaseCOMObjects(_LMConnector); |
||
3554 | break; |
||
3555 | } |
||
3556 | else if (_LMConnector.ConnectItem1SymbolObject != null && |
||
3557 | connector.ConnectItem2SymbolObject != null && |
||
3558 | _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
||
3559 | { |
||
3560 | result = true; |
||
3561 | ReleaseCOMObjects(_LMConnector); |
||
3562 | break; |
||
3563 | } |
||
3564 | else if (_LMConnector.ConnectItem2SymbolObject != null && |
||
3565 | connector.ConnectItem1SymbolObject != null && |
||
3566 | _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
||
3567 | { |
||
3568 | result = true; |
||
3569 | ReleaseCOMObjects(_LMConnector); |
||
3570 | break; |
||
3571 | } |
||
3572 | else if (_LMConnector.ConnectItem2SymbolObject != null && |
||
3573 | connector.ConnectItem2SymbolObject != null && |
||
3574 | _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
||
3575 | { |
||
3576 | result = true; |
||
3577 | ReleaseCOMObjects(_LMConnector); |
||
3578 | break; |
||
3579 | 53c81765 | gaqhf | } |
3580 | |||
3581 | 1ab9a205 | gaqhf | ReleaseCOMObjects(_LMConnector); |
3582 | } |
||
3583 | 53c81765 | gaqhf | } |
3584 | 1ab9a205 | gaqhf | |
3585 | |||
3586 | return result; |
||
3587 | 53c81765 | gaqhf | } |
3588 | |||
3589 | 02a45794 | gaqhf | private void FindConnectedConnector(LMConnector connector, LMModelItem modelItem, ref LMConnector connectedConnector, ref int connectorIndex) |
3590 | { |
||
3591 | foreach (LMRepresentation rep in modelItem.Representations) |
||
3592 | { |
||
3593 | if (connectedConnector != null) |
||
3594 | break; |
||
3595 | |||
3596 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
3597 | { |
||
3598 | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
||
3599 | |||
3600 | if (_LMConnector.ConnectItem1SymbolObject != null && |
||
3601 | connector.ConnectItem1SymbolObject != null && |
||
3602 | _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
||
3603 | { |
||
3604 | connectedConnector = _LMConnector; |
||
3605 | connectorIndex = 1; |
||
3606 | break; |
||
3607 | } |
||
3608 | else if (_LMConnector.ConnectItem1SymbolObject != null && |
||
3609 | connector.ConnectItem2SymbolObject != null && |
||
3610 | _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
||
3611 | { |
||
3612 | connectedConnector = _LMConnector; |
||
3613 | connectorIndex = 2; |
||
3614 | break; |
||
3615 | } |
||
3616 | else if (_LMConnector.ConnectItem2SymbolObject != null && |
||
3617 | connector.ConnectItem1SymbolObject != null && |
||
3618 | _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
||
3619 | { |
||
3620 | connectedConnector = _LMConnector; |
||
3621 | connectorIndex = 1; |
||
3622 | break; |
||
3623 | } |
||
3624 | else if (_LMConnector.ConnectItem2SymbolObject != null && |
||
3625 | connector.ConnectItem2SymbolObject != null && |
||
3626 | _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
||
3627 | { |
||
3628 | connectedConnector = _LMConnector; |
||
3629 | connectorIndex = 2; |
||
3630 | break; |
||
3631 | } |
||
3632 | |||
3633 | if (connectedConnector == null) |
||
3634 | ReleaseCOMObjects(_LMConnector); |
||
3635 | } |
||
3636 | } |
||
3637 | } |
||
3638 | |||
3639 | 53c81765 | gaqhf | /// <summary> |
3640 | 74752074 | gaqhf | /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드 |
3641 | /// </summary> |
||
3642 | 644f40b3 | gaqhf | /// <param name="modelItemID1"></param> |
3643 | /// <param name="modelItemID2"></param> |
||
3644 | 90662b0b | gaqhf | private void JoinRun(string modelId1, string modelId2, ref string survivorId, bool IsSameConnector = true) |
3645 | 335b7a24 | gaqhf | { |
3646 | ca6e0f51 | gaqhf | try |
3647 | 644f40b3 | gaqhf | { |
3648 | a31a512e | gaqhf | LMModelItem modelItem1 = dataSource.GetModelItem(modelId1); |
3649 | 63a112d9 | gaqhf | LMConnector connector1 = GetLMConnectorFirst(modelId1); |
3650 | List<double[]> vertices1 = null; |
||
3651 | string graphicOID1 = string.Empty; |
||
3652 | if (connector1 != null) |
||
3653 | { |
||
3654 | vertices1 = GetConnectorVertices(connector1); |
||
3655 | graphicOID1 = connector1.get_GraphicOID(); |
||
3656 | } |
||
3657 | ca6e0f51 | gaqhf | _LMAItem item1 = modelItem1.AsLMAItem(); |
3658 | 63a112d9 | gaqhf | ReleaseCOMObjects(connector1); |
3659 | connector1 = null; |
||
3660 | |||
3661 | a31a512e | gaqhf | LMModelItem modelItem2 = dataSource.GetModelItem(modelId2); |
3662 | 63a112d9 | gaqhf | LMConnector connector2 = GetLMConnectorFirst(modelId2); |
3663 | List<double[]> vertices2 = null; |
||
3664 | string graphicOID2 = string.Empty; |
||
3665 | if (connector2 != null) |
||
3666 | { |
||
3667 | vertices2 = GetConnectorVertices(connector2); |
||
3668 | graphicOID2 = connector2.get_GraphicOID(); |
||
3669 | } |
||
3670 | ca6e0f51 | gaqhf | _LMAItem item2 = modelItem2.AsLMAItem(); |
3671 | 63a112d9 | gaqhf | ReleaseCOMObjects(connector2); |
3672 | connector2 = null; |
||
3673 | 644f40b3 | gaqhf | |
3674 | ca6e0f51 | gaqhf | // item2가 item1으로 조인 |
3675 | _placement.PIDJoinRuns(ref item1, ref item2); |
||
3676 | item1.Commit(); |
||
3677 | item2.Commit(); |
||
3678 | 7f00b26c | gaqhf | |
3679 | ca6e0f51 | gaqhf | string beforeID = string.Empty; |
3680 | string afterID = string.Empty; |
||
3681 | 335b7a24 | gaqhf | |
3682 | ca6e0f51 | gaqhf | if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active") |
3683 | { |
||
3684 | beforeID = modelItem2.Id; |
||
3685 | afterID = modelItem1.Id; |
||
3686 | a31a512e | gaqhf | survivorId = afterID; |
3687 | ca6e0f51 | gaqhf | } |
3688 | else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active") |
||
3689 | { |
||
3690 | beforeID = modelItem1.Id; |
||
3691 | afterID = modelItem2.Id; |
||
3692 | a31a512e | gaqhf | survivorId = afterID; |
3693 | ca6e0f51 | gaqhf | } |
3694 | a31a512e | gaqhf | else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active") |
3695 | 7e680366 | gaqhf | { |
3696 | int model1Cnt = GetConnectorCount(modelId1); |
||
3697 | int model2Cnt = GetConnectorCount(modelId2); |
||
3698 | if (model1Cnt == 0) |
||
3699 | { |
||
3700 | beforeID = modelItem1.Id; |
||
3701 | afterID = modelItem2.Id; |
||
3702 | survivorId = afterID; |
||
3703 | } |
||
3704 | else if (model2Cnt == 0) |
||
3705 | { |
||
3706 | beforeID = modelItem2.Id; |
||
3707 | afterID = modelItem1.Id; |
||
3708 | survivorId = afterID; |
||
3709 | } |
||
3710 | else |
||
3711 | survivorId = null; |
||
3712 | } |
||
3713 | ca6e0f51 | gaqhf | else |
3714 | { |
||
3715 | a31a512e | gaqhf | Log.Write("잘못된 경우"); |
3716 | survivorId = null; |
||
3717 | ca6e0f51 | gaqhf | } |
3718 | 87f02fc0 | gaqhf | |
3719 | ca6e0f51 | gaqhf | if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID)) |
3720 | 7f00b26c | gaqhf | { |
3721 | ca6e0f51 | gaqhf | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID); |
3722 | 7f00b26c | gaqhf | foreach (var line in lines) |
3723 | ca6e0f51 | gaqhf | line.SPPID.ModelItemId = afterID; |
3724 | 65a1ed4b | gaqhf | } |
3725 | 7f00b26c | gaqhf | |
3726 | ca6e0f51 | gaqhf | ReleaseCOMObjects(modelItem1); |
3727 | ReleaseCOMObjects(item1); |
||
3728 | ReleaseCOMObjects(modelItem2); |
||
3729 | ReleaseCOMObjects(item2); |
||
3730 | } |
||
3731 | catch (Exception ex) |
||
3732 | 335b7a24 | gaqhf | { |
3733 | ca6e0f51 | gaqhf | Log.Write("Join Error"); |
3734 | 63a112d9 | gaqhf | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
3735 | 335b7a24 | gaqhf | } |
3736 | } |
||
3737 | |||
3738 | 2b8c256c | gaqhf | private bool IsModelingEndBreak(Symbol symbol1, Symbol symbol2) |
3739 | { |
||
3740 | bool result = false; |
||
3741 | List<EndBreak> endBreaks = document.EndBreaks.FindAll(x => |
||
3742 | (x.OWNER == symbol1.UID || x.OWNER == symbol2.UID) && |
||
3743 | (x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID)); |
||
3744 | |||
3745 | foreach (var item in endBreaks) |
||
3746 | { |
||
3747 | if (!string.IsNullOrEmpty(item.SPPID.RepresentationId)) |
||
3748 | { |
||
3749 | result = true; |
||
3750 | break; |
||
3751 | } |
||
3752 | } |
||
3753 | |||
3754 | return result; |
||
3755 | } |
||
3756 | a31a512e | gaqhf | private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId) |
3757 | { |
||
3758 | fae4f386 | gaqhf | List<string> temp = new List<string>(); |
3759 | List<LMConnector> connectors = new List<LMConnector>(); |
||
3760 | 48fd75e2 | gaqhf | foreach (LMConnector connector in symbol.Avoid1Connectors) |
3761 | a31a512e | gaqhf | { |
3762 | fae4f386 | gaqhf | if (connector.get_ItemStatus() != "Active") |
3763 | continue; |
||
3764 | |||
3765 | a31a512e | gaqhf | LMModelItem modelItem = connector.ModelItemObject; |
3766 | fae4f386 | gaqhf | LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector); |
3767 | if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id)) |
||
3768 | temp.Add(modelItem.Id); |
||
3769 | |||
3770 | if (temp.Contains(modelItem.Id) && |
||
3771 | connOtherSymbol != null && |
||
3772 | connOtherSymbol.get_RepresentationType() == "Branch" && |
||
3773 | Convert.ToBoolean(connector.get_IsZeroLength())) |
||
3774 | temp.Remove(modelItem.Id); |
||
3775 | |||
3776 | |||
3777 | if (temp.Contains(modelItem.Id)) |
||
3778 | connectors.Add(connector); |
||
3779 | ReleaseCOMObjects(connOtherSymbol); |
||
3780 | connOtherSymbol = null; |
||
3781 | a31a512e | gaqhf | ReleaseCOMObjects(modelItem); |
3782 | fae4f386 | gaqhf | modelItem = null; |
3783 | a31a512e | gaqhf | } |
3784 | |||
3785 | 48fd75e2 | gaqhf | foreach (LMConnector connector in symbol.Avoid2Connectors) |
3786 | a31a512e | gaqhf | { |
3787 | fae4f386 | gaqhf | if (connector.get_ItemStatus() != "Active") |
3788 | continue; |
||
3789 | |||
3790 | a31a512e | gaqhf | LMModelItem modelItem = connector.ModelItemObject; |
3791 | fae4f386 | gaqhf | LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector); |
3792 | if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id)) |
||
3793 | temp.Add(modelItem.Id); |
||
3794 | |||
3795 | if (temp.Contains(modelItem.Id) && |
||
3796 | connOtherSymbol != null && |
||
3797 | connOtherSymbol.get_RepresentationType() == "Branch" && |
||
3798 | Convert.ToBoolean(connector.get_IsZeroLength())) |
||
3799 | temp.Remove(modelItem.Id); |
||
3800 | |||
3801 | if (temp.Contains(modelItem.Id)) |
||
3802 | connectors.Add(connector); |
||
3803 | ReleaseCOMObjects(connOtherSymbol); |
||
3804 | connOtherSymbol = null; |
||
3805 | a31a512e | gaqhf | ReleaseCOMObjects(modelItem); |
3806 | fae4f386 | gaqhf | modelItem = null; |
3807 | a31a512e | gaqhf | } |
3808 | |||
3809 | 48fd75e2 | gaqhf | |
3810 | 82d6e5ea | gaqhf | List<string> result = new List<string>(); |
3811 | string originalName = GetSPPIDFileName(modelId); |
||
3812 | fae4f386 | gaqhf | foreach (var connector in connectors) |
3813 | 82d6e5ea | gaqhf | { |
3814 | fae4f386 | gaqhf | string fileName = GetSPPIDFileName(connector.ModelItemID); |
3815 | 82d6e5ea | gaqhf | if (originalName == fileName) |
3816 | fae4f386 | gaqhf | result.Add(connector.ModelItemID); |
3817 | 82d6e5ea | gaqhf | else |
3818 | { |
||
3819 | fae4f386 | gaqhf | if (document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID) == null && Convert.ToBoolean(connector.get_IsZeroLength())) |
3820 | result.Add(connector.ModelItemID); |
||
3821 | else |
||
3822 | 82d6e5ea | gaqhf | { |
3823 | fae4f386 | gaqhf | Line line1 = document.LINES.Find(x => x.SPPID.ModelItemId == modelId); |
3824 | Line line2 = document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID.ToString()); |
||
3825 | if (line1 != null && line2 != null && line1.TYPE == line2.TYPE) |
||
3826 | result.Add(connector.ModelItemID); |
||
3827 | 82d6e5ea | gaqhf | } |
3828 | } |
||
3829 | } |
||
3830 | 154d8f43 | gaqhf | |
3831 | fae4f386 | gaqhf | foreach (var connector in connectors) |
3832 | 154d8f43 | gaqhf | ReleaseCOMObjects(connector); |
3833 | 2e69e97c | gaqhf | |
3834 | 82d6e5ea | gaqhf | return result; |
3835 | fae4f386 | gaqhf | |
3836 | |||
3837 | LMSymbol FindOtherConnectedSymbol(LMConnector connector) |
||
3838 | { |
||
3839 | LMSymbol findResult = null; |
||
3840 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.Id != symbol.Id && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
||
3841 | findResult = connector.ConnectItem1SymbolObject; |
||
3842 | else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.Id != symbol.Id && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
||
3843 | findResult = connector.ConnectItem2SymbolObject; |
||
3844 | |||
3845 | return findResult; |
||
3846 | } |
||
3847 | a31a512e | gaqhf | } |
3848 | |||
3849 | 74752074 | gaqhf | /// <summary> |
3850 | /// PipeRun의 좌표를 가져오는 메서드 |
||
3851 | /// </summary> |
||
3852 | /// <param name="modelId"></param> |
||
3853 | /// <returns></returns> |
||
3854 | 44087b23 | gaqhf | private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId, bool ContainZeroLength = true) |
3855 | 5e6ecf05 | gaqhf | { |
3856 | Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
||
3857 | 310aeb31 | gaqhf | LMModelItem modelItem = dataSource.GetModelItem(modelId); |
3858 | |||
3859 | if (modelItem != null) |
||
3860 | 5e6ecf05 | gaqhf | { |
3861 | 310aeb31 | gaqhf | foreach (LMRepresentation rep in modelItem.Representations) |
3862 | 5e6ecf05 | gaqhf | { |
3863 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
3864 | { |
||
3865 | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
||
3866 | 44087b23 | gaqhf | if (!ContainZeroLength && Convert.ToBoolean(_LMConnector.get_IsZeroLength())) |
3867 | { |
||
3868 | ReleaseCOMObjects(_LMConnector); |
||
3869 | _LMConnector = null; |
||
3870 | continue; |
||
3871 | } |
||
3872 | 5e6ecf05 | gaqhf | connectorVertices.Add(_LMConnector, new List<double[]>()); |
3873 | 32205389 | gaqhf | dynamic OID = rep.get_GraphicOID().ToString(); |
3874 | 335b7a24 | gaqhf | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
3875 | 5e6ecf05 | gaqhf | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
3876 | int verticesCount = lineStringGeometry.VertexCount; |
||
3877 | double[] vertices = null; |
||
3878 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
3879 | for (int i = 0; i < verticesCount; i++) |
||
3880 | { |
||
3881 | double x = 0; |
||
3882 | double y = 0; |
||
3883 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
3884 | 32205389 | gaqhf | connectorVertices[_LMConnector].Add(new double[] { x, y }); |
3885 | 5e6ecf05 | gaqhf | } |
3886 | } |
||
3887 | } |
||
3888 | |||
3889 | 310aeb31 | gaqhf | ReleaseCOMObjects(modelItem); |
3890 | 5e6ecf05 | gaqhf | } |
3891 | |||
3892 | return connectorVertices; |
||
3893 | } |
||
3894 | |||
3895 | 32205389 | gaqhf | private List<double[]> GetConnectorVertices(LMConnector connector) |
3896 | { |
||
3897 | List<double[]> vertices = new List<double[]>(); |
||
3898 | 02a45794 | gaqhf | if (connector != null) |
3899 | 32205389 | gaqhf | { |
3900 | 02a45794 | gaqhf | dynamic OID = connector.get_GraphicOID().ToString(); |
3901 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
3902 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
3903 | int verticesCount = lineStringGeometry.VertexCount; |
||
3904 | double[] value = null; |
||
3905 | lineStringGeometry.GetVertices(ref verticesCount, ref value); |
||
3906 | for (int i = 0; i < verticesCount; i++) |
||
3907 | { |
||
3908 | double x = 0; |
||
3909 | double y = 0; |
||
3910 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
3911 | vertices.Add(new double[] { x, y }); |
||
3912 | } |
||
3913 | 32205389 | gaqhf | } |
3914 | return vertices; |
||
3915 | } |
||
3916 | |||
3917 | b2064e69 | gaqhf | private double GetConnectorDistance(LMConnector connector) |
3918 | { |
||
3919 | double result = 0; |
||
3920 | List<double[]> vertices = new List<double[]>(); |
||
3921 | if (connector != null) |
||
3922 | { |
||
3923 | dynamic OID = connector.get_GraphicOID().ToString(); |
||
3924 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
3925 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
3926 | int verticesCount = lineStringGeometry.VertexCount; |
||
3927 | double[] value = null; |
||
3928 | lineStringGeometry.GetVertices(ref verticesCount, ref value); |
||
3929 | for (int i = 0; i < verticesCount; i++) |
||
3930 | { |
||
3931 | double x = 0; |
||
3932 | double y = 0; |
||
3933 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
3934 | vertices.Add(new double[] { x, y }); |
||
3935 | if (vertices.Count > 1) |
||
3936 | { |
||
3937 | result += SPPIDUtil.CalcPointToPointdDistance(vertices[vertices.Count - 2][0], vertices[vertices.Count - 2][1], x, y); |
||
3938 | } |
||
3939 | } |
||
3940 | } |
||
3941 | return result; |
||
3942 | } |
||
3943 | f676f99a | gaqhf | private double[] GetConnectorRange(LMConnector connector) |
3944 | { |
||
3945 | double[] result = null; |
||
3946 | List<double[]> vertices = new List<double[]>(); |
||
3947 | if (connector != null) |
||
3948 | { |
||
3949 | dynamic OID = connector.get_GraphicOID().ToString(); |
||
3950 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
3951 | double minX = 0; |
||
3952 | double minY = 0; |
||
3953 | double maxX = 0; |
||
3954 | double maxY = 0; |
||
3955 | |||
3956 | drawingObject.Range(out minX, out minY, out maxX, out maxY); |
||
3957 | result = new double[] { minX, minY, maxX, maxY }; |
||
3958 | } |
||
3959 | return result; |
||
3960 | } |
||
3961 | 63a112d9 | gaqhf | private List<double[]> GetConnectorVertices(dynamic graphicOID) |
3962 | { |
||
3963 | List<double[]> vertices = null; |
||
3964 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID]; |
||
3965 | if (drawingObject != null) |
||
3966 | { |
||
3967 | vertices = new List<double[]>(); |
||
3968 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
3969 | int verticesCount = lineStringGeometry.VertexCount; |
||
3970 | double[] value = null; |
||
3971 | lineStringGeometry.GetVertices(ref verticesCount, ref value); |
||
3972 | for (int i = 0; i < verticesCount; i++) |
||
3973 | { |
||
3974 | double x = 0; |
||
3975 | double y = 0; |
||
3976 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
3977 | vertices.Add(new double[] { x, y }); |
||
3978 | } |
||
3979 | } |
||
3980 | return vertices; |
||
3981 | } |
||
3982 | 7c7bcd10 | gaqhf | /// <summary> |
3983 | a0e3dca4 | gaqhf | /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식 |
3984 | 74752074 | gaqhf | /// </summary> |
3985 | /// <param name="connectorVertices"></param> |
||
3986 | /// <param name="connX"></param> |
||
3987 | /// <param name="connY"></param> |
||
3988 | /// <returns></returns> |
||
3989 | a0e3dca4 | gaqhf | private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
3990 | 5e6ecf05 | gaqhf | { |
3991 | double length = double.MaxValue; |
||
3992 | LMConnector targetConnector = null; |
||
3993 | foreach (var item in connectorVertices) |
||
3994 | { |
||
3995 | List<double[]> points = item.Value; |
||
3996 | for (int i = 0; i < points.Count - 1; i++) |
||
3997 | { |
||
3998 | double[] point1 = points[i]; |
||
3999 | double[] point2 = points[i + 1]; |
||
4000 | a0e3dca4 | gaqhf | double x1 = Math.Min(point1[0], point2[0]); |
4001 | double y1 = Math.Min(point1[1], point2[1]); |
||
4002 | double x2 = Math.Max(point1[0], point2[0]); |
||
4003 | double y2 = Math.Max(point1[1], point2[1]); |
||
4004 | 5e6ecf05 | gaqhf | |
4005 | a0e3dca4 | gaqhf | if ((x1 <= connX && x2 >= connX) || |
4006 | (y1 <= connY && y2 >= connY)) |
||
4007 | 5e6ecf05 | gaqhf | { |
4008 | a0e3dca4 | gaqhf | double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
4009 | 335b7a24 | gaqhf | if (length >= distance) |
4010 | 30a9ffce | gaqhf | { |
4011 | a0e3dca4 | gaqhf | targetConnector = item.Key; |
4012 | length = distance; |
||
4013 | } |
||
4014 | |||
4015 | distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
||
4016 | if (length >= distance) |
||
4017 | { |
||
4018 | targetConnector = item.Key; |
||
4019 | length = distance; |
||
4020 | 30a9ffce | gaqhf | } |
4021 | 5e6ecf05 | gaqhf | } |
4022 | } |
||
4023 | c3d2e266 | gaqhf | } |
4024 | |||
4025 | a0e3dca4 | gaqhf | // 못찾았을때. |
4026 | length = double.MaxValue; |
||
4027 | c3d2e266 | gaqhf | if (targetConnector == null) |
4028 | { |
||
4029 | foreach (var item in connectorVertices) |
||
4030 | { |
||
4031 | List<double[]> points = item.Value; |
||
4032 | a0e3dca4 | gaqhf | |
4033 | foreach (double[] point in points) |
||
4034 | c3d2e266 | gaqhf | { |
4035 | a0e3dca4 | gaqhf | double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
4036 | c3d2e266 | gaqhf | if (length >= distance) |
4037 | { |
||
4038 | targetConnector = item.Key; |
||
4039 | length = distance; |
||
4040 | } |
||
4041 | } |
||
4042 | } |
||
4043 | 5e6ecf05 | gaqhf | } |
4044 | |||
4045 | return targetConnector; |
||
4046 | } |
||
4047 | |||
4048 | a0e3dca4 | gaqhf | private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y) |
4049 | ac78b508 | gaqhf | { |
4050 | a0e3dca4 | gaqhf | Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId); |
4051 | 0ff6e67f | gaqhf | if (vertices.Count == 0) |
4052 | return null; |
||
4053 | a0e3dca4 | gaqhf | |
4054 | ac78b508 | gaqhf | double length = double.MaxValue; |
4055 | LMConnector targetConnector = null; |
||
4056 | a0e3dca4 | gaqhf | double[] resultPoint = null; |
4057 | List<double[]> targetVertices = null; |
||
4058 | |||
4059 | // Vertices 포인트에 제일 가까운곳 |
||
4060 | foreach (var item in vertices) |
||
4061 | ac78b508 | gaqhf | { |
4062 | List<double[]> points = item.Value; |
||
4063 | a0e3dca4 | gaqhf | for (int i = 0; i < points.Count; i++) |
4064 | ac78b508 | gaqhf | { |
4065 | a0e3dca4 | gaqhf | double[] point = points[i]; |
4066 | double tempX = point[0]; |
||
4067 | double tempY = point[1]; |
||
4068 | |||
4069 | double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y); |
||
4070 | ac78b508 | gaqhf | if (length >= distance) |
4071 | { |
||
4072 | targetConnector = item.Key; |
||
4073 | length = distance; |
||
4074 | a0e3dca4 | gaqhf | resultPoint = point; |
4075 | targetVertices = item.Value; |
||
4076 | ac78b508 | gaqhf | } |
4077 | } |
||
4078 | } |
||
4079 | |||
4080 | a0e3dca4 | gaqhf | // Vertices Cross에 제일 가까운곳 |
4081 | foreach (var item in vertices) |
||
4082 | 68464385 | gaqhf | { |
4083 | List<double[]> points = item.Value; |
||
4084 | for (int i = 0; i < points.Count - 1; i++) |
||
4085 | { |
||
4086 | double[] point1 = points[i]; |
||
4087 | double[] point2 = points[i + 1]; |
||
4088 | |||
4089 | a0e3dca4 | gaqhf | double maxLineX = Math.Max(point1[0], point2[0]); |
4090 | double minLineX = Math.Min(point1[0], point2[0]); |
||
4091 | double maxLineY = Math.Max(point1[1], point2[1]); |
||
4092 | double minLineY = Math.Min(point1[1], point2[1]); |
||
4093 | 68464385 | gaqhf | |
4094 | a0e3dca4 | gaqhf | SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
4095 | |||
4096 | double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y, point1[0], point1[1], point2[0], point2[1]); |
||
4097 | if (crossingPoint != null) |
||
4098 | { |
||
4099 | double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y); |
||
4100 | 68464385 | gaqhf | if (length >= distance) |
4101 | { |
||
4102 | a0e3dca4 | gaqhf | if (slope == SlopeType.Slope && |
4103 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
||
4104 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
4105 | { |
||
4106 | targetConnector = item.Key; |
||
4107 | length = distance; |
||
4108 | resultPoint = crossingPoint; |
||
4109 | targetVertices = item.Value; |
||
4110 | } |
||
4111 | else if (slope == SlopeType.HORIZONTAL && |
||
4112 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
||
4113 | { |
||
4114 | targetConnector = item.Key; |
||
4115 | length = distance; |
||
4116 | resultPoint = crossingPoint; |
||
4117 | targetVertices = item.Value; |
||
4118 | } |
||
4119 | else if (slope == SlopeType.VERTICAL && |
||
4120 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
4121 | { |
||
4122 | targetConnector = item.Key; |
||
4123 | length = distance; |
||
4124 | resultPoint = crossingPoint; |
||
4125 | targetVertices = item.Value; |
||
4126 | } |
||
4127 | 68464385 | gaqhf | } |
4128 | } |
||
4129 | } |
||
4130 | } |
||
4131 | |||
4132 | a0e3dca4 | gaqhf | foreach (var item in vertices) |
4133 | if (item.Key != null && item.Key != targetConnector) |
||
4134 | ReleaseCOMObjects(item.Key); |
||
4135 | |||
4136 | if (SPPIDUtil.IsBranchLine(line, targetLine)) |
||
4137 | 68464385 | gaqhf | { |
4138 | a0e3dca4 | gaqhf | double tempResultX = resultPoint[0]; |
4139 | double tempResultY = resultPoint[1]; |
||
4140 | SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY); |
||
4141 | 68464385 | gaqhf | |
4142 | a0e3dca4 | gaqhf | GridSetting gridSetting = GridSetting.GetInstance(); |
4143 | |||
4144 | for (int i = 0; i < targetVertices.Count; i++) |
||
4145 | { |
||
4146 | double[] point = targetVertices[i]; |
||
4147 | double tempX = targetVertices[i][0]; |
||
4148 | double tempY = targetVertices[i][1]; |
||
4149 | SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY); |
||
4150 | if (tempX == tempResultX && tempY == tempResultY) |
||
4151 | 68464385 | gaqhf | { |
4152 | a0e3dca4 | gaqhf | if (i == 0) |
4153 | 68464385 | gaqhf | { |
4154 | a0e3dca4 | gaqhf | LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject; |
4155 | b01e7456 | gaqhf | bool containZeroLength = false; |
4156 | if (connSymbol != null) |
||
4157 | a0e3dca4 | gaqhf | { |
4158 | 1805d3b7 | gaqhf | foreach (LMConnector connector in connSymbol.Connect1Connectors) |
4159 | { |
||
4160 | b01e7456 | gaqhf | if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4161 | 1805d3b7 | gaqhf | containZeroLength = true; |
4162 | } |
||
4163 | foreach (LMConnector connector in connSymbol.Connect2Connectors) |
||
4164 | a0e3dca4 | gaqhf | { |
4165 | b01e7456 | gaqhf | if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4166 | 1805d3b7 | gaqhf | containZeroLength = true; |
4167 | a0e3dca4 | gaqhf | } |
4168 | b01e7456 | gaqhf | } |
4169 | |||
4170 | if (connSymbol == null || |
||
4171 | (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") || |
||
4172 | containZeroLength) |
||
4173 | { |
||
4174 | bool bCalcX = false; |
||
4175 | bool bCalcY = false; |
||
4176 | if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
||
4177 | bCalcX = true; |
||
4178 | else if (targetLine.SlopeType == SlopeType.VERTICAL) |
||
4179 | bCalcY = true; |
||
4180 | else |
||
4181 | { |
||
4182 | bCalcX = true; |
||
4183 | bCalcY = true; |
||
4184 | } |
||
4185 | a0e3dca4 | gaqhf | |
4186 | b01e7456 | gaqhf | if (bCalcX) |
4187 | a0e3dca4 | gaqhf | { |
4188 | b01e7456 | gaqhf | double nextX = targetVertices[i + 1][0]; |
4189 | double newX = 0; |
||
4190 | if (nextX > tempX) |
||
4191 | { |
||
4192 | newX = tempX + gridSetting.Length; |
||
4193 | if (newX > nextX) |
||
4194 | newX = (point[0] + nextX) / 2; |
||
4195 | } |
||
4196 | a0e3dca4 | gaqhf | else |
4197 | { |
||
4198 | b01e7456 | gaqhf | newX = tempX - gridSetting.Length; |
4199 | if (newX < nextX) |
||
4200 | newX = (point[0] + nextX) / 2; |
||
4201 | a0e3dca4 | gaqhf | } |
4202 | b01e7456 | gaqhf | resultPoint = new double[] { newX, resultPoint[1] }; |
4203 | } |
||
4204 | a0e3dca4 | gaqhf | |
4205 | b01e7456 | gaqhf | if (bCalcY) |
4206 | { |
||
4207 | double nextY = targetVertices[i + 1][1]; |
||
4208 | double newY = 0; |
||
4209 | if (nextY > tempY) |
||
4210 | a0e3dca4 | gaqhf | { |
4211 | b01e7456 | gaqhf | newY = tempY + gridSetting.Length; |
4212 | if (newY > nextY) |
||
4213 | newY = (point[1] + nextY) / 2; |
||
4214 | a0e3dca4 | gaqhf | } |
4215 | b01e7456 | gaqhf | else |
4216 | a0e3dca4 | gaqhf | { |
4217 | b01e7456 | gaqhf | newY = tempY - gridSetting.Length; |
4218 | if (newY < nextY) |
||
4219 | newY = (point[1] + nextY) / 2; |
||
4220 | a0e3dca4 | gaqhf | } |
4221 | b01e7456 | gaqhf | resultPoint = new double[] { resultPoint[0], newY }; |
4222 | a0e3dca4 | gaqhf | } |
4223 | } |
||
4224 | } |
||
4225 | else if (i == targetVertices.Count - 1) |
||
4226 | { |
||
4227 | LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject; |
||
4228 | b01e7456 | gaqhf | bool containZeroLength = false; |
4229 | if (connSymbol != null) |
||
4230 | a0e3dca4 | gaqhf | { |
4231 | 1805d3b7 | gaqhf | foreach (LMConnector connector in connSymbol.Connect1Connectors) |
4232 | { |
||
4233 | b01e7456 | gaqhf | if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4234 | 1805d3b7 | gaqhf | containZeroLength = true; |
4235 | } |
||
4236 | foreach (LMConnector connector in connSymbol.Connect2Connectors) |
||
4237 | a0e3dca4 | gaqhf | { |
4238 | b01e7456 | gaqhf | if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4239 | 1805d3b7 | gaqhf | containZeroLength = true; |
4240 | a0e3dca4 | gaqhf | } |
4241 | b01e7456 | gaqhf | } |
4242 | |||
4243 | if (connSymbol == null || |
||
4244 | (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") || |
||
4245 | containZeroLength) |
||
4246 | { |
||
4247 | bool bCalcX = false; |
||
4248 | bool bCalcY = false; |
||
4249 | if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
||
4250 | bCalcX = true; |
||
4251 | else if (targetLine.SlopeType == SlopeType.VERTICAL) |
||
4252 | bCalcY = true; |
||
4253 | else |
||
4254 | { |
||
4255 | bCalcX = true; |
||
4256 | bCalcY = true; |
||
4257 | } |
||
4258 | a0e3dca4 | gaqhf | |
4259 | b01e7456 | gaqhf | if (bCalcX) |
4260 | a0e3dca4 | gaqhf | { |
4261 | b01e7456 | gaqhf | double nextX = targetVertices[i - 1][0]; |
4262 | double newX = 0; |
||
4263 | if (nextX > tempX) |
||
4264 | { |
||
4265 | newX = tempX + gridSetting.Length; |
||
4266 | if (newX > nextX) |
||
4267 | newX = (point[0] + nextX) / 2; |
||
4268 | } |
||
4269 | a0e3dca4 | gaqhf | else |
4270 | { |
||
4271 | b01e7456 | gaqhf | newX = tempX - gridSetting.Length; |
4272 | if (newX < nextX) |
||
4273 | newX = (point[0] + nextX) / 2; |
||
4274 | a0e3dca4 | gaqhf | } |
4275 | b01e7456 | gaqhf | resultPoint = new double[] { newX, resultPoint[1] }; |
4276 | } |
||
4277 | a0e3dca4 | gaqhf | |
4278 | b01e7456 | gaqhf | if (bCalcY) |
4279 | { |
||
4280 | double nextY = targetVertices[i - 1][1]; |
||
4281 | double newY = 0; |
||
4282 | if (nextY > tempY) |
||
4283 | a0e3dca4 | gaqhf | { |
4284 | b01e7456 | gaqhf | newY = tempY + gridSetting.Length; |
4285 | if (newY > nextY) |
||
4286 | newY = (point[1] + nextY) / 2; |
||
4287 | a0e3dca4 | gaqhf | } |
4288 | b01e7456 | gaqhf | else |
4289 | a0e3dca4 | gaqhf | { |
4290 | b01e7456 | gaqhf | newY = tempY - gridSetting.Length; |
4291 | if (newY < nextY) |
||
4292 | newY = (point[1] + nextY) / 2; |
||
4293 | a0e3dca4 | gaqhf | } |
4294 | b01e7456 | gaqhf | resultPoint = new double[] { resultPoint[0], newY }; |
4295 | a0e3dca4 | gaqhf | } |
4296 | } |
||
4297 | 68464385 | gaqhf | } |
4298 | a0e3dca4 | gaqhf | break; |
4299 | 68464385 | gaqhf | } |
4300 | } |
||
4301 | } |
||
4302 | |||
4303 | a0e3dca4 | gaqhf | x = resultPoint[0]; |
4304 | y = resultPoint[1]; |
||
4305 | |||
4306 | 68464385 | gaqhf | return targetConnector; |
4307 | } |
||
4308 | |||
4309 | 1ff0105e | gaqhf | private LMConnector GetLMConnectorOnlyOne(string modelItemID) |
4310 | { |
||
4311 | LMConnector result = null; |
||
4312 | List<LMConnector> connectors = new List<LMConnector>(); |
||
4313 | LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
||
4314 | |||
4315 | if (modelItem != null) |
||
4316 | { |
||
4317 | foreach (LMRepresentation rep in modelItem.Representations) |
||
4318 | { |
||
4319 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
4320 | connectors.Add(dataSource.GetConnector(rep.Id)); |
||
4321 | } |
||
4322 | |||
4323 | ReleaseCOMObjects(modelItem); |
||
4324 | } |
||
4325 | |||
4326 | if (connectors.Count == 1) |
||
4327 | result = connectors[0]; |
||
4328 | else |
||
4329 | foreach (var item in connectors) |
||
4330 | ReleaseCOMObjects(item); |
||
4331 | |||
4332 | return result; |
||
4333 | } |
||
4334 | |||
4335 | 63a112d9 | gaqhf | private LMConnector GetLMConnectorFirst(string modelItemID) |
4336 | { |
||
4337 | LMConnector result = null; |
||
4338 | LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
||
4339 | |||
4340 | if (modelItem != null) |
||
4341 | { |
||
4342 | foreach (LMRepresentation rep in modelItem.Representations) |
||
4343 | { |
||
4344 | 2e69e97c | gaqhf | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && |
4345 | 63a112d9 | gaqhf | rep.Attributes["ItemStatus"].get_Value() == "Active") |
4346 | { |
||
4347 | LMConnector connector = dataSource.GetConnector(rep.Id); |
||
4348 | if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
||
4349 | { |
||
4350 | result = connector; |
||
4351 | break; |
||
4352 | } |
||
4353 | else |
||
4354 | { |
||
4355 | ReleaseCOMObjects(connector); |
||
4356 | connector = null; |
||
4357 | } |
||
4358 | } |
||
4359 | } |
||
4360 | ReleaseCOMObjects(modelItem); |
||
4361 | modelItem = null; |
||
4362 | } |
||
4363 | |||
4364 | return result; |
||
4365 | } |
||
4366 | |||
4367 | 7e680366 | gaqhf | private int GetConnectorCount(string modelItemID) |
4368 | { |
||
4369 | LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
||
4370 | int result = 0; |
||
4371 | if (modelItem != null) |
||
4372 | { |
||
4373 | foreach (LMRepresentation rep in modelItem.Representations) |
||
4374 | { |
||
4375 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
4376 | result++; |
||
4377 | ReleaseCOMObjects(rep); |
||
4378 | } |
||
4379 | ReleaseCOMObjects(modelItem); |
||
4380 | } |
||
4381 | |||
4382 | return result; |
||
4383 | } |
||
4384 | |||
4385 | fae4f386 | gaqhf | public List<string> GetRepresentations(string modelItemID) |
4386 | { |
||
4387 | List<string> result = new List<string>(); ; |
||
4388 | LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
||
4389 | if (modelItem != null) |
||
4390 | { |
||
4391 | foreach (LMRepresentation rep in modelItem.Representations) |
||
4392 | { |
||
4393 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
4394 | result.Add(rep.Id); |
||
4395 | } |
||
4396 | ReleaseCOMObjects(modelItem); |
||
4397 | } |
||
4398 | |||
4399 | return result; |
||
4400 | } |
||
4401 | |||
4402 | 8701de36 | gaqhf | private void LineNumberModeling(LineNumber lineNumber) |
4403 | { |
||
4404 | Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
||
4405 | if (line != null) |
||
4406 | { |
||
4407 | double x = 0; |
||
4408 | double y = 0; |
||
4409 | CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation); |
||
4410 | |||
4411 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
||
4412 | LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, x, y); |
||
4413 | if (connectedLMConnector != null) |
||
4414 | { |
||
4415 | Array points = new double[] { 0, x, y }; |
||
4416 | 44087b23 | gaqhf | lineNumber.SPPID.SPPID_X = x; |
4417 | lineNumber.SPPID.SPPID_Y = y; |
||
4418 | 8701de36 | gaqhf | LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false); |
4419 | ca6e0f51 | gaqhf | |
4420 | 8701de36 | gaqhf | if (_LmLabelPresist != null) |
4421 | { |
||
4422 | _LmLabelPresist.Commit(); |
||
4423 | lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
||
4424 | ReleaseCOMObjects(_LmLabelPresist); |
||
4425 | } |
||
4426 | } |
||
4427 | |||
4428 | foreach (var item in connectorVertices) |
||
4429 | ReleaseCOMObjects(item.Key); |
||
4430 | } |
||
4431 | } |
||
4432 | 44087b23 | gaqhf | private void LineNumberCorrectModeling(LineNumber lineNumber) |
4433 | { |
||
4434 | Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
||
4435 | if (line == null || line.SPPID.Vertices == null) |
||
4436 | return; |
||
4437 | |||
4438 | if (!string.IsNullOrEmpty(lineNumber.SPPID.RepresentationId)) |
||
4439 | { |
||
4440 | LMLabelPersist removeLabel = dataSource.GetLabelPersist(lineNumber.SPPID.RepresentationId); |
||
4441 | if (removeLabel != null) |
||
4442 | 3d92d75d | gaqhf | { |
4443 | lineNumber.SPPID.SPPID_X = removeLabel.get_XCoordinate(); |
||
4444 | lineNumber.SPPID.SPPID_Y = removeLabel.get_YCoordinate(); |
||
4445 | |||
4446 | 44087b23 | gaqhf | GridSetting gridSetting = GridSetting.GetInstance(); |
4447 | 898e39fe | gaqhf | LMConnector connector = dataSource.GetConnector(removeLabel.RepresentationID); |
4448 | 3d92d75d | gaqhf | |
4449 | 44087b23 | gaqhf | double[] labelRange = null; |
4450 | GetSPPIDSymbolRange(removeLabel, ref labelRange); |
||
4451 | List<double[]> vertices = GetConnectorVertices(connector); |
||
4452 | |||
4453 | double[] resultStart = null; |
||
4454 | double[] resultEnd = null; |
||
4455 | double distance = double.MaxValue; |
||
4456 | for (int i = 0; i < vertices.Count - 1; i++) |
||
4457 | { |
||
4458 | double[] startPoint = vertices[i]; |
||
4459 | double[] endPoint = vertices[i + 1]; |
||
4460 | foreach (var item in line.SPPID.Vertices) |
||
4461 | { |
||
4462 | double[] lineStartPoint = item[0]; |
||
4463 | double[] lineEndPoint = item[item.Count - 1]; |
||
4464 | |||
4465 | double tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineStartPoint[0], lineStartPoint[1]) + |
||
4466 | SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineEndPoint[0], lineEndPoint[1]); |
||
4467 | if (tempDistance < distance) |
||
4468 | { |
||
4469 | distance = tempDistance; |
||
4470 | resultStart = startPoint; |
||
4471 | resultEnd = endPoint; |
||
4472 | } |
||
4473 | tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineEndPoint[0], lineEndPoint[1]) + |
||
4474 | SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineStartPoint[0], lineStartPoint[1]); |
||
4475 | if (tempDistance < distance) |
||
4476 | { |
||
4477 | distance = tempDistance; |
||
4478 | resultStart = startPoint; |
||
4479 | resultEnd = endPoint; |
||
4480 | } |
||
4481 | } |
||
4482 | } |
||
4483 | |||
4484 | if (resultStart != null && resultEnd != null) |
||
4485 | { |
||
4486 | SlopeType slope = SPPIDUtil.CalcSlope(resultStart[0], resultStart[1], resultEnd[0], resultEnd[1]); |
||
4487 | double lineStartX = 0; |
||
4488 | double lineStartY = 0; |
||
4489 | double lineEndX = 0; |
||
4490 | double lineEndY = 0; |
||
4491 | double lineNumberX = 0; |
||
4492 | double lineNumberY = 0; |
||
4493 | SPPIDUtil.ConvertPointBystring(line.STARTPOINT, ref lineStartX, ref lineStartY); |
||
4494 | SPPIDUtil.ConvertPointBystring(line.ENDPOINT, ref lineEndX, ref lineEndY); |
||
4495 | |||
4496 | double lineX = (lineStartX + lineEndX) / 2; |
||
4497 | double lineY = (lineStartY + lineEndY) / 2; |
||
4498 | lineNumberX = (lineNumber.X1 + lineNumber.X2) / 2; |
||
4499 | lineNumberY = (lineNumber.Y1 + lineNumber.Y2) / 2; |
||
4500 | |||
4501 | double SPPIDCenterX = (resultStart[0] + resultEnd[0]) / 2; |
||
4502 | double SPPIDCenterY = (resultStart[1] + resultEnd[1]) / 2; |
||
4503 | double labelCenterX = (labelRange[0] + labelRange[2]) / 2; |
||
4504 | double labelCenterY = (labelRange[1] + labelRange[3]) / 2; |
||
4505 | |||
4506 | double offsetX = 0; |
||
4507 | double offsetY = 0; |
||
4508 | if (slope == SlopeType.HORIZONTAL) |
||
4509 | { |
||
4510 | // Line Number 아래 |
||
4511 | if (lineY < lineNumberY) |
||
4512 | { |
||
4513 | offsetX = labelCenterX - SPPIDCenterX; |
||
4514 | offsetY = labelRange[3] - SPPIDCenterY + gridSetting.Length; |
||
4515 | MoveLineNumber(lineNumber, offsetX, offsetY); |
||
4516 | } |
||
4517 | // Line Number 위 |
||
4518 | else |
||
4519 | { |
||
4520 | offsetX = labelCenterX - SPPIDCenterX; |
||
4521 | offsetY = labelRange[1] - SPPIDCenterY - gridSetting.Length; |
||
4522 | MoveLineNumber(lineNumber, offsetX, offsetY); |
||
4523 | } |
||
4524 | } |
||
4525 | else if (slope == SlopeType.VERTICAL) |
||
4526 | { |
||
4527 | // Line Number 오르쪽 |
||
4528 | if (lineX < lineNumberX) |
||
4529 | { |
||
4530 | offsetX = labelRange[0] - SPPIDCenterX - gridSetting.Length; |
||
4531 | offsetY = labelCenterY - SPPIDCenterY; |
||
4532 | MoveLineNumber(lineNumber, offsetX, offsetY); |
||
4533 | } |
||
4534 | // Line Number 왼쪽 |
||
4535 | else |
||
4536 | { |
||
4537 | offsetX = labelRange[2] - SPPIDCenterX + gridSetting.Length; |
||
4538 | offsetY = labelCenterY - SPPIDCenterY; |
||
4539 | MoveLineNumber(lineNumber, offsetX, offsetY); |
||
4540 | } |
||
4541 | } |
||
4542 | |||
4543 | 898e39fe | gaqhf | if (offsetY != 0 || offsetY != 0) |
4544 | 44087b23 | gaqhf | { |
4545 | 898e39fe | gaqhf | if (connector.ConnectItem1SymbolObject != null && |
4546 | connector.ConnectItem1SymbolObject.get_RepresentationType() == "OPC") |
||
4547 | { |
||
4548 | Ingr.RAD2D.Symbol2d symbol = radApp.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
||
4549 | |||
4550 | double x1, y1, x2, y2, originX, originY; |
||
4551 | symbol.Range(out x1, out y1, out x2, out y2); |
||
4552 | symbol.GetOrigin(out originX, out originY); |
||
4553 | if (originX < lineNumber.SPPID.SPPID_X) |
||
4554 | 9a441e35 | gaqhf | offsetX = -1 * (originX + gridSetting.Length * 30 - labelCenterX); |
4555 | 898e39fe | gaqhf | else |
4556 | 9a441e35 | gaqhf | offsetX = -1 * (originX - gridSetting.Length * 30 - labelCenterX); |
4557 | 898e39fe | gaqhf | } |
4558 | else if (connector.ConnectItem2SymbolObject != null && |
||
4559 | connector.ConnectItem2SymbolObject.get_RepresentationType() == "OPC") |
||
4560 | { |
||
4561 | Ingr.RAD2D.Symbol2d symbol = radApp.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
||
4562 | |||
4563 | double x1, y1, x2, y2, originX, originY; |
||
4564 | symbol.Range(out x1, out y1, out x2, out y2); |
||
4565 | symbol.GetOrigin(out originX, out originY); |
||
4566 | if (originX < lineNumber.SPPID.SPPID_X) |
||
4567 | 9a441e35 | gaqhf | offsetX = -1 * (originX + gridSetting.Length * 30 - labelCenterX); |
4568 | 898e39fe | gaqhf | else |
4569 | 9a441e35 | gaqhf | offsetX = -1 * (originX - gridSetting.Length * 30 - labelCenterX); |
4570 | 898e39fe | gaqhf | } |
4571 | |||
4572 | 3d92d75d | gaqhf | radApp.ActiveSelectSet.RemoveAll(); |
4573 | DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[removeLabel.get_GraphicOID().ToString()] as DependencyObject; |
||
4574 | if (dependency != null) |
||
4575 | 44087b23 | gaqhf | { |
4576 | 3d92d75d | gaqhf | radApp.ActiveSelectSet.Add(dependency); |
4577 | Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
||
4578 | transform.DefineByMove2d(-offsetX, -offsetY); |
||
4579 | radApp.ActiveSelectSet.Transform(transform, true); |
||
4580 | radApp.ActiveSelectSet.RemoveAll(); |
||
4581 | 44087b23 | gaqhf | } |
4582 | } |
||
4583 | |||
4584 | void MoveLineNumber(LineNumber moveLineNumber, double x, double y) |
||
4585 | { |
||
4586 | moveLineNumber.SPPID.SPPID_X = moveLineNumber.SPPID.SPPID_X - x; |
||
4587 | moveLineNumber.SPPID.SPPID_Y = moveLineNumber.SPPID.SPPID_Y - y; |
||
4588 | } |
||
4589 | } |
||
4590 | |||
4591 | |||
4592 | ReleaseCOMObjects(connector); |
||
4593 | connector = null; |
||
4594 | } |
||
4595 | |||
4596 | ReleaseCOMObjects(removeLabel); |
||
4597 | removeLabel = null; |
||
4598 | } |
||
4599 | } |
||
4600 | 74752074 | gaqhf | /// <summary> |
4601 | b2d1c1aa | gaqhf | /// Flow Mark Modeling |
4602 | /// </summary> |
||
4603 | /// <param name="line"></param> |
||
4604 | private void FlowMarkModeling(Line line) |
||
4605 | { |
||
4606 | a0965e07 | gaqhf | if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath)) |
4607 | b2d1c1aa | gaqhf | { |
4608 | 32205389 | gaqhf | LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId); |
4609 | if (connector != null) |
||
4610 | b2d1c1aa | gaqhf | { |
4611 | 32205389 | gaqhf | string mappingPath = _ETCSetting.FlowMarkSymbolPath; |
4612 | List<double[]> vertices = GetConnectorVertices(connector); |
||
4613 | vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0); |
||
4614 | double[] point = vertices[vertices.Count - 1]; |
||
4615 | Array array = new double[] { 0, point[0], point[1] }; |
||
4616 | LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation()); |
||
4617 | if (_LMLabelPersist != null) |
||
4618 | 04fcadf1 | gaqhf | { |
4619 | _LMLabelPersist.Commit(); |
||
4620 | c5b2c7ff | gaqhf | FlowMarkRepIds.Add(_LMLabelPersist.Id); |
4621 | 32205389 | gaqhf | ReleaseCOMObjects(_LMLabelPersist); |
4622 | 04fcadf1 | gaqhf | } |
4623 | b2d1c1aa | gaqhf | } |
4624 | } |
||
4625 | } |
||
4626 | |||
4627 | /// <summary> |
||
4628 | 74752074 | gaqhf | /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input |
4629 | /// </summary> |
||
4630 | /// <param name="lineNumber"></param> |
||
4631 | 82d6e5ea | gaqhf | private void InputLineNumberAttribute(LineNumber lineNumber, List<string> endLine) |
4632 | a7e9beec | gaqhf | { |
4633 | f4571b5d | gaqhf | lineNumber.ATTRIBUTES.Sort(SortAttribute); |
4634 | int SortAttribute(BaseModel.Attribute a, BaseModel.Attribute b) |
||
4635 | { |
||
4636 | if (a.ATTRIBUTE == "Tag Seq No") |
||
4637 | return 1; |
||
4638 | else if (b.ATTRIBUTE == "Tag Seq No") |
||
4639 | return -1; |
||
4640 | |||
4641 | return 0; |
||
4642 | } |
||
4643 | |||
4644 | 8634af60 | gaqhf | foreach (LineRun run in lineNumber.RUNS) |
4645 | a7e9beec | gaqhf | { |
4646 | 8634af60 | gaqhf | foreach (var item in run.RUNITEMS) |
4647 | a7e9beec | gaqhf | { |
4648 | 16fb3441 | gaqhf | if (item.GetType() == typeof(Line)) |
4649 | 8634af60 | gaqhf | { |
4650 | Line line = item as Line; |
||
4651 | 82d6e5ea | gaqhf | if (line != null && !endLine.Contains(line.SPPID.ModelItemId)) |
4652 | a7e9beec | gaqhf | { |
4653 | 8634af60 | gaqhf | LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
4654 | if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
||
4655 | a7e9beec | gaqhf | { |
4656 | 8634af60 | gaqhf | foreach (var attribute in lineNumber.ATTRIBUTES) |
4657 | { |
||
4658 | LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
||
4659 | b2d1c1aa | gaqhf | if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
4660 | 8634af60 | gaqhf | { |
4661 | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
4662 | 41e26743 | gaqhf | if (mapping.SPPIDATTRIBUTENAME == "OperFluidCode" && !string.IsNullOrEmpty(attribute.VALUE)) |
4663 | { |
||
4664 | LMAAttribute _FluidSystemAttribute = _LMModelItem.Attributes["FluidSystem"]; |
||
4665 | if (_FluidSystemAttribute != null) |
||
4666 | { |
||
4667 | DataTable dt = SPPID_DB.GetFluidSystemInfo(attribute.VALUE); |
||
4668 | if (dt.Rows.Count == 1) |
||
4669 | { |
||
4670 | string fluidSystem = dt.Rows[0]["CODELIST_TEXT"].ToString(); |
||
4671 | if (DBNull.Value.Equals(_FluidSystemAttribute.get_Value())) |
||
4672 | _FluidSystemAttribute.set_Value(fluidSystem); |
||
4673 | else if (_FluidSystemAttribute.get_Value() != fluidSystem) |
||
4674 | _FluidSystemAttribute.set_Value(fluidSystem); |
||
4675 | |||
4676 | if (_LMAAttribute != null) |
||
4677 | { |
||
4678 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
4679 | _LMAAttribute.set_Value(attribute.VALUE); |
||
4680 | else if (_LMAAttribute.get_Value() != attribute.VALUE) |
||
4681 | _LMAAttribute.set_Value(attribute.VALUE); |
||
4682 | } |
||
4683 | } |
||
4684 | if (dt != null) |
||
4685 | dt.Dispose(); |
||
4686 | } |
||
4687 | } |
||
4688 | c9264d17 | gaqhf | else if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(attribute.VALUE) && _LMAAttribute != null) |
4689 | { |
||
4690 | 52599bc7 | gaqhf | DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", attribute.VALUE)); |
4691 | |||
4692 | if (rows.Length.Equals(1)) |
||
4693 | { |
||
4694 | if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric")) |
||
4695 | attribute.VALUE = rows[0]["MetricStr"].ToString(); |
||
4696 | else |
||
4697 | attribute.VALUE = rows[0]["InchStr"].ToString(); |
||
4698 | |||
4699 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
4700 | _LMAAttribute.set_Value(attribute.VALUE); |
||
4701 | else if (_LMAAttribute.get_Value() != attribute.VALUE) |
||
4702 | _LMAAttribute.set_Value(attribute.VALUE); |
||
4703 | } |
||
4704 | c9264d17 | gaqhf | } |
4705 | 41e26743 | gaqhf | else if (_LMAAttribute != null) |
4706 | 8634af60 | gaqhf | { |
4707 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
4708 | _LMAAttribute.set_Value(attribute.VALUE); |
||
4709 | else if (_LMAAttribute.get_Value() != attribute.VALUE) |
||
4710 | _LMAAttribute.set_Value(attribute.VALUE); |
||
4711 | } |
||
4712 | } |
||
4713 | } |
||
4714 | 68464385 | gaqhf | _LMModelItem.Commit(); |
4715 | a7e9beec | gaqhf | } |
4716 | 8634af60 | gaqhf | if (_LMModelItem != null) |
4717 | ReleaseCOMObjects(_LMModelItem); |
||
4718 | 82d6e5ea | gaqhf | endLine.Add(line.SPPID.ModelItemId); |
4719 | a7e9beec | gaqhf | } |
4720 | } |
||
4721 | } |
||
4722 | } |
||
4723 | } |
||
4724 | |||
4725 | 74752074 | gaqhf | /// <summary> |
4726 | /// Symbol Attribute 입력 메서드 |
||
4727 | /// </summary> |
||
4728 | 73415441 | gaqhf | /// <param name="item"></param> |
4729 | private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes) |
||
4730 | 1efc25a3 | gaqhf | { |
4731 | 7f00b26c | gaqhf | // Object 아이템이 Symbol일 경우 Equipment일 경우 |
4732 | string sRep = null; |
||
4733 | 77a869a8 | gaqhf | string sModelID = null; |
4734 | 7f00b26c | gaqhf | if (targetItem.GetType() == typeof(Symbol)) |
4735 | sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
||
4736 | else if (targetItem.GetType() == typeof(Equipment)) |
||
4737 | sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
||
4738 | 77a869a8 | gaqhf | else if (targetItem.GetType() == typeof(Line)) |
4739 | sModelID = ((Line)targetItem).SPPID.ModelItemId; |
||
4740 | f8b99593 | gaqhf | |
4741 | 7f00b26c | gaqhf | if (!string.IsNullOrEmpty(sRep)) |
4742 | 1efc25a3 | gaqhf | { |
4743 | 7f00b26c | gaqhf | LMSymbol _LMSymbol = dataSource.GetSymbol(sRep); |
4744 | f8b99593 | gaqhf | LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
4745 | LMAAttributes _Attributes = _LMModelItem.Attributes; |
||
4746 | |||
4747 | 7f00b26c | gaqhf | foreach (var item in targetAttributes) |
4748 | { |
||
4749 | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
||
4750 | if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
||
4751 | 65a1ed4b | gaqhf | { |
4752 | 1ecaaba8 | gaqhf | if (!mapping.IsText) |
4753 | 30ba9ae0 | gaqhf | { |
4754 | c9264d17 | gaqhf | LMAAttribute _LMAAttribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
4755 | if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(item.VALUE) && _LMAAttribute != null) |
||
4756 | b7a29053 | gaqhf | { |
4757 | 52599bc7 | gaqhf | DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", item.VALUE)); |
4758 | |||
4759 | if (rows.Length.Equals(1)) |
||
4760 | { |
||
4761 | if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric")) |
||
4762 | item.VALUE = rows[0]["MetricStr"].ToString(); |
||
4763 | else |
||
4764 | item.VALUE = rows[0]["InchStr"].ToString(); |
||
4765 | |||
4766 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
4767 | _LMAAttribute.set_Value(item.VALUE); |
||
4768 | else if (_LMAAttribute.get_Value() != item.VALUE) |
||
4769 | _LMAAttribute.set_Value(item.VALUE); |
||
4770 | } |
||
4771 | c9264d17 | gaqhf | } |
4772 | else if (_LMAAttribute != null) |
||
4773 | { |
||
4774 | _LMAAttribute.set_Value(item.VALUE); |
||
4775 | 1ecaaba8 | gaqhf | // OPC 일경우 Attribute 저장 |
4776 | if (targetItem.GetType() == typeof(Symbol)) |
||
4777 | { |
||
4778 | Symbol symbol = targetItem as Symbol; |
||
4779 | if (symbol.TYPE == "Piping OPC's" || symbol.TYPE == "Instrument OPC's") |
||
4780 | symbol.SPPID.Attributes.Add(new string[] { mapping.SPPIDATTRIBUTENAME, item.VALUE }); |
||
4781 | } |
||
4782 | b7a29053 | gaqhf | } |
4783 | 30ba9ae0 | gaqhf | } |
4784 | 1ecaaba8 | gaqhf | else |
4785 | DefaultTextModeling(item.VALUE, _LMSymbol.get_XCoordinate(), _LMSymbol.get_YCoordinate()); |
||
4786 | 65a1ed4b | gaqhf | } |
4787 | ac78b508 | gaqhf | } |
4788 | f8b99593 | gaqhf | _LMModelItem.Commit(); |
4789 | 7f00b26c | gaqhf | |
4790 | ReleaseCOMObjects(_Attributes); |
||
4791 | f8b99593 | gaqhf | ReleaseCOMObjects(_LMModelItem); |
4792 | 7f00b26c | gaqhf | ReleaseCOMObjects(_LMSymbol); |
4793 | 1efc25a3 | gaqhf | } |
4794 | 77a869a8 | gaqhf | else if (!string.IsNullOrEmpty(sModelID)) |
4795 | { |
||
4796 | LMModelItem _LMModelItem = dataSource.GetModelItem(sModelID); |
||
4797 | LMAAttributes _Attributes = _LMModelItem.Attributes; |
||
4798 | |||
4799 | foreach (var item in targetAttributes) |
||
4800 | { |
||
4801 | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
||
4802 | f969dc62 | gaqhf | if (mapping == null) |
4803 | continue; |
||
4804 | |||
4805 | 2e92b956 | gaqhf | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
4806 | if (mapping.SPPIDATTRIBUTENAME == "OperFluidCode" && !string.IsNullOrEmpty(item.VALUE)) |
||
4807 | { |
||
4808 | LMAAttribute _FluidSystemAttribute = _LMModelItem.Attributes["FluidSystem"]; |
||
4809 | if (_FluidSystemAttribute != null) |
||
4810 | { |
||
4811 | DataTable dt = SPPID_DB.GetFluidSystemInfo(item.VALUE); |
||
4812 | if (dt.Rows.Count == 1) |
||
4813 | { |
||
4814 | string fluidSystem = dt.Rows[0]["CODELIST_TEXT"].ToString(); |
||
4815 | if (DBNull.Value.Equals(_FluidSystemAttribute.get_Value())) |
||
4816 | _FluidSystemAttribute.set_Value(fluidSystem); |
||
4817 | else if (_FluidSystemAttribute.get_Value() != fluidSystem) |
||
4818 | _FluidSystemAttribute.set_Value(fluidSystem); |
||
4819 | |||
4820 | if (_LMAAttribute != null) |
||
4821 | { |
||
4822 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
4823 | _LMAAttribute.set_Value(item.VALUE); |
||
4824 | else if (_LMAAttribute.get_Value() != item.VALUE) |
||
4825 | _LMAAttribute.set_Value(item.VALUE); |
||
4826 | } |
||
4827 | } |
||
4828 | if (dt != null) |
||
4829 | dt.Dispose(); |
||
4830 | } |
||
4831 | } |
||
4832 | c9264d17 | gaqhf | else if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(item.VALUE) && _LMAAttribute != null) |
4833 | { |
||
4834 | 52599bc7 | gaqhf | DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", item.VALUE)); |
4835 | |||
4836 | if (rows.Length.Equals(1)) |
||
4837 | { |
||
4838 | if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric")) |
||
4839 | item.VALUE = rows[0]["MetricStr"].ToString(); |
||
4840 | else |
||
4841 | item.VALUE = rows[0]["InchStr"].ToString(); |
||
4842 | |||
4843 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
4844 | _LMAAttribute.set_Value(item.VALUE); |
||
4845 | else if (_LMAAttribute.get_Value() != item.VALUE) |
||
4846 | _LMAAttribute.set_Value(item.VALUE); |
||
4847 | } |
||
4848 | c9264d17 | gaqhf | } |
4849 | 2e92b956 | gaqhf | else if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
4850 | 77a869a8 | gaqhf | { |
4851 | if (!mapping.IsText) |
||
4852 | { |
||
4853 | LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
4854 | if (_Attribute != null) |
||
4855 | _Attribute.set_Value(item.VALUE); |
||
4856 | } |
||
4857 | } |
||
4858 | } |
||
4859 | _LMModelItem.Commit(); |
||
4860 | |||
4861 | ReleaseCOMObjects(_Attributes); |
||
4862 | ReleaseCOMObjects(_LMModelItem); |
||
4863 | } |
||
4864 | 1efc25a3 | gaqhf | } |
4865 | |||
4866 | 74752074 | gaqhf | /// <summary> |
4867 | 16584d30 | gaqhf | /// Input SpecBreak Attribute |
4868 | /// </summary> |
||
4869 | /// <param name="specBreak"></param> |
||
4870 | private void InputSpecBreakAttribute(SpecBreak specBreak) |
||
4871 | { |
||
4872 | 7f00b26c | gaqhf | object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID); |
4873 | object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID); |
||
4874 | |||
4875 | if (upStreamObj != null && |
||
4876 | downStreamObj != null) |
||
4877 | 16584d30 | gaqhf | { |
4878 | 7f00b26c | gaqhf | LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj); |
4879 | 16584d30 | gaqhf | |
4880 | 7f00b26c | gaqhf | if (targetLMConnector != null) |
4881 | 16584d30 | gaqhf | { |
4882 | 7f00b26c | gaqhf | foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists) |
4883 | 16584d30 | gaqhf | { |
4884 | 7f00b26c | gaqhf | string symbolPath = _LMLabelPersist.get_FileName(); |
4885 | AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath); |
||
4886 | if (mapping != null) |
||
4887 | 16584d30 | gaqhf | { |
4888 | 7f00b26c | gaqhf | BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID); |
4889 | if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
||
4890 | 16584d30 | gaqhf | { |
4891 | 7f00b26c | gaqhf | string[] values = attribute.VALUE.Split(new char[] { ',' }); |
4892 | if (values.Length == 2) |
||
4893 | 16584d30 | gaqhf | { |
4894 | 7f00b26c | gaqhf | string upStreamValue = values[0]; |
4895 | string downStreamValue = values[1]; |
||
4896 | 16584d30 | gaqhf | |
4897 | 7f00b26c | gaqhf | InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME); |
4898 | 16584d30 | gaqhf | } |
4899 | } |
||
4900 | } |
||
4901 | } |
||
4902 | 7f00b26c | gaqhf | |
4903 | ReleaseCOMObjects(targetLMConnector); |
||
4904 | 16584d30 | gaqhf | } |
4905 | } |
||
4906 | 7f00b26c | gaqhf | |
4907 | 16584d30 | gaqhf | |
4908 | #region 내부에서만 쓰는 메서드 |
||
4909 | 7f00b26c | gaqhf | void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName) |
4910 | 16584d30 | gaqhf | { |
4911 | 7f00b26c | gaqhf | Symbol upStreamSymbol = _upStreamObj as Symbol; |
4912 | Line upStreamLine = _upStreamObj as Line; |
||
4913 | Symbol downStreamSymbol = _downStreamObj as Symbol; |
||
4914 | Line downStreamLine = _downStreamObj as Line; |
||
4915 | // 둘다 Line일 경우 |
||
4916 | if (upStreamLine != null && downStreamLine != null) |
||
4917 | 16584d30 | gaqhf | { |
4918 | 7f00b26c | gaqhf | InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue); |
4919 | InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue); |
||
4920 | } |
||
4921 | // 둘다 Symbol일 경우 |
||
4922 | else if (upStreamSymbol != null && downStreamSymbol != null) |
||
4923 | { |
||
4924 | LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol); |
||
4925 | LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
||
4926 | LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
||
4927 | 16584d30 | gaqhf | |
4928 | 7f00b26c | gaqhf | foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
4929 | { |
||
4930 | if (connector.get_ItemStatus() != "Active") |
||
4931 | continue; |
||
4932 | 16584d30 | gaqhf | |
4933 | 7f00b26c | gaqhf | if (connector.Id != zeroLenthConnector.Id) |
4934 | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
||
4935 | } |
||
4936 | 16584d30 | gaqhf | |
4937 | 7f00b26c | gaqhf | foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
4938 | { |
||
4939 | if (connector.get_ItemStatus() != "Active") |
||
4940 | continue; |
||
4941 | 16584d30 | gaqhf | |
4942 | 7f00b26c | gaqhf | if (connector.Id != zeroLenthConnector.Id) |
4943 | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
||
4944 | } |
||
4945 | 16584d30 | gaqhf | |
4946 | 7f00b26c | gaqhf | foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors) |
4947 | { |
||
4948 | if (connector.get_ItemStatus() != "Active") |
||
4949 | continue; |
||
4950 | 16584d30 | gaqhf | |
4951 | 7f00b26c | gaqhf | if (connector.Id != zeroLenthConnector.Id) |
4952 | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
||
4953 | } |
||
4954 | 16584d30 | gaqhf | |
4955 | 7f00b26c | gaqhf | foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors) |
4956 | { |
||
4957 | if (connector.get_ItemStatus() != "Active") |
||
4958 | continue; |
||
4959 | 16584d30 | gaqhf | |
4960 | 7f00b26c | gaqhf | if (connector.Id != zeroLenthConnector.Id) |
4961 | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
||
4962 | 16584d30 | gaqhf | } |
4963 | |||
4964 | 7f00b26c | gaqhf | ReleaseCOMObjects(zeroLenthConnector); |
4965 | ReleaseCOMObjects(upStreamLMSymbol); |
||
4966 | ReleaseCOMObjects(downStreamLMSymbol); |
||
4967 | } |
||
4968 | else if (upStreamSymbol != null && downStreamLine != null) |
||
4969 | { |
||
4970 | LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine); |
||
4971 | InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue); |
||
4972 | LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
||
4973 | 16584d30 | gaqhf | |
4974 | 7f00b26c | gaqhf | foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
4975 | { |
||
4976 | if (connector.get_ItemStatus() != "Active") |
||
4977 | continue; |
||
4978 | 16584d30 | gaqhf | |
4979 | c993d55a | gaqhf | if (connector.Id == zeroLenthConnector.Id) |
4980 | 7f00b26c | gaqhf | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
4981 | } |
||
4982 | 16584d30 | gaqhf | |
4983 | 7f00b26c | gaqhf | foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
4984 | { |
||
4985 | if (connector.get_ItemStatus() != "Active") |
||
4986 | continue; |
||
4987 | 16584d30 | gaqhf | |
4988 | c993d55a | gaqhf | if (connector.Id == zeroLenthConnector.Id) |
4989 | 7f00b26c | gaqhf | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
4990 | 16584d30 | gaqhf | } |
4991 | |||
4992 | 7f00b26c | gaqhf | ReleaseCOMObjects(zeroLenthConnector); |
4993 | ReleaseCOMObjects(upStreamLMSymbol); |
||
4994 | } |
||
4995 | else if (upStreamLine != null && downStreamSymbol != null) |
||
4996 | { |
||
4997 | LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol); |
||
4998 | InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue); |
||
4999 | LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
||
5000 | 16584d30 | gaqhf | |
5001 | 7f00b26c | gaqhf | foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors) |
5002 | { |
||
5003 | if (connector.get_ItemStatus() != "Active") |
||
5004 | continue; |
||
5005 | 16584d30 | gaqhf | |
5006 | c993d55a | gaqhf | if (connector.Id == zeroLenthConnector.Id) |
5007 | 7f00b26c | gaqhf | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
5008 | } |
||
5009 | 16584d30 | gaqhf | |
5010 | 7f00b26c | gaqhf | foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors) |
5011 | { |
||
5012 | if (connector.get_ItemStatus() != "Active") |
||
5013 | continue; |
||
5014 | 16584d30 | gaqhf | |
5015 | c993d55a | gaqhf | if (connector.Id == zeroLenthConnector.Id) |
5016 | 7f00b26c | gaqhf | InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
5017 | 16584d30 | gaqhf | } |
5018 | 7f00b26c | gaqhf | |
5019 | ReleaseCOMObjects(zeroLenthConnector); |
||
5020 | ReleaseCOMObjects(downStreamLMSymbol); |
||
5021 | 16584d30 | gaqhf | } |
5022 | } |
||
5023 | |||
5024 | void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value) |
||
5025 | { |
||
5026 | 7f00b26c | gaqhf | LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
5027 | if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
||
5028 | 16584d30 | gaqhf | { |
5029 | 7f00b26c | gaqhf | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName]; |
5030 | if (_LMAAttribute != null) |
||
5031 | 16584d30 | gaqhf | { |
5032 | 7f00b26c | gaqhf | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5033 | _LMAAttribute.set_Value(value); |
||
5034 | else if (_LMAAttribute.get_Value() != value) |
||
5035 | _LMAAttribute.set_Value(value); |
||
5036 | 16584d30 | gaqhf | } |
5037 | 7f00b26c | gaqhf | |
5038 | _LMModelItem.Commit(); |
||
5039 | 16584d30 | gaqhf | } |
5040 | 7f00b26c | gaqhf | if (_LMModelItem != null) |
5041 | ReleaseCOMObjects(_LMModelItem); |
||
5042 | 16584d30 | gaqhf | } |
5043 | |||
5044 | void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value) |
||
5045 | { |
||
5046 | 7f00b26c | gaqhf | LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID); |
5047 | if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
||
5048 | 16584d30 | gaqhf | { |
5049 | 7f00b26c | gaqhf | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName]; |
5050 | if (_LMAAttribute != null) |
||
5051 | 16584d30 | gaqhf | { |
5052 | 7f00b26c | gaqhf | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5053 | _LMAAttribute.set_Value(value); |
||
5054 | else if (_LMAAttribute.get_Value() != value) |
||
5055 | _LMAAttribute.set_Value(value); |
||
5056 | 16584d30 | gaqhf | } |
5057 | 7f00b26c | gaqhf | |
5058 | _LMModelItem.Commit(); |
||
5059 | 16584d30 | gaqhf | } |
5060 | 7f00b26c | gaqhf | if (_LMModelItem != null) |
5061 | ReleaseCOMObjects(_LMModelItem); |
||
5062 | 16584d30 | gaqhf | } |
5063 | #endregion |
||
5064 | } |
||
5065 | |||
5066 | d8afa58b | gaqhf | private void InputEndBreakAttribute(EndBreak endBreak) |
5067 | { |
||
5068 | object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
||
5069 | object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE); |
||
5070 | |||
5071 | if ((ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Line)) || |
||
5072 | (ownerObj.GetType() == typeof(Line) && connectedItem.GetType() == typeof(Symbol))) |
||
5073 | { |
||
5074 | LMLabelPersist labelPersist = dataSource.GetLabelPersist(endBreak.SPPID.RepresentationId); |
||
5075 | if (labelPersist != null) |
||
5076 | { |
||
5077 | LMRepresentation representation = labelPersist.RepresentationObject; |
||
5078 | if (representation != null) |
||
5079 | { |
||
5080 | LMConnector connector = dataSource.GetConnector(representation.Id); |
||
5081 | LMModelItem ZeroLengthModelItem = connector.ModelItemObject; |
||
5082 | string modelItemID = connector.ModelItemID; |
||
5083 | if (Convert.ToBoolean(connector.get_IsZeroLength())) |
||
5084 | { |
||
5085 | List<string> modelItemIDs = new List<string>(); |
||
5086 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
||
5087 | { |
||
5088 | LMSymbol symbol = connector.ConnectItem1SymbolObject; |
||
5089 | foreach (LMConnector item in symbol.Connect1Connectors) |
||
5090 | { |
||
5091 | if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
||
5092 | modelItemIDs.Add(item.ModelItemID); |
||
5093 | ReleaseCOMObjects(item); |
||
5094 | } |
||
5095 | foreach (LMConnector item in symbol.Connect2Connectors) |
||
5096 | { |
||
5097 | if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
||
5098 | modelItemIDs.Add(item.ModelItemID); |
||
5099 | ReleaseCOMObjects(item); |
||
5100 | } |
||
5101 | ReleaseCOMObjects(symbol); |
||
5102 | symbol = null; |
||
5103 | } |
||
5104 | else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
||
5105 | { |
||
5106 | LMSymbol symbol = connector.ConnectItem2SymbolObject; |
||
5107 | foreach (LMConnector item in symbol.Connect1Connectors) |
||
5108 | { |
||
5109 | if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
||
5110 | modelItemIDs.Add(item.ModelItemID); |
||
5111 | ReleaseCOMObjects(item); |
||
5112 | } |
||
5113 | foreach (LMConnector item in symbol.Connect2Connectors) |
||
5114 | { |
||
5115 | if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
||
5116 | modelItemIDs.Add(item.ModelItemID); |
||
5117 | ReleaseCOMObjects(item); |
||
5118 | } |
||
5119 | ReleaseCOMObjects(symbol); |
||
5120 | symbol = null; |
||
5121 | } |
||
5122 | |||
5123 | modelItemIDs = modelItemIDs.Distinct().ToList(); |
||
5124 | if (modelItemIDs.Count == 1) |
||
5125 | { |
||
5126 | LMModelItem modelItem = dataSource.GetModelItem(modelItemIDs[0]); |
||
5127 | 3ebe4712 | gaqhf | LMConnector onlyOne = GetLMConnectorOnlyOne(modelItem.Id); |
5128 | if (onlyOne != null && Convert.ToBoolean(onlyOne.get_IsZeroLength())) |
||
5129 | { |
||
5130 | bool result = false; |
||
5131 | foreach (LMLabelPersist loop in onlyOne.LabelPersists) |
||
5132 | { |
||
5133 | if (document.EndBreaks.Find(x => x.SPPID.RepresentationId == loop.RepresentationID) != null) |
||
5134 | result = true; |
||
5135 | ReleaseCOMObjects(loop); |
||
5136 | } |
||
5137 | |||
5138 | if (result) |
||
5139 | { |
||
5140 | object value = modelItem.Attributes["TagSequenceNo"].get_Value(); |
||
5141 | ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value); |
||
5142 | ZeroLengthModelItem.Commit(); |
||
5143 | } |
||
5144 | else |
||
5145 | { |
||
5146 | List<string> loopModelItems = new List<string>(); |
||
5147 | if (onlyOne.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
||
5148 | { |
||
5149 | LMSymbol _symbol = onlyOne.ConnectItem1SymbolObject; |
||
5150 | foreach (LMConnector loop in _symbol.Connect1Connectors) |
||
5151 | { |
||
5152 | if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
||
5153 | loopModelItems.Add(loop.ModelItemID); |
||
5154 | ReleaseCOMObjects(loop); |
||
5155 | } |
||
5156 | a7c63998 | gaqhf | foreach (LMConnector loop in _symbol.Connect2Connectors) |
5157 | { |
||
5158 | if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
||
5159 | loopModelItems.Add(loop.ModelItemID); |
||
5160 | ReleaseCOMObjects(loop); |
||
5161 | } |
||
5162 | 3ebe4712 | gaqhf | ReleaseCOMObjects(_symbol); |
5163 | _symbol = null; |
||
5164 | } |
||
5165 | else if (onlyOne.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
||
5166 | { |
||
5167 | a7c63998 | gaqhf | LMSymbol _symbol = onlyOne.ConnectItem2SymbolObject; |
5168 | 3ebe4712 | gaqhf | foreach (LMConnector loop in _symbol.Connect1Connectors) |
5169 | { |
||
5170 | if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
||
5171 | loopModelItems.Add(loop.ModelItemID); |
||
5172 | ReleaseCOMObjects(loop); |
||
5173 | } |
||
5174 | a7c63998 | gaqhf | foreach (LMConnector loop in _symbol.Connect2Connectors) |
5175 | { |
||
5176 | if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
||
5177 | loopModelItems.Add(loop.ModelItemID); |
||
5178 | ReleaseCOMObjects(loop); |
||
5179 | } |
||
5180 | 3ebe4712 | gaqhf | ReleaseCOMObjects(_symbol); |
5181 | _symbol = null; |
||
5182 | } |
||
5183 | |||
5184 | loopModelItems = loopModelItems.Distinct().ToList(); |
||
5185 | if (loopModelItems.Count == 1) |
||
5186 | { |
||
5187 | LMModelItem loopModelItem = dataSource.GetModelItem(loopModelItems[0]); |
||
5188 | object value = loopModelItem.Attributes["TagSequenceNo"].get_Value(); |
||
5189 | e1c86c6a | gaqhf | modelItem.Attributes["TagSequenceNo"].set_Value(value); |
5190 | modelItem.Commit(); |
||
5191 | 3ebe4712 | gaqhf | ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value); |
5192 | ZeroLengthModelItem.Commit(); |
||
5193 | |||
5194 | ReleaseCOMObjects(loopModelItem); |
||
5195 | loopModelItem = null; |
||
5196 | } |
||
5197 | } |
||
5198 | } |
||
5199 | else |
||
5200 | { |
||
5201 | object value = modelItem.Attributes["TagSequenceNo"].get_Value(); |
||
5202 | ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value); |
||
5203 | ZeroLengthModelItem.Commit(); |
||
5204 | } |
||
5205 | d8afa58b | gaqhf | ReleaseCOMObjects(modelItem); |
5206 | modelItem = null; |
||
5207 | 3ebe4712 | gaqhf | ReleaseCOMObjects(onlyOne); |
5208 | onlyOne = null; |
||
5209 | d8afa58b | gaqhf | } |
5210 | } |
||
5211 | ReleaseCOMObjects(connector); |
||
5212 | connector = null; |
||
5213 | ReleaseCOMObjects(ZeroLengthModelItem); |
||
5214 | ZeroLengthModelItem = null; |
||
5215 | } |
||
5216 | ReleaseCOMObjects(representation); |
||
5217 | representation = null; |
||
5218 | } |
||
5219 | ReleaseCOMObjects(labelPersist); |
||
5220 | labelPersist = null; |
||
5221 | } |
||
5222 | } |
||
5223 | |||
5224 | 16584d30 | gaqhf | /// <summary> |
5225 | 74752074 | gaqhf | /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링 |
5226 | /// </summary> |
||
5227 | /// <param name="text"></param> |
||
5228 | e27329d6 | gaqhf | private void NormalTextModeling(Text text) |
5229 | cfda1fed | gaqhf | { |
5230 | 6b298450 | gaqhf | LMSymbol _LMSymbol = null; |
5231 | e27329d6 | gaqhf | |
5232 | LMItemNote _LMItemNote = null; |
||
5233 | LMAAttribute _LMAAttribute = null; |
||
5234 | |||
5235 | double x = 0; |
||
5236 | double y = 0; |
||
5237 | double angle = text.ANGLE; |
||
5238 | CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation); |
||
5239 | |||
5240 | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
||
5241 | text.SPPID.SPPID_X = x; |
||
5242 | text.SPPID.SPPID_Y = y; |
||
5243 | |||
5244 | _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle); |
||
5245 | if (_LMSymbol != null) |
||
5246 | 6b298450 | gaqhf | { |
5247 | e27329d6 | gaqhf | _LMSymbol.Commit(); |
5248 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
5249 | if (_LMItemNote != null) |
||
5250 | ea80efaa | gaqhf | { |
5251 | e27329d6 | gaqhf | _LMItemNote.Commit(); |
5252 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
5253 | if (_LMAAttribute != null) |
||
5254 | ea80efaa | gaqhf | { |
5255 | e27329d6 | gaqhf | _LMAAttribute.set_Value(text.VALUE); |
5256 | text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
5257 | _LMItemNote.Commit(); |
||
5258 | 0860c756 | gaqhf | |
5259 | |||
5260 | e27329d6 | gaqhf | double[] range = null; |
5261 | foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists) |
||
5262 | { |
||
5263 | double[] temp = null; |
||
5264 | GetSPPIDSymbolRange(labelPersist, ref temp); |
||
5265 | if (temp != null) |
||
5266 | { |
||
5267 | if (range == null) |
||
5268 | range = temp; |
||
5269 | else |
||
5270 | 0860c756 | gaqhf | { |
5271 | e27329d6 | gaqhf | range = new double[] { |
5272 | Math.Min(range[0], temp[0]), |
||
5273 | Math.Min(range[1], temp[1]), |
||
5274 | Math.Max(range[2], temp[2]), |
||
5275 | Math.Max(range[3], temp[3]) |
||
5276 | }; |
||
5277 | 0860c756 | gaqhf | } |
5278 | } |
||
5279 | } |
||
5280 | e27329d6 | gaqhf | text.SPPID.Range = range; |
5281 | |||
5282 | if (_LMAAttribute != null) |
||
5283 | ReleaseCOMObjects(_LMAAttribute); |
||
5284 | if (_LMItemNote != null) |
||
5285 | ReleaseCOMObjects(_LMItemNote); |
||
5286 | ea80efaa | gaqhf | } |
5287 | e27329d6 | gaqhf | |
5288 | TextCorrectModeling(text); |
||
5289 | ea80efaa | gaqhf | } |
5290 | e27329d6 | gaqhf | } |
5291 | if (_LMSymbol != null) |
||
5292 | ReleaseCOMObjects(_LMSymbol); |
||
5293 | } |
||
5294 | ea80efaa | gaqhf | |
5295 | 1ecaaba8 | gaqhf | private void DefaultTextModeling(string value, double x, double y) |
5296 | { |
||
5297 | LMSymbol _LMSymbol = null; |
||
5298 | |||
5299 | LMItemNote _LMItemNote = null; |
||
5300 | LMAAttribute _LMAAttribute = null; |
||
5301 | |||
5302 | _LMSymbol = _placement.PIDPlaceSymbol(_ETCSetting.TextSymbolPath, x, y, Rotation: 0); |
||
5303 | if (_LMSymbol != null) |
||
5304 | { |
||
5305 | _LMSymbol.Commit(); |
||
5306 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
5307 | if (_LMItemNote != null) |
||
5308 | { |
||
5309 | _LMItemNote.Commit(); |
||
5310 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
5311 | if (_LMAAttribute != null) |
||
5312 | { |
||
5313 | _LMAAttribute.set_Value(value); |
||
5314 | _LMItemNote.Commit(); |
||
5315 | |||
5316 | if (_LMAAttribute != null) |
||
5317 | ReleaseCOMObjects(_LMAAttribute); |
||
5318 | if (_LMItemNote != null) |
||
5319 | ReleaseCOMObjects(_LMItemNote); |
||
5320 | } |
||
5321 | } |
||
5322 | } |
||
5323 | if (_LMSymbol != null) |
||
5324 | ReleaseCOMObjects(_LMSymbol); |
||
5325 | } |
||
5326 | |||
5327 | e27329d6 | gaqhf | private void AssociationTextModeling(Text text) |
5328 | { |
||
5329 | LMSymbol _LMSymbol = null; |
||
5330 | LMConnector connectedLMConnector = null; |
||
5331 | object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
||
5332 | b0d80571 | gaqhf | if (owner != null && (owner.GetType() == typeof(Symbol) || owner.GetType() == typeof(Equipment))) |
5333 | e27329d6 | gaqhf | { |
5334 | Symbol symbol = owner as Symbol; |
||
5335 | _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
5336 | if (_LMSymbol != null) |
||
5337 | { |
||
5338 | 8214047e | gaqhf | foreach (BaseModel.Attribute attribute in symbol.ATTRIBUTES.FindAll(x => x.ASSOCITEM == text.UID)) |
5339 | 7f00b26c | gaqhf | { |
5340 | 8214047e | gaqhf | if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
5341 | 7f00b26c | gaqhf | { |
5342 | 8214047e | gaqhf | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
5343 | 7f00b26c | gaqhf | |
5344 | 8214047e | gaqhf | if (mapping != null) |
5345 | 83c14a07 | gaqhf | { |
5346 | 8214047e | gaqhf | double x = 0; |
5347 | double y = 0; |
||
5348 | |||
5349 | CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
||
5350 | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
||
5351 | Array array = new double[] { 0, x, y }; |
||
5352 | text.SPPID.SPPID_X = x; |
||
5353 | text.SPPID.SPPID_Y = y; |
||
5354 | LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
||
5355 | if (_LMLabelPersist != null) |
||
5356 | { |
||
5357 | text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id; |
||
5358 | _LMLabelPersist.Commit(); |
||
5359 | ReleaseCOMObjects(_LMLabelPersist); |
||
5360 | } |
||
5361 | 7f00b26c | gaqhf | } |
5362 | } |
||
5363 | } |
||
5364 | ea80efaa | gaqhf | } |
5365 | 6b298450 | gaqhf | } |
5366 | e27329d6 | gaqhf | else if (owner != null && owner.GetType() == typeof(Line)) |
5367 | 6b298450 | gaqhf | { |
5368 | e27329d6 | gaqhf | Line line = owner as Line; |
5369 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
||
5370 | connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y); |
||
5371 | 1299077b | gaqhf | |
5372 | e27329d6 | gaqhf | if (connectedLMConnector != null) |
5373 | 30ba9ae0 | gaqhf | { |
5374 | 8214047e | gaqhf | foreach (BaseModel.Attribute attribute in line.ATTRIBUTES.FindAll(x => x.ASSOCITEM == text.UID)) |
5375 | 30ba9ae0 | gaqhf | { |
5376 | 8214047e | gaqhf | if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
5377 | e27329d6 | gaqhf | { |
5378 | 8214047e | gaqhf | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
5379 | 1299077b | gaqhf | |
5380 | 8214047e | gaqhf | if (mapping != null) |
5381 | 1299077b | gaqhf | { |
5382 | 8214047e | gaqhf | double x = 0; |
5383 | double y = 0; |
||
5384 | CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
||
5385 | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
||
5386 | Array array = new double[] { 0, x, y }; |
||
5387 | |||
5388 | LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
||
5389 | if (_LMLabelPersist != null) |
||
5390 | 85d3b2eb | gaqhf | { |
5391 | 8214047e | gaqhf | text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id; |
5392 | _LMLabelPersist.Commit(); |
||
5393 | 85d3b2eb | gaqhf | |
5394 | 8214047e | gaqhf | DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_LMLabelPersist.get_GraphicOID().ToString()] as DependencyObject; |
5395 | if (dependency != null) |
||
5396 | { |
||
5397 | radApp.ActiveSelectSet.RemoveAll(); |
||
5398 | radApp.ActiveSelectSet.Add(dependency); |
||
5399 | Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
||
5400 | transform.DefineByMove2d(x - _LMLabelPersist.get_XCoordinate(), y - _LMLabelPersist.get_YCoordinate()); |
||
5401 | radApp.ActiveSelectSet.Transform(transform, true); |
||
5402 | radApp.ActiveSelectSet.RemoveAll(); |
||
5403 | } |
||
5404 | |||
5405 | ReleaseCOMObjects(_LMLabelPersist); |
||
5406 | } |
||
5407 | 1299077b | gaqhf | } |
5408 | 30ba9ae0 | gaqhf | } |
5409 | } |
||
5410 | } |
||
5411 | 6b298450 | gaqhf | } |
5412 | 7f00b26c | gaqhf | if (_LMSymbol != null) |
5413 | ReleaseCOMObjects(_LMSymbol); |
||
5414 | cfda1fed | gaqhf | } |
5415 | |||
5416 | e27329d6 | gaqhf | private void TextCorrectModeling(Text text) |
5417 | 1299077b | gaqhf | { |
5418 | e27329d6 | gaqhf | if (text.SPPID.Range == null) |
5419 | return; |
||
5420 | |||
5421 | 1299077b | gaqhf | bool needRemodeling = false; |
5422 | bool loop = true; |
||
5423 | GridSetting gridSetting = GridSetting.GetInstance(); |
||
5424 | while (loop) |
||
5425 | { |
||
5426 | loop = false; |
||
5427 | e27329d6 | gaqhf | foreach (var overlapText in document.TEXTINFOS) |
5428 | 1299077b | gaqhf | { |
5429 | e27329d6 | gaqhf | if (overlapText.ASSOCIATION || overlapText == text || overlapText.SPPID.Range == null) |
5430 | continue; |
||
5431 | |||
5432 | 1299077b | gaqhf | if (SPPIDUtil.IsOverlap(overlapText.SPPID.Range, text.SPPID.Range)) |
5433 | { |
||
5434 | e27329d6 | gaqhf | double percentX = 0; |
5435 | double percentY = 0; |
||
5436 | if (overlapText.X1 <= text.X2 && overlapText.X2 >= text.X1) |
||
5437 | { |
||
5438 | double gapX = Math.Min(overlapText.X2, text.X2) - Math.Max(overlapText.X1, text.X1); |
||
5439 | percentX = Math.Max(gapX / (overlapText.X2 - overlapText.X1), gapX / (text.X2 - text.X1)); |
||
5440 | } |
||
5441 | if (overlapText.Y1 <= text.Y2 && overlapText.Y2 >= text.Y1) |
||
5442 | { |
||
5443 | double gapY = Math.Min(overlapText.Y2, text.Y2) - Math.Max(overlapText.Y1, text.Y1); |
||
5444 | percentY = Math.Max(gapY / (overlapText.Y2 - overlapText.Y1), gapY / (text.Y2 - text.Y1)); |
||
5445 | } |
||
5446 | |||
5447 | 1299077b | gaqhf | double tempX = 0; |
5448 | double tempY = 0; |
||
5449 | bool overlapX = false; |
||
5450 | bool overlapY = false; |
||
5451 | SPPIDUtil.CalcOverlap(text.SPPID.Range, overlapText.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY); |
||
5452 | e27329d6 | gaqhf | if (percentX >= percentY) |
5453 | 1299077b | gaqhf | { |
5454 | int count = Convert.ToInt32(tempY / gridSetting.Length) + 1; |
||
5455 | double move = gridSetting.Length * count; |
||
5456 | text.SPPID.SPPID_Y = text.SPPID.SPPID_Y - move; |
||
5457 | text.SPPID.Range = new double[] { text.SPPID.Range[0], text.SPPID.Range[1] - move, text.SPPID.Range[2], text.SPPID.Range[3] - move }; |
||
5458 | needRemodeling = true; |
||
5459 | loop = true; |
||
5460 | } |
||
5461 | e27329d6 | gaqhf | else |
5462 | 1299077b | gaqhf | { |
5463 | int count = Convert.ToInt32(tempX / gridSetting.Length) + 1; |
||
5464 | double move = gridSetting.Length * count; |
||
5465 | text.SPPID.SPPID_X = text.SPPID.SPPID_X + move; |
||
5466 | text.SPPID.Range = new double[] { text.SPPID.Range[0] + move, text.SPPID.Range[1], text.SPPID.Range[2] + move, text.SPPID.Range[3] }; |
||
5467 | needRemodeling = true; |
||
5468 | loop = true; |
||
5469 | } |
||
5470 | } |
||
5471 | } |
||
5472 | } |
||
5473 | 2e69e97c | gaqhf | |
5474 | 1299077b | gaqhf | |
5475 | if (needRemodeling) |
||
5476 | { |
||
5477 | LMSymbol symbol = dataSource.GetSymbol(text.SPPID.RepresentationId); |
||
5478 | _placement.PIDRemovePlacement(symbol.AsLMRepresentation()); |
||
5479 | text.SPPID.RepresentationId = null; |
||
5480 | |||
5481 | LMItemNote _LMItemNote = null; |
||
5482 | LMAAttribute _LMAAttribute = null; |
||
5483 | LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.SPPID_X, text.SPPID.SPPID_Y, Rotation: text.ANGLE); |
||
5484 | if (_LMSymbol != null) |
||
5485 | { |
||
5486 | _LMSymbol.Commit(); |
||
5487 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
5488 | if (_LMItemNote != null) |
||
5489 | { |
||
5490 | _LMItemNote.Commit(); |
||
5491 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
5492 | if (_LMAAttribute != null) |
||
5493 | { |
||
5494 | _LMAAttribute.set_Value(text.VALUE); |
||
5495 | text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
5496 | _LMItemNote.Commit(); |
||
5497 | |||
5498 | ReleaseCOMObjects(_LMAAttribute); |
||
5499 | ReleaseCOMObjects(_LMItemNote); |
||
5500 | } |
||
5501 | } |
||
5502 | } |
||
5503 | |||
5504 | ReleaseCOMObjects(symbol); |
||
5505 | symbol = null; |
||
5506 | ReleaseCOMObjects(_LMItemNote); |
||
5507 | _LMItemNote = null; |
||
5508 | ReleaseCOMObjects(_LMAAttribute); |
||
5509 | _LMAAttribute = null; |
||
5510 | ReleaseCOMObjects(_LMSymbol); |
||
5511 | _LMSymbol = null; |
||
5512 | } |
||
5513 | } |
||
5514 | |||
5515 | 4e865771 | gaqhf | private void AssociationTextCorrectModeling(Text text, List<Text> endTexts) |
5516 | { |
||
5517 | if (!string.IsNullOrEmpty(text.SPPID.RepresentationId)) |
||
5518 | { |
||
5519 | 8c7fc81a | gaqhf | List<Text> allTexts = new List<Text>(); |
5520 | 4e865771 | gaqhf | LMLabelPersist targetLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId); |
5521 | LMRepresentation representation = targetLabel.RepresentationObject; |
||
5522 | Symbol symbol = document.SYMBOLS.Find(x => x.SPPID.RepresentationId == representation.Id); |
||
5523 | if (targetLabel.RepresentationObject != null && symbol != null) |
||
5524 | { |
||
5525 | double[] symbolRange = null; |
||
5526 | GetSPPIDSymbolRange(symbol, ref symbolRange, true, true); |
||
5527 | if (symbolRange != null) |
||
5528 | { |
||
5529 | foreach (LMLabelPersist labelPersist in representation.LabelPersists) |
||
5530 | { |
||
5531 | Text findText = document.TEXTINFOS.Find(x => x.SPPID.RepresentationId == labelPersist.AsLMRepresentation().Id && x.ASSOCIATION); |
||
5532 | if (findText != null) |
||
5533 | { |
||
5534 | double[] range = null; |
||
5535 | GetSPPIDSymbolRange(labelPersist, ref range); |
||
5536 | findText.SPPID.Range = range; |
||
5537 | 8c7fc81a | gaqhf | allTexts.Add(findText); |
5538 | 4e865771 | gaqhf | } |
5539 | |||
5540 | ReleaseCOMObjects(labelPersist); |
||
5541 | } |
||
5542 | |||
5543 | 8c7fc81a | gaqhf | if (allTexts.Count > 0) |
5544 | 4e865771 | gaqhf | { |
5545 | #region Sort Text By Y |
||
5546 | 8c7fc81a | gaqhf | allTexts.Sort(SortTextByY); |
5547 | 4e865771 | gaqhf | int SortTextByY(Text a, Text b) |
5548 | { |
||
5549 | return b.SPPID.Range[3].CompareTo(a.SPPID.Range[3]); |
||
5550 | } |
||
5551 | #endregion |
||
5552 | |||
5553 | 8c7fc81a | gaqhf | #region 정렬하기전 방향 |
5554 | List<Text> left = new List<Text>(); |
||
5555 | List<Text> down = new List<Text>(); |
||
5556 | List<Text> right = new List<Text>(); |
||
5557 | List<Text> up = new List<Text>(); |
||
5558 | List<List<Text>> sortTexts = new List<List<Text>>() { left, down, right, up }; |
||
5559 | foreach (var loopText in allTexts) |
||
5560 | 4e865771 | gaqhf | { |
5561 | 8c7fc81a | gaqhf | double textCenterX = (loopText.X1 + loopText.X2) / 2; |
5562 | double textCenterY = (loopText.Y1 + loopText.Y2) / 2; |
||
5563 | double originX = 0; |
||
5564 | double originY = 0; |
||
5565 | SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY); |
||
5566 | double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY); |
||
5567 | |||
5568 | if (angle < 45) |
||
5569 | { |
||
5570 | // Text 오른쪽 |
||
5571 | if (textCenterX > originX) |
||
5572 | right.Add(loopText); |
||
5573 | // Text 왼쪽 |
||
5574 | else |
||
5575 | 2e69e97c | gaqhf | left.Add(loopText); |
5576 | 8c7fc81a | gaqhf | } |
5577 | else |
||
5578 | 4e865771 | gaqhf | { |
5579 | 8c7fc81a | gaqhf | // Text 아래쪽 |
5580 | if (textCenterY > originY) |
||
5581 | down.Add(loopText); |
||
5582 | // Text 위쪽 |
||
5583 | else |
||
5584 | up.Add(loopText); |
||
5585 | 4e865771 | gaqhf | } |
5586 | } |
||
5587 | 2e69e97c | gaqhf | |
5588 | 4e865771 | gaqhf | #endregion |
5589 | |||
5590 | 8c7fc81a | gaqhf | foreach (var texts in sortTexts) |
5591 | 4e865771 | gaqhf | { |
5592 | 2e69e97c | gaqhf | if (texts.Count == 0) |
5593 | 8c7fc81a | gaqhf | continue; |
5594 | 2e69e97c | gaqhf | |
5595 | 8c7fc81a | gaqhf | #region 첫번째 Text로 기준 맞춤 |
5596 | for (int i = 0; i < texts.Count; i++) |
||
5597 | 4e865771 | gaqhf | { |
5598 | 8c7fc81a | gaqhf | if (i != 0) |
5599 | { |
||
5600 | Text currentText = texts[i]; |
||
5601 | Text prevText = texts[i - 1]; |
||
5602 | double minY = prevText.SPPID.Range[1]; |
||
5603 | double centerPrevX = (prevText.SPPID.Range[0] + prevText.SPPID.Range[2]) / 2; |
||
5604 | double centerX = (currentText.SPPID.Range[0] + currentText.SPPID.Range[2]) / 2; |
||
5605 | double _gapX = centerX - centerPrevX; |
||
5606 | double _gapY = currentText.SPPID.Range[3] - minY; |
||
5607 | MoveText(currentText, _gapX, _gapY); |
||
5608 | } |
||
5609 | 4e865771 | gaqhf | } |
5610 | 8c7fc81a | gaqhf | List<double> rangeMinX = texts.Select(loopX => loopX.SPPID.Range[0]).ToList(); |
5611 | List<double> rangeMinY = texts.Select(loopX => loopX.SPPID.Range[1]).ToList(); |
||
5612 | List<double> rangeMaxX = texts.Select(loopX => loopX.SPPID.Range[2]).ToList(); |
||
5613 | List<double> rangeMaxY = texts.Select(loopX => loopX.SPPID.Range[3]).ToList(); |
||
5614 | rangeMinX.Sort(); |
||
5615 | rangeMinY.Sort(); |
||
5616 | rangeMaxX.Sort(); |
||
5617 | rangeMaxY.Sort(); |
||
5618 | double allTextCenterX = (rangeMinX[0] + rangeMaxX[rangeMaxX.Count - 1]) / 2; |
||
5619 | double allTextCenterY = (rangeMinY[0] + rangeMaxY[rangeMaxY.Count - 1]) / 2; |
||
5620 | #endregion |
||
5621 | #region 정렬 |
||
5622 | Text correctBySymbol = texts[0]; |
||
5623 | double textCenterX = (correctBySymbol.X1 + correctBySymbol.X2) / 2; |
||
5624 | double textCenterY = (correctBySymbol.Y1 + correctBySymbol.Y2) / 2; |
||
5625 | double originX = 0; |
||
5626 | double originY = 0; |
||
5627 | SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY); |
||
5628 | double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY); |
||
5629 | double symbolCenterX = (symbolRange[0] + symbolRange[2]) / 2; |
||
5630 | double symbolCenterY = (symbolRange[1] + symbolRange[3]) / 2; |
||
5631 | |||
5632 | double gapX = 0; |
||
5633 | double gapY = 0; |
||
5634 | if (angle < 45) |
||
5635 | 4e865771 | gaqhf | { |
5636 | 8c7fc81a | gaqhf | // Text 오른쪽 |
5637 | if (textCenterX > originX) |
||
5638 | { |
||
5639 | gapX = rangeMinX[0] - symbolRange[2]; |
||
5640 | gapY = allTextCenterY - symbolCenterY; |
||
5641 | } |
||
5642 | // Text 왼쪽 |
||
5643 | else |
||
5644 | { |
||
5645 | gapX = rangeMaxX[rangeMaxX.Count - 1] - symbolRange[0]; |
||
5646 | gapY = allTextCenterY - symbolCenterY; |
||
5647 | } |
||
5648 | 4e865771 | gaqhf | } |
5649 | else |
||
5650 | { |
||
5651 | 8c7fc81a | gaqhf | // Text 아래쪽 |
5652 | if (textCenterY > originY) |
||
5653 | { |
||
5654 | gapX = allTextCenterX - symbolCenterX; |
||
5655 | gapY = rangeMaxY[rangeMaxY.Count - 1] - symbolRange[1]; |
||
5656 | } |
||
5657 | // Text 위쪽 |
||
5658 | else |
||
5659 | { |
||
5660 | gapX = allTextCenterX - symbolCenterX; |
||
5661 | gapY = rangeMinY[0] - symbolRange[3]; |
||
5662 | } |
||
5663 | 4e865771 | gaqhf | } |
5664 | |||
5665 | 8c7fc81a | gaqhf | foreach (var item in texts) |
5666 | { |
||
5667 | MoveText(item, gapX, gapY); |
||
5668 | RemodelingAssociationText(item); |
||
5669 | } |
||
5670 | #endregion |
||
5671 | 4e865771 | gaqhf | } |
5672 | } |
||
5673 | } |
||
5674 | } |
||
5675 | |||
5676 | void MoveText(Text moveText, double x, double y) |
||
5677 | { |
||
5678 | moveText.SPPID.SPPID_X = moveText.SPPID.SPPID_X - x; |
||
5679 | moveText.SPPID.SPPID_Y = moveText.SPPID.SPPID_Y - y; |
||
5680 | moveText.SPPID.Range = new double[] { |
||
5681 | moveText.SPPID.Range[0] - x, |
||
5682 | moveText.SPPID.Range[1]- y, |
||
5683 | moveText.SPPID.Range[2]- x, |
||
5684 | moveText.SPPID.Range[3]- y |
||
5685 | }; |
||
5686 | } |
||
5687 | |||
5688 | 8c7fc81a | gaqhf | endTexts.AddRange(allTexts); |
5689 | 4e865771 | gaqhf | |
5690 | ReleaseCOMObjects(targetLabel); |
||
5691 | targetLabel = null; |
||
5692 | ReleaseCOMObjects(representation); |
||
5693 | representation = null; |
||
5694 | } |
||
5695 | } |
||
5696 | |||
5697 | private void RemodelingAssociationText(Text text) |
||
5698 | { |
||
5699 | LMLabelPersist removeLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId); |
||
5700 | _placement.PIDRemovePlacement(removeLabel.AsLMRepresentation()); |
||
5701 | removeLabel.Commit(); |
||
5702 | ReleaseCOMObjects(removeLabel); |
||
5703 | removeLabel = null; |
||
5704 | |||
5705 | object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
||
5706 | if (owner != null && owner.GetType() == typeof(Symbol)) |
||
5707 | { |
||
5708 | Symbol symbol = owner as Symbol; |
||
5709 | _LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
5710 | if (_LMSymbol != null) |
||
5711 | { |
||
5712 | BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID); |
||
5713 | if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
||
5714 | { |
||
5715 | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
||
5716 | |||
5717 | if (mapping != null) |
||
5718 | { |
||
5719 | double x = 0; |
||
5720 | double y = 0; |
||
5721 | |||
5722 | Array array = new double[] { 0, text.SPPID.SPPID_X, text.SPPID.SPPID_Y }; |
||
5723 | LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
||
5724 | if (_LMLabelPersist != null) |
||
5725 | { |
||
5726 | text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id; |
||
5727 | _LMLabelPersist.Commit(); |
||
5728 | } |
||
5729 | ReleaseCOMObjects(_LMLabelPersist); |
||
5730 | _LMLabelPersist = null; |
||
5731 | } |
||
5732 | } |
||
5733 | } |
||
5734 | ReleaseCOMObjects(_LMSymbol); |
||
5735 | _LMSymbol = null; |
||
5736 | } |
||
5737 | } |
||
5738 | |||
5739 | 74752074 | gaqhf | /// <summary> |
5740 | /// Note Modeling |
||
5741 | /// </summary> |
||
5742 | /// <param name="note"></param> |
||
5743 | 1299077b | gaqhf | private void NoteModeling(Note note, List<Note> correctList) |
5744 | cfda1fed | gaqhf | { |
5745 | 6b298450 | gaqhf | LMSymbol _LMSymbol = null; |
5746 | LMItemNote _LMItemNote = null; |
||
5747 | LMAAttribute _LMAAttribute = null; |
||
5748 | |||
5749 | 7f00b26c | gaqhf | if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None") |
5750 | 6b298450 | gaqhf | { |
5751 | 7f00b26c | gaqhf | double x = 0; |
5752 | double y = 0; |
||
5753 | fc0a8c33 | gaqhf | |
5754 | 7f00b26c | gaqhf | CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation); |
5755 | 1299077b | gaqhf | SPPIDUtil.ConvertGridPoint(ref x, ref y); |
5756 | note.SPPID.SPPID_X = x; |
||
5757 | note.SPPID.SPPID_Y = y; |
||
5758 | fc0a8c33 | gaqhf | |
5759 | 7f00b26c | gaqhf | _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y); |
5760 | 30ba9ae0 | gaqhf | if (_LMSymbol != null) |
5761 | { |
||
5762 | _LMSymbol.Commit(); |
||
5763 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
5764 | if (_LMItemNote != null) |
||
5765 | { |
||
5766 | _LMItemNote.Commit(); |
||
5767 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
5768 | if (_LMAAttribute != null) |
||
5769 | { |
||
5770 | _LMAAttribute.set_Value(note.VALUE); |
||
5771 | note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
5772 | 1299077b | gaqhf | |
5773 | double[] range = null; |
||
5774 | foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists) |
||
5775 | { |
||
5776 | double[] temp = null; |
||
5777 | GetSPPIDSymbolRange(labelPersist, ref temp); |
||
5778 | if (temp != null) |
||
5779 | { |
||
5780 | if (range == null) |
||
5781 | range = temp; |
||
5782 | else |
||
5783 | { |
||
5784 | range = new double[] { |
||
5785 | Math.Min(range[0], temp[0]), |
||
5786 | Math.Min(range[1], temp[1]), |
||
5787 | Math.Max(range[2], temp[2]), |
||
5788 | Math.Max(range[3], temp[3]) |
||
5789 | }; |
||
5790 | } |
||
5791 | } |
||
5792 | } |
||
5793 | if (range != null) |
||
5794 | correctList.Add(note); |
||
5795 | note.SPPID.Range = range; |
||
5796 | |||
5797 | |||
5798 | 30ba9ae0 | gaqhf | _LMItemNote.Commit(); |
5799 | } |
||
5800 | } |
||
5801 | } |
||
5802 | 6b298450 | gaqhf | } |
5803 | cfda1fed | gaqhf | |
5804 | 7f00b26c | gaqhf | if (_LMAAttribute != null) |
5805 | ReleaseCOMObjects(_LMAAttribute); |
||
5806 | if (_LMItemNote != null) |
||
5807 | ReleaseCOMObjects(_LMItemNote); |
||
5808 | if (_LMSymbol != null) |
||
5809 | ReleaseCOMObjects(_LMSymbol); |
||
5810 | cfda1fed | gaqhf | } |
5811 | |||
5812 | 1299077b | gaqhf | private void NoteCorrectModeling(Note note, List<Note> endList) |
5813 | { |
||
5814 | bool needRemodeling = false; |
||
5815 | bool loop = true; |
||
5816 | GridSetting gridSetting = GridSetting.GetInstance(); |
||
5817 | while (loop) |
||
5818 | { |
||
5819 | loop = false; |
||
5820 | foreach (var overlap in endList) |
||
5821 | { |
||
5822 | ba25c427 | gaqhf | if (SPPIDUtil.IsOverlap(overlap.SPPID.Range, note.SPPID.Range)) |
5823 | 1299077b | gaqhf | { |
5824 | ba25c427 | gaqhf | double tempX = 0; |
5825 | double tempY = 0; |
||
5826 | bool overlapX = false; |
||
5827 | bool overlapY = false; |
||
5828 | SPPIDUtil.CalcOverlap(note.SPPID.Range, overlap.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY); |
||
5829 | double angle = SPPIDUtil.CalcAngle(note.LOCATION_X, note.LOCATION_Y, overlap.LOCATION_X, overlap.LOCATION_Y); |
||
5830 | if (overlapY && angle >= 45) |
||
5831 | 1299077b | gaqhf | { |
5832 | ba25c427 | gaqhf | int count = Convert.ToInt32(tempY / gridSetting.Length) + 1; |
5833 | double move = gridSetting.Length * count; |
||
5834 | note.SPPID.SPPID_Y = note.SPPID.SPPID_Y - move; |
||
5835 | note.SPPID.Range = new double[] { note.SPPID.Range[0], note.SPPID.Range[1] - move, note.SPPID.Range[2], note.SPPID.Range[3] - move }; |
||
5836 | needRemodeling = true; |
||
5837 | loop = true; |
||
5838 | } |
||
5839 | if (overlapX && angle <= 45) |
||
5840 | { |
||
5841 | int count = Convert.ToInt32(tempX / gridSetting.Length) + 1; |
||
5842 | double move = gridSetting.Length * count; |
||
5843 | note.SPPID.SPPID_X = note.SPPID.SPPID_X + move; |
||
5844 | note.SPPID.Range = new double[] { note.SPPID.Range[0] + move, note.SPPID.Range[1], note.SPPID.Range[2] + move, note.SPPID.Range[3] }; |
||
5845 | needRemodeling = true; |
||
5846 | loop = true; |
||
5847 | 1299077b | gaqhf | } |
5848 | } |
||
5849 | } |
||
5850 | } |
||
5851 | |||
5852 | |||
5853 | if (needRemodeling) |
||
5854 | { |
||
5855 | LMSymbol symbol = dataSource.GetSymbol(note.SPPID.RepresentationId); |
||
5856 | _placement.PIDRemovePlacement(symbol.AsLMRepresentation()); |
||
5857 | note.SPPID.RepresentationId = null; |
||
5858 | |||
5859 | LMItemNote _LMItemNote = null; |
||
5860 | LMAAttribute _LMAAttribute = null; |
||
5861 | LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.SPPID_X, note.SPPID.SPPID_Y, Rotation: note.ANGLE); |
||
5862 | if (_LMSymbol != null) |
||
5863 | { |
||
5864 | _LMSymbol.Commit(); |
||
5865 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
5866 | if (_LMItemNote != null) |
||
5867 | { |
||
5868 | _LMItemNote.Commit(); |
||
5869 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
5870 | if (_LMAAttribute != null) |
||
5871 | { |
||
5872 | _LMAAttribute.set_Value(note.VALUE); |
||
5873 | note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
5874 | _LMItemNote.Commit(); |
||
5875 | |||
5876 | ReleaseCOMObjects(_LMAAttribute); |
||
5877 | ReleaseCOMObjects(_LMItemNote); |
||
5878 | } |
||
5879 | } |
||
5880 | } |
||
5881 | |||
5882 | ReleaseCOMObjects(symbol); |
||
5883 | symbol = null; |
||
5884 | ReleaseCOMObjects(_LMItemNote); |
||
5885 | _LMItemNote = null; |
||
5886 | ReleaseCOMObjects(_LMAAttribute); |
||
5887 | _LMAAttribute = null; |
||
5888 | ReleaseCOMObjects(_LMSymbol); |
||
5889 | _LMSymbol = null; |
||
5890 | } |
||
5891 | |||
5892 | endList.Add(note); |
||
5893 | } |
||
5894 | |||
5895 | a31a512e | gaqhf | private void JoinRunBySameType(string modelItemId, ref string survivorId) |
5896 | ca6e0f51 | gaqhf | { |
5897 | a31a512e | gaqhf | LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
5898 | if (modelItem != null) |
||
5899 | ca6e0f51 | gaqhf | { |
5900 | a31a512e | gaqhf | foreach (LMRepresentation rep in modelItem.Representations) |
5901 | { |
||
5902 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
5903 | { |
||
5904 | LMConnector connector = dataSource.GetConnector(rep.Id); |
||
5905 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
||
5906 | { |
||
5907 | LMSymbol symbol = connector.ConnectItem1SymbolObject; |
||
5908 | List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
||
5909 | if (modelItemIds.Count == 1) |
||
5910 | { |
||
5911 | d77973b3 | gaqhf | string joinModelItemId = modelItemIds[0]; |
5912 | 63a112d9 | gaqhf | JoinRun(joinModelItemId, modelItemId, ref survivorId, false); |
5913 | a31a512e | gaqhf | if (survivorId != null) |
5914 | break; |
||
5915 | } |
||
5916 | } |
||
5917 | if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
||
5918 | { |
||
5919 | LMSymbol symbol = connector.ConnectItem2SymbolObject; |
||
5920 | List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
||
5921 | if (modelItemIds.Count == 1) |
||
5922 | { |
||
5923 | d77973b3 | gaqhf | string joinModelItemId = modelItemIds[0]; |
5924 | 63a112d9 | gaqhf | JoinRun(joinModelItemId, modelItemId, ref survivorId, false); |
5925 | a31a512e | gaqhf | if (survivorId != null) |
5926 | break; |
||
5927 | } |
||
5928 | } |
||
5929 | } |
||
5930 | } |
||
5931 | ca6e0f51 | gaqhf | } |
5932 | dec9ecfd | gaqhf | } |
5933 | |||
5934 | d9794a6c | gaqhf | /// <summary> |
5935 | 74752074 | gaqhf | /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표) |
5936 | /// </summary> |
||
5937 | /// <param name="x"></param> |
||
5938 | /// <param name="y"></param> |
||
5939 | /// <param name="originX"></param> |
||
5940 | /// <param name="originY"></param> |
||
5941 | /// <param name="SPPIDLabelLocation"></param> |
||
5942 | /// <param name="location"></param> |
||
5943 | b65a7e32 | gaqhf | private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location) |
5944 | { |
||
5945 | if (location == Location.None) |
||
5946 | { |
||
5947 | x = originX; |
||
5948 | y = originY; |
||
5949 | } |
||
5950 | else |
||
5951 | { |
||
5952 | if (location.HasFlag(Location.Center)) |
||
5953 | { |
||
5954 | x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2; |
||
5955 | y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2; |
||
5956 | } |
||
5957 | |||
5958 | if (location.HasFlag(Location.Left)) |
||
5959 | x = SPPIDLabelLocation.X1; |
||
5960 | else if (location.HasFlag(Location.Right)) |
||
5961 | x = SPPIDLabelLocation.X2; |
||
5962 | |||
5963 | if (location.HasFlag(Location.Down)) |
||
5964 | y = SPPIDLabelLocation.Y1; |
||
5965 | else if (location.HasFlag(Location.Up)) |
||
5966 | y = SPPIDLabelLocation.Y2; |
||
5967 | } |
||
5968 | } |
||
5969 | 5a4b8f32 | gaqhf | |
5970 | 74752074 | gaqhf | /// <summary> |
5971 | 4d2571ab | gaqhf | /// Symbol의 우선순위 Modeling 목록을 가져온다. |
5972 | /// 1. Angle Valve |
||
5973 | /// 2. 3개로 이루어진 Symbol Group |
||
5974 | /// </summary> |
||
5975 | /// <returns></returns> |
||
5976 | private List<Symbol> GetPrioritySymbol() |
||
5977 | { |
||
5978 | DataTable symbolTable = document.SymbolTable; |
||
5979 | // List에 순서대로 쌓는다. |
||
5980 | List<Symbol> symbols = new List<Symbol>(); |
||
5981 | 3734dcc5 | gaqhf | |
5982 | 4d2571ab | gaqhf | // Angle Valve 부터 |
5983 | d9794a6c | gaqhf | foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2)) |
5984 | 4d2571ab | gaqhf | { |
5985 | if (!symbols.Contains(symbol)) |
||
5986 | { |
||
5987 | double originX = 0; |
||
5988 | double originY = 0; |
||
5989 | |||
5990 | // ID2 Table에서 Original Point 가져옴. |
||
5991 | 7f00b26c | gaqhf | string OriginalPoint = symbolTable.Select(string.Format("UID = {0}", symbol.DBUID))[0]["OriginalPoint"].ToString(); |
5992 | 4d2571ab | gaqhf | SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY); |
5993 | |||
5994 | SlopeType slopeType1 = SlopeType.None; |
||
5995 | SlopeType slopeType2 = SlopeType.None; |
||
5996 | d9794a6c | gaqhf | foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0)) |
5997 | 4d2571ab | gaqhf | { |
5998 | double connectorX = 0; |
||
5999 | double connectorY = 0; |
||
6000 | SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY); |
||
6001 | if (slopeType1 == SlopeType.None) |
||
6002 | slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
||
6003 | else |
||
6004 | slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
||
6005 | } |
||
6006 | |||
6007 | if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) || |
||
6008 | (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL)) |
||
6009 | symbols.Add(symbol); |
||
6010 | } |
||
6011 | } |
||
6012 | |||
6013 | f1a7faf9 | gaqhf | List<Symbol> tempSymbols = new List<Symbol>(); |
6014 | // Conn 갯수 기준 |
||
6015 | d9794a6c | gaqhf | foreach (var item in document.SYMBOLS) |
6016 | { |
||
6017 | f1a7faf9 | gaqhf | if (!symbols.Contains(item)) |
6018 | tempSymbols.Add(item); |
||
6019 | d9794a6c | gaqhf | } |
6020 | f1a7faf9 | gaqhf | tempSymbols.Sort(SortSymbolPriority); |
6021 | symbols.AddRange(tempSymbols); |
||
6022 | 4d2571ab | gaqhf | |
6023 | return symbols; |
||
6024 | } |
||
6025 | |||
6026 | cf210438 | gaqhf | private void SetPriorityLine(List<Line> lines) |
6027 | d63050d6 | gaqhf | { |
6028 | cf210438 | gaqhf | lines.Sort(SortLinePriority); |
6029 | d63050d6 | gaqhf | |
6030 | int SortLinePriority(Line a, Line b) |
||
6031 | { |
||
6032 | // Branch 없는것부터 |
||
6033 | int branchRetval = CompareBranchLine(a, b); |
||
6034 | if (branchRetval != 0) |
||
6035 | { |
||
6036 | return branchRetval; |
||
6037 | } |
||
6038 | else |
||
6039 | { |
||
6040 | // Symbol 연결 갯수 |
||
6041 | int connSymbolRetval = CompareConnSymbol(a, b); |
||
6042 | if (connSymbolRetval != 0) |
||
6043 | { |
||
6044 | return connSymbolRetval; |
||
6045 | } |
||
6046 | else |
||
6047 | { |
||
6048 | 24515a3a | gaqhf | // 아이템 연결 갯수(심볼, Line이면서 Not Branch) |
6049 | int connItemRetval = CompareConnItem(a, b); |
||
6050 | if (connItemRetval != 0) |
||
6051 | d63050d6 | gaqhf | { |
6052 | 24515a3a | gaqhf | return connItemRetval; |
6053 | d63050d6 | gaqhf | } |
6054 | else |
||
6055 | { |
||
6056 | 24515a3a | gaqhf | // ConnectedItem이 없는것 |
6057 | int noneConnRetval = CompareNoneConn(a, b); |
||
6058 | if (noneConnRetval != 0) |
||
6059 | d63050d6 | gaqhf | { |
6060 | 24515a3a | gaqhf | return noneConnRetval; |
6061 | d63050d6 | gaqhf | } |
6062 | else |
||
6063 | { |
||
6064 | |||
6065 | } |
||
6066 | } |
||
6067 | } |
||
6068 | } |
||
6069 | |||
6070 | return 0; |
||
6071 | } |
||
6072 | |||
6073 | e283d483 | gaqhf | int CompareNotSegmentLine(Line a, Line b) |
6074 | { |
||
6075 | List<Connector> connectorsA = a.CONNECTORS |
||
6076 | .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol)) |
||
6077 | .ToList(); |
||
6078 | |||
6079 | List<Connector> connectorsB = b.CONNECTORS |
||
6080 | .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol)) |
||
6081 | .ToList(); |
||
6082 | |||
6083 | // 오름차순 |
||
6084 | return connectorsB.Count.CompareTo(connectorsA.Count); |
||
6085 | } |
||
6086 | |||
6087 | d63050d6 | gaqhf | int CompareConnSymbol(Line a, Line b) |
6088 | { |
||
6089 | List<Connector> connectorsA = a.CONNECTORS |
||
6090 | .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol)) |
||
6091 | .ToList(); |
||
6092 | |||
6093 | List<Connector> connectorsB = b.CONNECTORS |
||
6094 | .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol)) |
||
6095 | .ToList(); |
||
6096 | |||
6097 | // 오름차순 |
||
6098 | return connectorsB.Count.CompareTo(connectorsA.Count); |
||
6099 | } |
||
6100 | |||
6101 | int CompareConnItem(Line a, Line b) |
||
6102 | { |
||
6103 | List<Connector> connectorsA = a.CONNECTORS |
||
6104 | 2e69e97c | gaqhf | .Where(conn => conn.ConnectedObject != null && |
6105 | (conn.ConnectedObject.GetType() == typeof(Symbol) || |
||
6106 | d63050d6 | gaqhf | (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a)))) |
6107 | .ToList(); |
||
6108 | |||
6109 | List<Connector> connectorsB = b.CONNECTORS |
||
6110 | .Where(conn => conn.ConnectedObject != null && |
||
6111 | (conn.ConnectedObject.GetType() == typeof(Symbol) || |
||
6112 | (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b)))) |
||
6113 | .ToList(); |
||
6114 | |||
6115 | // 오름차순 |
||
6116 | return connectorsB.Count.CompareTo(connectorsA.Count); |
||
6117 | } |
||
6118 | |||
6119 | int CompareBranchLine(Line a, Line b) |
||
6120 | { |
||
6121 | List<Connector> connectorsA = a.CONNECTORS |
||
6122 | .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line)) |
||
6123 | .ToList(); |
||
6124 | List<Connector> connectorsB = b.CONNECTORS |
||
6125 | .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line)) |
||
6126 | .ToList(); |
||
6127 | |||
6128 | // 내림차순 |
||
6129 | return connectorsA.Count.CompareTo(connectorsB.Count); |
||
6130 | } |
||
6131 | |||
6132 | int CompareNoneConn(Line a, Line b) |
||
6133 | { |
||
6134 | List<Connector> connectorsA = a.CONNECTORS |
||
6135 | .Where(conn => conn.ConnectedObject == null) |
||
6136 | .ToList(); |
||
6137 | |||
6138 | List<Connector> connectorsB = b.CONNECTORS |
||
6139 | .Where(conn => conn.ConnectedObject == null) |
||
6140 | .ToList(); |
||
6141 | |||
6142 | // 오름차순 |
||
6143 | return connectorsB.Count.CompareTo(connectorsA.Count); |
||
6144 | } |
||
6145 | } |
||
6146 | |||
6147 | 1299077b | gaqhf | private void SortText(List<Text> texts) |
6148 | { |
||
6149 | texts.Sort(Sort); |
||
6150 | |||
6151 | int Sort(Text a, Text b) |
||
6152 | { |
||
6153 | int yRetval = CompareY(a, b); |
||
6154 | if (yRetval != 0) |
||
6155 | { |
||
6156 | return yRetval; |
||
6157 | } |
||
6158 | else |
||
6159 | { |
||
6160 | return CompareX(a, b); |
||
6161 | } |
||
6162 | } |
||
6163 | |||
6164 | int CompareY(Text a, Text b) |
||
6165 | { |
||
6166 | return a.LOCATION_Y.CompareTo(b.LOCATION_Y); |
||
6167 | } |
||
6168 | |||
6169 | int CompareX(Text a, Text b) |
||
6170 | { |
||
6171 | return a.LOCATION_X.CompareTo(b.LOCATION_X); |
||
6172 | } |
||
6173 | } |
||
6174 | private void SortNote(List<Note> notes) |
||
6175 | { |
||
6176 | notes.Sort(Sort); |
||
6177 | |||
6178 | int Sort(Note a, Note b) |
||
6179 | { |
||
6180 | int yRetval = CompareY(a, b); |
||
6181 | if (yRetval != 0) |
||
6182 | { |
||
6183 | return yRetval; |
||
6184 | } |
||
6185 | else |
||
6186 | { |
||
6187 | return CompareX(a, b); |
||
6188 | } |
||
6189 | } |
||
6190 | |||
6191 | int CompareY(Note a, Note b) |
||
6192 | { |
||
6193 | return a.LOCATION_Y.CompareTo(b.LOCATION_Y); |
||
6194 | } |
||
6195 | |||
6196 | int CompareX(Note a, Note b) |
||
6197 | { |
||
6198 | return a.LOCATION_X.CompareTo(b.LOCATION_X); |
||
6199 | } |
||
6200 | } |
||
6201 | |||
6202 | a0e3dca4 | gaqhf | private void SortBranchLines() |
6203 | { |
||
6204 | f3e2693f | gaqhf | BranchLines.Sort(SortBranchLine); |
6205 | a0e3dca4 | gaqhf | int SortBranchLine(Line a, Line b) |
6206 | { |
||
6207 | int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null && |
||
6208 | x.ConnectedObject.GetType() == typeof(Line) && |
||
6209 | SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) && |
||
6210 | string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count; |
||
6211 | |||
6212 | int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null && |
||
6213 | x.ConnectedObject.GetType() == typeof(Line) && |
||
6214 | SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) && |
||
6215 | string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count; |
||
6216 | |||
6217 | // 내림차순 |
||
6218 | return countA.CompareTo(countB); |
||
6219 | } |
||
6220 | } |
||
6221 | |||
6222 | f1a7faf9 | gaqhf | private static int SortSymbolPriority(Symbol a, Symbol b) |
6223 | { |
||
6224 | int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count; |
||
6225 | int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count; |
||
6226 | int retval = countB.CompareTo(countA); |
||
6227 | if (retval != 0) |
||
6228 | return retval; |
||
6229 | else |
||
6230 | return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X); |
||
6231 | } |
||
6232 | |||
6233 | a31a512e | gaqhf | private string GetSPPIDFileName(LMModelItem modelItem) |
6234 | { |
||
6235 | string symbolPath = null; |
||
6236 | foreach (LMRepresentation rep in modelItem.Representations) |
||
6237 | { |
||
6238 | if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
||
6239 | { |
||
6240 | symbolPath = rep.get_FileName(); |
||
6241 | break; |
||
6242 | } |
||
6243 | } |
||
6244 | return symbolPath; |
||
6245 | } |
||
6246 | |||
6247 | 82d6e5ea | gaqhf | private string GetSPPIDFileName(string modelItemId) |
6248 | { |
||
6249 | LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
||
6250 | string symbolPath = null; |
||
6251 | foreach (LMRepresentation rep in modelItem.Representations) |
||
6252 | { |
||
6253 | if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
||
6254 | { |
||
6255 | symbolPath = rep.get_FileName(); |
||
6256 | break; |
||
6257 | } |
||
6258 | } |
||
6259 | ReleaseCOMObjects(modelItem); |
||
6260 | return symbolPath; |
||
6261 | } |
||
6262 | |||
6263 | 4d2571ab | gaqhf | /// <summary> |
6264 | b2d1c1aa | gaqhf | /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom |
6265 | /// </summary> |
||
6266 | /// <param name="graphicOID"></param> |
||
6267 | /// <param name="milliseconds"></param> |
||
6268 | private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150) |
||
6269 | { |
||
6270 | if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null) |
||
6271 | { |
||
6272 | double minX = 0; |
||
6273 | double minY = 0; |
||
6274 | double maxX = 0; |
||
6275 | double maxY = 0; |
||
6276 | radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY); |
||
6277 | radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null); |
||
6278 | |||
6279 | Thread.Sleep(milliseconds); |
||
6280 | } |
||
6281 | } |
||
6282 | |||
6283 | /// <summary> |
||
6284 | 74752074 | gaqhf | /// ComObject를 Release |
6285 | /// </summary> |
||
6286 | /// <param name="objVars"></param> |
||
6287 | 5a4b8f32 | gaqhf | public void ReleaseCOMObjects(params object[] objVars) |
6288 | { |
||
6289 | 02a45794 | gaqhf | if (objVars != null) |
6290 | 5a4b8f32 | gaqhf | { |
6291 | 02a45794 | gaqhf | int intNewRefCount = 0; |
6292 | foreach (object obj in objVars) |
||
6293 | { |
||
6294 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
6295 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
6296 | } |
||
6297 | 5a4b8f32 | gaqhf | } |
6298 | } |
||
6299 | 5a9396ae | humkyung | |
6300 | /// IDisposable 구현 |
||
6301 | ~AutoModeling() |
||
6302 | { |
||
6303 | this.Dispose(false); |
||
6304 | } |
||
6305 | |||
6306 | private bool disposed; |
||
6307 | public void Dispose() |
||
6308 | { |
||
6309 | this.Dispose(true); |
||
6310 | GC.SuppressFinalize(this); |
||
6311 | } |
||
6312 | |||
6313 | protected virtual void Dispose(bool disposing) |
||
6314 | { |
||
6315 | if (this.disposed) return; |
||
6316 | if (disposing) |
||
6317 | { |
||
6318 | // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다. |
||
6319 | } |
||
6320 | // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다. |
||
6321 | this.disposed = true; |
||
6322 | } |
||
6323 | cfda1fed | gaqhf | } |
6324 | } |