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