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