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