hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 3165c259
이력 | 보기 | 이력해설 | 다운로드 (43.4 KB)
1 | cfda1fed | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using Llama; |
||
7 | using Plaice; |
||
8 | 8aa6f2db | gaqhf | using Ingr.RAD2D.Interop.RAD2D; |
9 | using Ingr.RAD2D.Internal; |
||
10 | using Ingr.RAD2D.Helper; |
||
11 | cfda1fed | gaqhf | using Converter.BaseModel; |
12 | using Converter.SPPID.Model; |
||
13 | using Converter.SPPID.Properties; |
||
14 | using Converter.SPPID.Util; |
||
15 | using Converter.SPPID.DB; |
||
16 | 5e6ecf05 | gaqhf | using Ingr.RAD2D.MacroControls.CmdCtrl; |
17 | using Ingr.RAD2D; |
||
18 | 5dfb8a24 | gaqhf | using System.Windows; |
19 | cfda1fed | gaqhf | using System.Threading; |
20 | 5dfb8a24 | gaqhf | using System.Drawing; |
21 | cfda1fed | gaqhf | using Microsoft.VisualBasic; |
22 | using Newtonsoft.Json; |
||
23 | |||
24 | namespace Converter.SPPID |
||
25 | { |
||
26 | public class AutoModeling |
||
27 | { |
||
28 | 809a7640 | gaqhf | Placement _placement; |
29 | LMADataSource dataSource; |
||
30 | 5e6ecf05 | gaqhf | Ingr.RAD2D.Application radApp; |
31 | cfda1fed | gaqhf | SPPID_Document document; |
32 | f1c9dbaa | gaqhf | |
33 | 3165c259 | gaqhf | List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>(); |
34 | 5e6ecf05 | gaqhf | public AutoModeling(SPPID_Document document, Ingr.RAD2D.Application radApp) |
35 | cfda1fed | gaqhf | { |
36 | this.document = document; |
||
37 | 5e6ecf05 | gaqhf | this.radApp = radApp; |
38 | cfda1fed | gaqhf | } |
39 | |||
40 | public void Run() |
||
41 | { |
||
42 | 809a7640 | gaqhf | _placement = new Placement(); |
43 | dataSource = _placement.PIDDataSource; |
||
44 | 5dfb8a24 | gaqhf | //dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
45 | //dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName); |
||
46 | //application.ActiveWindow.Fit(); |
||
47 | //Thread.Sleep(100); |
||
48 | //application.ActiveWindow.Zoom = 60; |
||
49 | //Thread.Sleep(100); |
||
50 | 5e6ecf05 | gaqhf | try |
51 | 5dfb8a24 | gaqhf | { |
52 | 5e6ecf05 | gaqhf | foreach (Equipment equipment in document.Equipments) |
53 | 5dfb8a24 | gaqhf | { |
54 | 5e6ecf05 | gaqhf | SymbolModeling(equipment as Symbol, null, null); |
55 | 8aa6f2db | gaqhf | } |
56 | |||
57 | 5e6ecf05 | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
58 | { |
||
59 | foreach (LineRun run in lineNumber.RUNS) |
||
60 | { |
||
61 | SymbolModelingByRun(run); |
||
62 | } |
||
63 | } |
||
64 | 8aa6f2db | gaqhf | |
65 | 5e6ecf05 | gaqhf | foreach (TrimLine trimLine in document.TRIMLINES) |
66 | 8aa6f2db | gaqhf | { |
67 | 5e6ecf05 | gaqhf | foreach (LineRun run in trimLine.RUNS) |
68 | { |
||
69 | SymbolModelingByRun(run); |
||
70 | } |
||
71 | 8aa6f2db | gaqhf | } |
72 | |||
73 | 5e6ecf05 | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
74 | 8aa6f2db | gaqhf | { |
75 | 5e6ecf05 | gaqhf | foreach (LineRun run in lineNumber.RUNS) |
76 | { |
||
77 | LineModelingByRun(run); |
||
78 | } |
||
79 | 8aa6f2db | gaqhf | } |
80 | 809a7640 | gaqhf | |
81 | 5e6ecf05 | gaqhf | foreach (TrimLine trimLine in document.TRIMLINES) |
82 | 8aa6f2db | gaqhf | { |
83 | 5e6ecf05 | gaqhf | foreach (LineRun run in trimLine.RUNS) |
84 | { |
||
85 | LineModelingByRun(run); |
||
86 | } |
||
87 | 809a7640 | gaqhf | } |
88 | 335b7a24 | gaqhf | |
89 | 3165c259 | gaqhf | foreach (var item in BranchLines) |
90 | 335b7a24 | gaqhf | { |
91 | BranchLineModeling(item); |
||
92 | } |
||
93 | |||
94 | 3165c259 | gaqhf | foreach (var item in document.EndBreaks) |
95 | { |
||
96 | EndBreakModeling(item); |
||
97 | } |
||
98 | 335b7a24 | gaqhf | |
99 | |||
100 | 8b085570 | gaqhf | |
101 | 3165c259 | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
102 | { |
||
103 | |||
104 | foreach (LineRun run in lineNumber.RUNS) |
||
105 | { |
||
106 | JoinRunLine(run); |
||
107 | } |
||
108 | } |
||
109 | 8b085570 | gaqhf | |
110 | 3165c259 | gaqhf | foreach (TrimLine trimLine in document.TRIMLINES) |
111 | { |
||
112 | foreach (LineRun run in trimLine.RUNS) |
||
113 | { |
||
114 | JoinRunLine(run); |
||
115 | } |
||
116 | } |
||
117 | 809a7640 | gaqhf | } |
118 | 5e6ecf05 | gaqhf | catch (Exception ex) |
119 | { |
||
120 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
121 | } |
||
122 | finally |
||
123 | { |
||
124 | ReleaseCOMObjects(dataSource); |
||
125 | ReleaseCOMObjects(_placement); |
||
126 | } |
||
127 | |||
128 | 809a7640 | gaqhf | System.Windows.Forms.MessageBox.Show("end"); |
129 | } |
||
130 | f1c9dbaa | gaqhf | |
131 | 8aa6f2db | gaqhf | private void LineModelingByRun(LineRun run) |
132 | 809a7640 | gaqhf | { |
133 | Line prevLine = null; |
||
134 | List<Line> lines = new List<Line>(); |
||
135 | foreach (var item in run.RUNITEMS) |
||
136 | { |
||
137 | // Line일 경우 |
||
138 | if (item.GetType() == typeof(Line)) |
||
139 | { |
||
140 | Line line = item as Line; |
||
141 | if (prevLine == null) |
||
142 | lines.Add(line); |
||
143 | else if (prevLine != null) |
||
144 | { |
||
145 | if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
||
146 | lines.Add(line); |
||
147 | else |
||
148 | f1c9dbaa | gaqhf | { |
149 | 809a7640 | gaqhf | LineModeling(lines); |
150 | lines.Clear(); |
||
151 | lines.Add(line); |
||
152 | 5dfb8a24 | gaqhf | } |
153 | } |
||
154 | |||
155 | 809a7640 | gaqhf | prevLine = line; |
156 | } |
||
157 | // Symbol 일 경우 |
||
158 | else if (item.GetType() == typeof(Symbol)) |
||
159 | { |
||
160 | f1c9dbaa | gaqhf | if (lines.Count > 0) |
161 | 809a7640 | gaqhf | { |
162 | f1c9dbaa | gaqhf | LineModeling(lines); |
163 | 809a7640 | gaqhf | lines.Clear(); |
164 | } |
||
165 | 5dfb8a24 | gaqhf | } |
166 | } |
||
167 | |||
168 | 809a7640 | gaqhf | if (lines.Count > 0) |
169 | LineModeling(lines); |
||
170 | } |
||
171 | 5dfb8a24 | gaqhf | |
172 | 8aa6f2db | gaqhf | private void SymbolModelingByRun(LineRun run) |
173 | 809a7640 | gaqhf | { |
174 | // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling |
||
175 | if (run.RUNITEMS.Count > 0) |
||
176 | { |
||
177 | if (run.RUNITEMS[0].GetType() == typeof(Symbol)) |
||
178 | SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run); |
||
179 | |||
180 | if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol)) |
||
181 | SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run); |
||
182 | } |
||
183 | |||
184 | Symbol prevSymbol = null; |
||
185 | Symbol targetSymbol = null; |
||
186 | foreach (var item in run.RUNITEMS) |
||
187 | { |
||
188 | if (item.GetType() == typeof(Symbol)) |
||
189 | { |
||
190 | Symbol symbol = item as Symbol; |
||
191 | SymbolModeling(symbol, targetSymbol, prevSymbol); |
||
192 | prevSymbol = symbol; |
||
193 | targetSymbol = symbol; |
||
194 | } |
||
195 | else |
||
196 | { |
||
197 | targetSymbol = null; |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 | |||
202 | 8aa6f2db | gaqhf | private void SymbolModelingByRunStart(Symbol symbol, LineRun run) |
203 | 809a7640 | gaqhf | { |
204 | foreach (var connector in symbol.CONNECTORS) |
||
205 | { |
||
206 | object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
207 | if (targetItem != null && |
||
208 | (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
||
209 | !IsSameLineNumber(symbol, targetItem)) |
||
210 | { |
||
211 | SymbolModeling(symbol, targetItem as Symbol, null); |
||
212 | for (int i = 1; i < run.RUNITEMS.Count; i++) |
||
213 | { |
||
214 | object item = run.RUNITEMS[i]; |
||
215 | if (item.GetType() == typeof(Symbol)) |
||
216 | SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null); |
||
217 | else |
||
218 | break; |
||
219 | } |
||
220 | break; |
||
221 | } |
||
222 | } |
||
223 | |||
224 | |||
225 | } |
||
226 | |||
227 | 8aa6f2db | gaqhf | private void SymbolModelingByRunEnd(Symbol symbol, LineRun run) |
228 | 809a7640 | gaqhf | { |
229 | foreach (var connector in symbol.CONNECTORS) |
||
230 | { |
||
231 | object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
232 | if (targetItem != null && |
||
233 | (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
||
234 | !IsSameLineNumber(symbol, targetItem)) |
||
235 | { |
||
236 | SymbolModeling(symbol, targetItem as Symbol, null); |
||
237 | for (int i = run.RUNITEMS.Count - 2; i >= 0; i--) |
||
238 | { |
||
239 | object item = run.RUNITEMS[i]; |
||
240 | if (item.GetType() == typeof(Symbol)) |
||
241 | SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null); |
||
242 | else |
||
243 | break; |
||
244 | } |
||
245 | break; |
||
246 | } |
||
247 | } |
||
248 | 5dfb8a24 | gaqhf | } |
249 | cfda1fed | gaqhf | |
250 | 5dfb8a24 | gaqhf | private void TestSource() |
251 | { |
||
252 | cfda1fed | gaqhf | |
253 | } |
||
254 | |||
255 | 809a7640 | gaqhf | private void SymbolModeling(Symbol symbol, Symbol prevSymbol, object prevItem, bool IsFirst) |
256 | cfda1fed | gaqhf | { |
257 | 809a7640 | gaqhf | if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
258 | return; |
||
259 | |||
260 | 5dfb8a24 | gaqhf | LMSymbol _LMSymbol = null; |
261 | |||
262 | string mappingPath = symbol.SPPID.MAPPINGNAME; |
||
263 | 1b261371 | gaqhf | double x = symbol.SPPID.ORIGINAL_X; |
264 | double y = symbol.SPPID.ORIGINAL_Y; |
||
265 | 5dfb8a24 | gaqhf | int mirror = 0; |
266 | double angle = symbol.ANGLE; |
||
267 | LMSymbol _TargetItem = null; |
||
268 | |||
269 | 809a7640 | gaqhf | if (IsFirst) |
270 | { |
||
271 | foreach (var connector in symbol.CONNECTORS) |
||
272 | { |
||
273 | object item = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
274 | if (item != null && |
||
275 | (item.GetType() == typeof(Symbol) || item.GetType() == typeof(Equipment)) && |
||
276 | !IsSameLineNumber(symbol, item)) |
||
277 | { |
||
278 | _TargetItem = dataSource.GetSymbol(((Symbol)item).SPPID.RepresentationId); |
||
279 | break; |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | else if (prevItem != null && prevItem.GetType() == typeof(Symbol)) |
||
284 | f1c9dbaa | gaqhf | _TargetItem = dataSource.GetSymbol(((Symbol)prevItem).SPPID.RepresentationId); |
285 | 8aa6f2db | gaqhf | |
286 | 5dfb8a24 | gaqhf | if (prevSymbol != null) |
287 | { |
||
288 | 1b261371 | gaqhf | SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
289 | f1c9dbaa | gaqhf | LMSymbol prevLMSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
290 | 1b261371 | gaqhf | double prevX = prevLMSymbol.get_XCoordinate(); |
291 | double prevY = prevLMSymbol.get_YCoordinate(); |
||
292 | 5dfb8a24 | gaqhf | if (slopeType == SlopeType.HORIZONTAL) |
293 | 1b261371 | gaqhf | y = prevY; |
294 | 5dfb8a24 | gaqhf | else if (slopeType == SlopeType.VERTICAL) |
295 | 1b261371 | gaqhf | x = prevX; |
296 | 8aa6f2db | gaqhf | |
297 | f1c9dbaa | gaqhf | ReleaseCOMObjects(prevLMSymbol); |
298 | 5dfb8a24 | gaqhf | } |
299 | |||
300 | if (_TargetItem == null) |
||
301 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
302 | else |
||
303 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
||
304 | |||
305 | if (_LMSymbol != null) |
||
306 | { |
||
307 | f1c9dbaa | gaqhf | _LMSymbol.Commit(); |
308 | symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
309 | 5dfb8a24 | gaqhf | } |
310 | |||
311 | f1c9dbaa | gaqhf | if (_TargetItem != null) |
312 | ReleaseCOMObjects(_TargetItem); |
||
313 | 809a7640 | gaqhf | |
314 | f1c9dbaa | gaqhf | ReleaseCOMObjects(_LMSymbol); |
315 | cfda1fed | gaqhf | } |
316 | |||
317 | 809a7640 | gaqhf | private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol) |
318 | { |
||
319 | if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
||
320 | return; |
||
321 | |||
322 | LMSymbol _LMSymbol = null; |
||
323 | |||
324 | string mappingPath = symbol.SPPID.MAPPINGNAME; |
||
325 | double x = symbol.SPPID.ORIGINAL_X; |
||
326 | double y = symbol.SPPID.ORIGINAL_Y; |
||
327 | int mirror = 0; |
||
328 | double angle = symbol.ANGLE; |
||
329 | |||
330 | if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
||
331 | { |
||
332 | LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
||
333 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
||
334 | ReleaseCOMObjects(_TargetItem); |
||
335 | } |
||
336 | else if (prevSymbol != null) |
||
337 | { |
||
338 | LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
||
339 | SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
||
340 | double prevX = _PrevSymbol.get_XCoordinate(); |
||
341 | double prevY = _PrevSymbol.get_YCoordinate(); |
||
342 | if (slopeType == SlopeType.HORIZONTAL) |
||
343 | y = prevY; |
||
344 | else if (slopeType == SlopeType.VERTICAL) |
||
345 | x = prevX; |
||
346 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
347 | } |
||
348 | else |
||
349 | { |
||
350 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
351 | } |
||
352 | |||
353 | |||
354 | if (_LMSymbol != null) |
||
355 | { |
||
356 | _LMSymbol.Commit(); |
||
357 | symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
358 | } |
||
359 | |||
360 | ReleaseCOMObjects(_LMSymbol); |
||
361 | } |
||
362 | |||
363 | private bool IsSameLineNumber(object item, object targetItem) |
||
364 | { |
||
365 | foreach (var lineNumber in document.LINENUMBERS) |
||
366 | { |
||
367 | foreach (var run in lineNumber.RUNS) |
||
368 | { |
||
369 | foreach (var runItem in run.RUNITEMS) |
||
370 | { |
||
371 | if (runItem == item) |
||
372 | { |
||
373 | foreach (var findItem in run.RUNITEMS) |
||
374 | { |
||
375 | if (findItem == targetItem) |
||
376 | { |
||
377 | return true; |
||
378 | } |
||
379 | } |
||
380 | |||
381 | return false; |
||
382 | |||
383 | } |
||
384 | } |
||
385 | } |
||
386 | } |
||
387 | |||
388 | return false; |
||
389 | } |
||
390 | |||
391 | 1b261371 | gaqhf | private void LineModeling(List<Line> lines) |
392 | { |
||
393 | 335b7a24 | gaqhf | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
394 | 1b261371 | gaqhf | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
395 | f1c9dbaa | gaqhf | LMSymbol _LMSymbol1 = null; |
396 | LMSymbol _LMSymbol2 = null; |
||
397 | 5e6ecf05 | gaqhf | Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
398 | LMConnector targetConnector1 = null; |
||
399 | Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
||
400 | LMConnector targetConnector2 = null; |
||
401 | 335b7a24 | gaqhf | |
402 | Line startBranchLine = null; |
||
403 | Line endBranchLine = null; |
||
404 | |||
405 | 1b261371 | gaqhf | for (int i = 0; i < lines.Count; i++) |
406 | { |
||
407 | Line line = lines[i]; |
||
408 | f1c9dbaa | gaqhf | if (i == 0 || i + 1 != lines.Count) |
409 | { |
||
410 | 809a7640 | gaqhf | // 시작점에 연결된 Symbol 찾기 |
411 | f1c9dbaa | gaqhf | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
412 | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
||
413 | { |
||
414 | _LMSymbol1 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId); |
||
415 | if (_LMSymbol1 != null) |
||
416 | placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y); |
||
417 | else |
||
418 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
419 | } |
||
420 | 335b7a24 | gaqhf | else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
421 | 5e6ecf05 | gaqhf | { |
422 | connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
||
423 | 56bc67e1 | gaqhf | targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
424 | 5e6ecf05 | gaqhf | |
425 | if (targetConnector1 != null) |
||
426 | placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y); |
||
427 | else |
||
428 | 335b7a24 | gaqhf | { |
429 | startBranchLine = connItem as Line; |
||
430 | 5e6ecf05 | gaqhf | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
431 | 335b7a24 | gaqhf | } |
432 | 5e6ecf05 | gaqhf | } |
433 | f1c9dbaa | gaqhf | else |
434 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
435 | } |
||
436 | |||
437 | if (i + 1 == lines.Count) |
||
438 | { |
||
439 | 809a7640 | gaqhf | // 끝점에 연결된 Symbol 찾기 |
440 | f1c9dbaa | gaqhf | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
441 | 5e6ecf05 | gaqhf | |
442 | if (i != 0) |
||
443 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
444 | |||
445 | f1c9dbaa | gaqhf | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
446 | { |
||
447 | _LMSymbol2 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId); |
||
448 | if (_LMSymbol2 != null) |
||
449 | placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y); |
||
450 | else |
||
451 | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
||
452 | |||
453 | } |
||
454 | 335b7a24 | gaqhf | else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
455 | 5e6ecf05 | gaqhf | { |
456 | connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
||
457 | 56bc67e1 | gaqhf | targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y); |
458 | 5e6ecf05 | gaqhf | |
459 | if (targetConnector2 != null) |
||
460 | placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y); |
||
461 | else |
||
462 | 335b7a24 | gaqhf | { |
463 | endBranchLine = connItem as Line; |
||
464 | 5e6ecf05 | gaqhf | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
465 | 335b7a24 | gaqhf | } |
466 | 5e6ecf05 | gaqhf | } |
467 | f1c9dbaa | gaqhf | else |
468 | { |
||
469 | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
||
470 | } |
||
471 | } |
||
472 | } |
||
473 | |||
474 | LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
475 | 335b7a24 | gaqhf | |
476 | f1c9dbaa | gaqhf | if (_lMConnector != null) |
477 | { |
||
478 | foreach (var line in lines) |
||
479 | 5e6ecf05 | gaqhf | line.SPPID.ModelItemId = _lMConnector.ModelItemID; |
480 | f1c9dbaa | gaqhf | _lMConnector.Commit(); |
481 | 335b7a24 | gaqhf | if (startBranchLine != null || endBranchLine != null) |
482 | { |
||
483 | 3165c259 | gaqhf | BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine)); |
484 | 335b7a24 | gaqhf | } |
485 | 1b261371 | gaqhf | } |
486 | 5e6ecf05 | gaqhf | |
487 | 1b261371 | gaqhf | |
488 | f1c9dbaa | gaqhf | if (_LMSymbol1 != null) |
489 | ReleaseCOMObjects(_LMSymbol1); |
||
490 | if (_LMSymbol2 != null) |
||
491 | ReleaseCOMObjects(_LMSymbol2); |
||
492 | 5e6ecf05 | gaqhf | if (targetConnector1 != null) |
493 | ReleaseCOMObjects(targetConnector1); |
||
494 | if (targetConnector2 != null) |
||
495 | ReleaseCOMObjects(targetConnector2); |
||
496 | foreach (var item in connectorVertices1) |
||
497 | ReleaseCOMObjects(item.Key); |
||
498 | foreach (var item in connectorVertices2) |
||
499 | ReleaseCOMObjects(item.Key); |
||
500 | 1b261371 | gaqhf | |
501 | f1c9dbaa | gaqhf | ReleaseCOMObjects(_lMConnector); |
502 | 1b261371 | gaqhf | ReleaseCOMObjects(placeRunInputs); |
503 | ReleaseCOMObjects(_LMAItem); |
||
504 | } |
||
505 | |||
506 | 335b7a24 | gaqhf | private void BranchLineModeling(Tuple<string, Line, Line> branch) |
507 | { |
||
508 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
||
509 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
||
510 | |||
511 | 8b085570 | gaqhf | LMConnector _StartConnector = null; |
512 | LMConnector _EndConnector = null; |
||
513 | 335b7a24 | gaqhf | double lengthStart = double.MaxValue; |
514 | double lengthEnd = double.MaxValue; |
||
515 | List<double[]> startPoints = new List<double[]>(); |
||
516 | List<double[]> endPoints = new List<double[]>(); |
||
517 | |||
518 | foreach (var item in connectorVertices) |
||
519 | { |
||
520 | foreach (var point in item.Value) |
||
521 | { |
||
522 | // Start Point가 Branch |
||
523 | if (branch.Item2 != null) |
||
524 | { |
||
525 | Line targetLine = branch.Item2; |
||
526 | double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
||
527 | if (lengthStart > distance) |
||
528 | { |
||
529 | 8b085570 | gaqhf | _StartConnector = item.Key; |
530 | 335b7a24 | gaqhf | lengthStart = distance; |
531 | startPoints = item.Value; |
||
532 | } |
||
533 | } |
||
534 | // End Point가 Branch |
||
535 | if (branch.Item3 != null) |
||
536 | { |
||
537 | Line targetLine = branch.Item3; |
||
538 | double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
||
539 | if (lengthEnd > distance) |
||
540 | { |
||
541 | 8b085570 | gaqhf | _EndConnector = item.Key; |
542 | 335b7a24 | gaqhf | lengthEnd = distance; |
543 | endPoints = item.Value; |
||
544 | } |
||
545 | } |
||
546 | } |
||
547 | } |
||
548 | #region Branch가 양쪽 전부일 때 |
||
549 | 8b085570 | gaqhf | if (_StartConnector != null && _StartConnector == _EndConnector) |
550 | 335b7a24 | gaqhf | { |
551 | 8b085570 | gaqhf | _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
552 | 335b7a24 | gaqhf | |
553 | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
||
554 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
555 | |||
556 | Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
||
557 | 8b085570 | gaqhf | LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
558 | 335b7a24 | gaqhf | Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
559 | 8b085570 | gaqhf | LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices, |
560 | 335b7a24 | gaqhf | startPoints[startPoints.Count - 1][0], |
561 | startPoints[startPoints.Count - 1][1], |
||
562 | startPoints[startPoints.Count - 2][0], |
||
563 | startPoints[startPoints.Count - 2][1]); |
||
564 | |||
565 | for (int i = 0; i < startPoints.Count; i++) |
||
566 | { |
||
567 | double[] point = startPoints[i]; |
||
568 | if (i == 0) |
||
569 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
570 | 335b7a24 | gaqhf | else if (i == startPoints.Count - 1) |
571 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
572 | 335b7a24 | gaqhf | else |
573 | placeRunInputs.AddPoint(point[0], point[1]); |
||
574 | } |
||
575 | |||
576 | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
577 | if (_LMConnector != null) |
||
578 | { |
||
579 | _LMConnector.Commit(); |
||
580 | foreach (var item in lines) |
||
581 | item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
582 | } |
||
583 | |||
584 | foreach (var item in startConnectorVertices) |
||
585 | ReleaseCOMObjects(item.Key); |
||
586 | foreach (var item in endConnectorVertices) |
||
587 | ReleaseCOMObjects(item.Key); |
||
588 | ReleaseCOMObjects(placeRunInputs); |
||
589 | ReleaseCOMObjects(_LMAItem); |
||
590 | ReleaseCOMObjects(_LMConnector); |
||
591 | } |
||
592 | #endregion |
||
593 | 8b085570 | gaqhf | #region 양쪽이 다른 Branch |
594 | 335b7a24 | gaqhf | else |
595 | { |
||
596 | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
||
597 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
598 | |||
599 | // Branch 시작 Connector |
||
600 | 8b085570 | gaqhf | if (_StartConnector != null) |
601 | 335b7a24 | gaqhf | { |
602 | 8b085570 | gaqhf | LMConnector _EndTargetConnector = null; |
603 | LMSymbol _EndTargetSymbol = null; |
||
604 | 335b7a24 | gaqhf | // Branch 반대편이 Line |
605 | foreach (var item in connectorVertices) |
||
606 | { |
||
607 | 8b085570 | gaqhf | if (item.Key == _StartConnector) |
608 | 335b7a24 | gaqhf | continue; |
609 | |||
610 | 8b085570 | gaqhf | if (item.Key.ConnectItem1SymbolID == _StartConnector.ConnectItem2SymbolID) |
611 | 335b7a24 | gaqhf | { |
612 | 8b085570 | gaqhf | _EndTargetConnector = item.Key; |
613 | 335b7a24 | gaqhf | break; |
614 | } |
||
615 | } |
||
616 | // Branch 반대편이 Symbol |
||
617 | 8b085570 | gaqhf | if (_EndTargetConnector == null) |
618 | 335b7a24 | gaqhf | { |
619 | foreach (var line in lines) |
||
620 | { |
||
621 | foreach (var connector in line.CONNECTORS) |
||
622 | { |
||
623 | Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
||
624 | if (symbol != null) |
||
625 | { |
||
626 | 8b085570 | gaqhf | _EndTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
627 | 335b7a24 | gaqhf | break; |
628 | } |
||
629 | } |
||
630 | } |
||
631 | } |
||
632 | |||
633 | 8b085570 | gaqhf | _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
634 | 335b7a24 | gaqhf | |
635 | Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
||
636 | 8b085570 | gaqhf | LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
637 | 335b7a24 | gaqhf | |
638 | for (int i = 0; i < startPoints.Count; i++) |
||
639 | { |
||
640 | double[] point = startPoints[i]; |
||
641 | if (i == 0) |
||
642 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
643 | 335b7a24 | gaqhf | else if (i == startPoints.Count - 1) |
644 | { |
||
645 | 8b085570 | gaqhf | if (_EndTargetConnector != null) |
646 | placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
||
647 | else if (_EndTargetSymbol != null) |
||
648 | placeRunInputs.AddSymbolTarget(_EndTargetSymbol, point[0], point[1]); |
||
649 | 335b7a24 | gaqhf | else |
650 | placeRunInputs.AddPoint(point[0], point[1]); |
||
651 | } |
||
652 | else |
||
653 | placeRunInputs.AddPoint(point[0], point[1]); |
||
654 | } |
||
655 | |||
656 | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
657 | if (_LMConnector != null ) |
||
658 | { |
||
659 | 8b085570 | gaqhf | if (_EndTargetConnector != null) |
660 | 335b7a24 | gaqhf | { |
661 | 8b085570 | gaqhf | JoinPipeRun(_LMConnector.ModelItemID, _EndTargetConnector.ModelItemID); |
662 | 335b7a24 | gaqhf | } |
663 | else |
||
664 | { |
||
665 | foreach (var item in lines) |
||
666 | item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
667 | } |
||
668 | |||
669 | _LMConnector.Commit(); |
||
670 | ReleaseCOMObjects(_LMConnector); |
||
671 | } |
||
672 | |||
673 | 8b085570 | gaqhf | if (_EndTargetConnector != null) |
674 | ReleaseCOMObjects(_EndTargetConnector); |
||
675 | if (_EndTargetSymbol != null) |
||
676 | ReleaseCOMObjects(_EndTargetSymbol); |
||
677 | 335b7a24 | gaqhf | foreach (var item in startConnectorVertices) |
678 | ReleaseCOMObjects(item.Key); |
||
679 | |||
680 | } |
||
681 | // Branch 끝 Connector |
||
682 | 8b085570 | gaqhf | if (_EndConnector != null) |
683 | 335b7a24 | gaqhf | { |
684 | 8b085570 | gaqhf | LMConnector _StartTargetConnector = null; |
685 | LMSymbol _StartTargetSymbol = null; |
||
686 | 335b7a24 | gaqhf | // Branch 반대편이 Line |
687 | foreach (var item in connectorVertices) |
||
688 | { |
||
689 | 8b085570 | gaqhf | if (item.Key == _EndConnector) |
690 | 335b7a24 | gaqhf | continue; |
691 | |||
692 | 8b085570 | gaqhf | if (item.Key.ConnectItem2SymbolID == _EndConnector.ConnectItem1SymbolID) |
693 | 335b7a24 | gaqhf | { |
694 | 8b085570 | gaqhf | _StartTargetConnector = item.Key; |
695 | 335b7a24 | gaqhf | break; |
696 | } |
||
697 | } |
||
698 | // Branch 반대편이 Symbol |
||
699 | 8b085570 | gaqhf | if (_StartTargetConnector == null) |
700 | 335b7a24 | gaqhf | { |
701 | foreach (var line in lines) |
||
702 | { |
||
703 | foreach (var connector in line.CONNECTORS) |
||
704 | { |
||
705 | Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
||
706 | if (symbol != null) |
||
707 | { |
||
708 | 8b085570 | gaqhf | _StartTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
709 | 335b7a24 | gaqhf | break; |
710 | } |
||
711 | } |
||
712 | } |
||
713 | } |
||
714 | |||
715 | 8b085570 | gaqhf | _placement.PIDRemovePlacement(_EndConnector.AsLMRepresentation()); |
716 | 335b7a24 | gaqhf | |
717 | Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
||
718 | 8b085570 | gaqhf | LMConnector _EndTargetConnector = FindTargetLMConnector(startConnectorVertices, |
719 | 335b7a24 | gaqhf | endPoints[endPoints.Count - 1][0], |
720 | endPoints[endPoints.Count - 1][1], |
||
721 | endPoints[endPoints.Count - 2][0], |
||
722 | endPoints[endPoints.Count - 2][1]); |
||
723 | |||
724 | for (int i = 0; i < endPoints.Count; i++) |
||
725 | { |
||
726 | double[] point = endPoints[i]; |
||
727 | if (i == 0) |
||
728 | { |
||
729 | 8b085570 | gaqhf | if (_StartTargetConnector != null) |
730 | placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
||
731 | else if (_StartTargetSymbol != null) |
||
732 | placeRunInputs.AddSymbolTarget(_StartTargetSymbol, point[0], point[1]); |
||
733 | 335b7a24 | gaqhf | else |
734 | placeRunInputs.AddPoint(point[0], point[1]); |
||
735 | } |
||
736 | else if (i == endPoints.Count - 1) |
||
737 | { |
||
738 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
739 | 335b7a24 | gaqhf | } |
740 | else |
||
741 | placeRunInputs.AddPoint(point[0], point[1]); |
||
742 | } |
||
743 | |||
744 | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
745 | if (_LMConnector != null) |
||
746 | { |
||
747 | 8b085570 | gaqhf | if (_StartTargetConnector != null) |
748 | 335b7a24 | gaqhf | { |
749 | 8b085570 | gaqhf | JoinPipeRun(_LMConnector.ModelItemID, _StartTargetConnector.ModelItemID); |
750 | 335b7a24 | gaqhf | } |
751 | else |
||
752 | { |
||
753 | foreach (var item in lines) |
||
754 | item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
755 | } |
||
756 | |||
757 | _LMConnector.Commit(); |
||
758 | ReleaseCOMObjects(_LMConnector); |
||
759 | } |
||
760 | |||
761 | 8b085570 | gaqhf | if (_StartTargetConnector != null) |
762 | ReleaseCOMObjects(_StartTargetConnector); |
||
763 | if (_StartTargetSymbol != null) |
||
764 | ReleaseCOMObjects(_StartTargetSymbol); |
||
765 | 335b7a24 | gaqhf | foreach (var item in startConnectorVertices) |
766 | ReleaseCOMObjects(item.Key); |
||
767 | } |
||
768 | |||
769 | ReleaseCOMObjects(_LMAItem); |
||
770 | ReleaseCOMObjects(placeRunInputs); |
||
771 | } |
||
772 | #endregion |
||
773 | |||
774 | 8b085570 | gaqhf | if (_StartConnector != null) |
775 | ReleaseCOMObjects(_StartConnector); |
||
776 | if (_EndConnector != null) |
||
777 | ReleaseCOMObjects(_EndConnector); |
||
778 | 335b7a24 | gaqhf | foreach (var item in connectorVertices) |
779 | ReleaseCOMObjects(item.Key); |
||
780 | |||
781 | |||
782 | |||
783 | //if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(targetLine.SPPID.ModelItemId)) |
||
784 | //{ |
||
785 | |||
786 | |||
787 | |||
788 | //} |
||
789 | } |
||
790 | |||
791 | 3165c259 | gaqhf | private void EndBreakModeling(EndBreak endBreak) |
792 | 335b7a24 | gaqhf | { |
793 | 3165c259 | gaqhf | Line ownerLine = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER) as Line; |
794 | Line connLine = null; |
||
795 | Property property = endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item"); |
||
796 | if (property != null) |
||
797 | connLine = SPPIDUtil.FindObjectByUID(document, property.VALUE) as Line; |
||
798 | 335b7a24 | gaqhf | |
799 | 3165c259 | gaqhf | if (ownerLine != null && connLine != null) |
800 | 335b7a24 | gaqhf | { |
801 | 3165c259 | gaqhf | LMLabelPersist _LmLabelPersist = null; |
802 | |||
803 | string lineModelId = ownerLine.SPPID.ModelItemId; |
||
804 | LMPipeRun _LMPipeRun = _placement.PIDDataSource.GetPipeRun(lineModelId); |
||
805 | LMPipeRun _ConnLMPipeRun = _placement.PIDDataSource.GetPipeRun(connLine.SPPID.ModelItemId); |
||
806 | LMConnector connectedLMConnector = null; |
||
807 | |||
808 | if (_LMPipeRun != null && _ConnLMPipeRun != null) |
||
809 | 335b7a24 | gaqhf | { |
810 | 3165c259 | gaqhf | foreach (LMRepresentation rep in _LMPipeRun.Representations) |
811 | 335b7a24 | gaqhf | { |
812 | 3165c259 | gaqhf | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
813 | { |
||
814 | LMConnector _LMConnector = _placement.PIDDataSource.GetConnector(rep.Id); |
||
815 | if (_LMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem1SymbolID) && ExistConnItem(_ConnLMPipeRun, _LMConnector.ConnectItem1SymbolID)) |
||
816 | { |
||
817 | connectedLMConnector = _LMConnector; |
||
818 | break; |
||
819 | } |
||
820 | else if (_LMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem2SymbolID) && ExistConnItem(_ConnLMPipeRun, _LMConnector.ConnectItem2SymbolID)) |
||
821 | { |
||
822 | connectedLMConnector = _LMConnector; |
||
823 | break; |
||
824 | } |
||
825 | else |
||
826 | { |
||
827 | ReleaseCOMObjects(_LMConnector); |
||
828 | } |
||
829 | } |
||
830 | 335b7a24 | gaqhf | } |
831 | 3165c259 | gaqhf | if (connectedLMConnector != null) |
832 | 335b7a24 | gaqhf | { |
833 | 3165c259 | gaqhf | Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
834 | _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
||
835 | ReleaseCOMObjects(connectedLMConnector); |
||
836 | 335b7a24 | gaqhf | } |
837 | 3165c259 | gaqhf | |
838 | ReleaseCOMObjects(_LMPipeRun); |
||
839 | ReleaseCOMObjects(_ConnLMPipeRun); |
||
840 | if (_LmLabelPersist != null) |
||
841 | ReleaseCOMObjects(_LmLabelPersist); |
||
842 | 335b7a24 | gaqhf | } |
843 | } |
||
844 | 3165c259 | gaqhf | } |
845 | private bool ExistConnItem(LMPipeRun _LMPipeRun, string ConnItem) |
||
846 | { |
||
847 | foreach (LMRepresentation rep in _LMPipeRun.Representations) |
||
848 | 335b7a24 | gaqhf | { |
849 | 3165c259 | gaqhf | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
850 | 335b7a24 | gaqhf | { |
851 | 3165c259 | gaqhf | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
852 | if (_LMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem1SymbolID) && _LMConnector.ConnectItem1SymbolID == ConnItem) |
||
853 | 335b7a24 | gaqhf | { |
854 | 3165c259 | gaqhf | ReleaseCOMObjects(_LMConnector); |
855 | return true; |
||
856 | 335b7a24 | gaqhf | } |
857 | 3165c259 | gaqhf | else if (_LMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem2SymbolID) && _LMConnector.ConnectItem2SymbolID == ConnItem) |
858 | 335b7a24 | gaqhf | { |
859 | 3165c259 | gaqhf | ReleaseCOMObjects(_LMConnector); |
860 | return true; |
||
861 | 335b7a24 | gaqhf | } |
862 | else |
||
863 | { |
||
864 | 3165c259 | gaqhf | ReleaseCOMObjects(_LMConnector); |
865 | 335b7a24 | gaqhf | } |
866 | } |
||
867 | } |
||
868 | |||
869 | 3165c259 | gaqhf | return false; |
870 | 335b7a24 | gaqhf | } |
871 | |||
872 | private void JoinPipeRun(string fromModelItemId, string toModelItemId) |
||
873 | { |
||
874 | LMPipeRun run1 = dataSource.GetPipeRun(toModelItemId); |
||
875 | LMPipeRun run2 = dataSource.GetPipeRun(fromModelItemId); |
||
876 | // item2가 item1으로 조인 |
||
877 | try |
||
878 | { |
||
879 | _LMAItem item1 = run1.AsLMAItem(); |
||
880 | _LMAItem item2 = run2.AsLMAItem(); |
||
881 | |||
882 | _placement.PIDJoinRuns(ref item1, ref item2); |
||
883 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId); |
||
884 | foreach (var line in lines) |
||
885 | line.SPPID.ModelItemId = toModelItemId; |
||
886 | |||
887 | } |
||
888 | catch (Exception ex) |
||
889 | { |
||
890 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
891 | } |
||
892 | finally |
||
893 | { |
||
894 | ReleaseCOMObjects(run1); |
||
895 | ReleaseCOMObjects(run2); |
||
896 | } |
||
897 | } |
||
898 | |||
899 | private void AutoJoinPipeRun(string modelItemId) |
||
900 | { |
||
901 | LMPipeRun run = dataSource.GetPipeRun(modelItemId); |
||
902 | _LMAItem item = run.AsLMAItem(); |
||
903 | _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
||
904 | } |
||
905 | |||
906 | private void JoinRunLine(LineRun run) |
||
907 | { |
||
908 | string modelItemId = string.Empty; |
||
909 | foreach (var item in run.RUNITEMS) |
||
910 | { |
||
911 | if (item.GetType() == typeof(Line)) |
||
912 | { |
||
913 | Line line = item as Line; |
||
914 | if (modelItemId != line.SPPID.ModelItemId) |
||
915 | { |
||
916 | AutoJoinPipeRun(line.SPPID.ModelItemId); |
||
917 | modelItemId = line.SPPID.ModelItemId; |
||
918 | } |
||
919 | //if (string.IsNullOrEmpty(modelItemId)) |
||
920 | //{ |
||
921 | // modelItemId = line.SPPID.ModelItemId; |
||
922 | //} |
||
923 | //else if(modelItemId != line.SPPID.ModelItemId) |
||
924 | //{ |
||
925 | // JoinPipeRun(line.SPPID.ModelItemId, modelItemId); |
||
926 | //} |
||
927 | } |
||
928 | } |
||
929 | } |
||
930 | |||
931 | 5e6ecf05 | gaqhf | private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
932 | { |
||
933 | Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
||
934 | LMPipeRun _LMPipeRun = dataSource.GetPipeRun(modelId); |
||
935 | if (_LMPipeRun != null) |
||
936 | { |
||
937 | foreach (LMRepresentation rep in _LMPipeRun.Representations) |
||
938 | { |
||
939 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
940 | { |
||
941 | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
||
942 | connectorVertices.Add(_LMConnector, new List<double[]>()); |
||
943 | dynamic OID = rep.get_GraphicOID(); |
||
944 | 335b7a24 | gaqhf | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
945 | 5e6ecf05 | gaqhf | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
946 | int verticesCount = lineStringGeometry.VertexCount; |
||
947 | double[] vertices = null; |
||
948 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
949 | for (int i = 0; i < verticesCount; i++) |
||
950 | { |
||
951 | double x = 0; |
||
952 | double y = 0; |
||
953 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
954 | 335b7a24 | gaqhf | connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) }); |
955 | 5e6ecf05 | gaqhf | } |
956 | } |
||
957 | } |
||
958 | |||
959 | ReleaseCOMObjects(_LMPipeRun); |
||
960 | } |
||
961 | |||
962 | return connectorVertices; |
||
963 | } |
||
964 | |||
965 | 56bc67e1 | gaqhf | private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2) |
966 | 5e6ecf05 | gaqhf | { |
967 | double length = double.MaxValue; |
||
968 | LMConnector targetConnector = null; |
||
969 | foreach (var item in connectorVertices) |
||
970 | { |
||
971 | List<double[]> points = item.Value; |
||
972 | for (int i = 0; i < points.Count - 1; i++) |
||
973 | { |
||
974 | double[] point1 = points[i]; |
||
975 | double[] point2 = points[i + 1]; |
||
976 | |||
977 | 335b7a24 | gaqhf | double maxLineX = Math.Max(point1[0], point2[0]); |
978 | double minLineX = Math.Min(point1[0], point2[0]); |
||
979 | double maxLineY = Math.Max(point1[1], point2[1]); |
||
980 | double minLineY = Math.Min(point1[1], point2[1]); |
||
981 | |||
982 | SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
||
983 | |||
984 | 56bc67e1 | gaqhf | // 두직선의 교차점 |
985 | double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
||
986 | if (crossingPoint != null) |
||
987 | 5e6ecf05 | gaqhf | { |
988 | 30a9ffce | gaqhf | double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]); |
989 | 335b7a24 | gaqhf | if (length >= distance) |
990 | 30a9ffce | gaqhf | { |
991 | 335b7a24 | gaqhf | if (slope == SlopeType.Slope && |
992 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
||
993 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
994 | { |
||
995 | targetConnector = item.Key; |
||
996 | length = distance; |
||
997 | } |
||
998 | else if (slope == SlopeType.HORIZONTAL && |
||
999 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
||
1000 | { |
||
1001 | targetConnector = item.Key; |
||
1002 | length = distance; |
||
1003 | } |
||
1004 | else if (slope == SlopeType.VERTICAL && |
||
1005 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
1006 | { |
||
1007 | targetConnector = item.Key; |
||
1008 | length = distance; |
||
1009 | } |
||
1010 | 30a9ffce | gaqhf | } |
1011 | 5e6ecf05 | gaqhf | } |
1012 | } |
||
1013 | } |
||
1014 | |||
1015 | return targetConnector; |
||
1016 | } |
||
1017 | |||
1018 | cfda1fed | gaqhf | private void LineNumberModeling(LineNumber lineNumber) |
1019 | { |
||
1020 | |||
1021 | } |
||
1022 | |||
1023 | private void TextModeling(Text text) |
||
1024 | { |
||
1025 | |||
1026 | } |
||
1027 | |||
1028 | private void NoteModeling(Note note) |
||
1029 | { |
||
1030 | |||
1031 | } |
||
1032 | |||
1033 | 5dfb8a24 | gaqhf | |
1034 | public void ReleaseCOMObjects(params object[] objVars) |
||
1035 | { |
||
1036 | int intNewRefCount = 0; |
||
1037 | foreach (object obj in objVars) |
||
1038 | { |
||
1039 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
1040 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
1041 | } |
||
1042 | } |
||
1043 | cfda1fed | gaqhf | } |
1044 | } |