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