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