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