hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ b93e7eef
이력 | 보기 | 이력해설 | 다운로드 (82.6 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 | ca214bc3 | gaqhf | using DevExpress.XtraSplashScreen; |
25 | cfda1fed | gaqhf | namespace Converter.SPPID |
26 | { |
||
27 | public class AutoModeling |
||
28 | { |
||
29 | 809a7640 | gaqhf | Placement _placement; |
30 | LMADataSource dataSource; |
||
31 | 1ba9c671 | gaqhf | dynamic newDrawing; |
32 | d19ae675 | gaqhf | dynamic application; |
33 | 5e6ecf05 | gaqhf | Ingr.RAD2D.Application radApp; |
34 | cfda1fed | gaqhf | SPPID_Document document; |
35 | b65a7e32 | gaqhf | ETCSetting _ETCSetting; |
36 | f1c9dbaa | gaqhf | |
37 | d5ec4d0f | gaqhf | public string DocumentLabelText { get; set; } |
38 | |||
39 | f31645b6 | gaqhf | int CurrentCount; |
40 | |||
41 | List <Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>(); |
||
42 | d19ae675 | gaqhf | public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp) |
43 | cfda1fed | gaqhf | { |
44 | this.document = document; |
||
45 | d19ae675 | gaqhf | this.application = application; |
46 | 5e6ecf05 | gaqhf | this.radApp = radApp; |
47 | b65a7e32 | gaqhf | this._ETCSetting = ETCSetting.GetInstance(); |
48 | cfda1fed | gaqhf | } |
49 | |||
50 | b265df51 | gaqhf | private int ClacProgressCount() |
51 | f31645b6 | gaqhf | { |
52 | b265df51 | gaqhf | int EquipCount = 0; |
53 | int SymbolCount = 0; |
||
54 | int LineCount = 0; |
||
55 | int NoteCount = 0; |
||
56 | int TextCount = 0; |
||
57 | int EndBreakCount = 0; |
||
58 | int LineNumberCount = 0; |
||
59 | |||
60 | f31645b6 | gaqhf | EquipCount = document.Equipments.Count; |
61 | SymbolCount = document.SYMBOLS.Count; |
||
62 | SymbolCount = SymbolCount * 3; |
||
63 | |||
64 | foreach (LineNumber lineNumber in document.LINENUMBERS) |
||
65 | foreach (LineRun run in lineNumber.RUNS) |
||
66 | foreach (var item in run.RUNITEMS) |
||
67 | if (item.GetType() == typeof(Line)) |
||
68 | LineCount++; |
||
69 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
70 | foreach (LineRun run in trimLine.RUNS) |
||
71 | foreach (var item in run.RUNITEMS) |
||
72 | if (item.GetType() == typeof(Line)) |
||
73 | LineCount++; |
||
74 | |||
75 | LineCount = LineCount * 2; |
||
76 | NoteCount = document.NOTES.Count; |
||
77 | TextCount = document.TEXTINFOS.Count; |
||
78 | EndBreakCount = document.EndBreaks.Count; |
||
79 | LineNumberCount = document.LINENUMBERS.Count; |
||
80 | LineNumberCount = LineNumberCount * 2; |
||
81 | |||
82 | b265df51 | gaqhf | return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount; |
83 | f31645b6 | gaqhf | } |
84 | |||
85 | 1ba9c671 | gaqhf | public void Run() |
86 | c2fef4ca | gaqhf | { |
87 | 1ba9c671 | gaqhf | try |
88 | c2fef4ca | gaqhf | { |
89 | 1ba9c671 | gaqhf | _placement = new Placement(); |
90 | dataSource = _placement.PIDDataSource; |
||
91 | |||
92 | newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName); |
||
93 | application.ActiveWindow.Fit(); |
||
94 | Thread.Sleep(500); |
||
95 | application.ActiveWindow.Zoom = 2000; |
||
96 | Thread.Sleep(1000); |
||
97 | |||
98 | double maxX = 0; |
||
99 | double maxY = 0; |
||
100 | foreach (object drawingObj in radApp.ActiveDocument.ActiveSheet.DrawingObjects) |
||
101 | c2fef4ca | gaqhf | { |
102 | 1f1b3a40 | gaqhf | Ingr.RAD2D.SmartFrame2d smartFrame2d = drawingObj as Ingr.RAD2D.SmartFrame2d; |
103 | if (smartFrame2d != null) |
||
104 | c2fef4ca | gaqhf | { |
105 | 1ba9c671 | gaqhf | double x1 = 0; |
106 | double x2 = 0; |
||
107 | double y1 = 0; |
||
108 | double y2 = 0; |
||
109 | 1f1b3a40 | gaqhf | smartFrame2d.Range(out x1, out y1, out x2, out y2); |
110 | 1ba9c671 | gaqhf | maxX = Math.Max(x2, maxX); |
111 | maxY = Math.Max(y2, maxY); |
||
112 | c2fef4ca | gaqhf | } |
113 | } |
||
114 | 3939eebf | gaqhf | if (maxX != 0 && maxY != 0) |
115 | 310aeb31 | gaqhf | { |
116 | 3939eebf | gaqhf | document.SetSPPIDLocation(maxX, maxY); |
117 | b265df51 | gaqhf | int AllCount = ClacProgressCount(); |
118 | 3939eebf | gaqhf | |
119 | 965eb728 | gaqhf | SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
120 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd); |
121 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount); |
||
122 | d5ec4d0f | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText); |
123 | 965eb728 | gaqhf | |
124 | 3939eebf | gaqhf | // Equipment Modeling |
125 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling"); |
126 | 3939eebf | gaqhf | foreach (Equipment equipment in document.Equipments) |
127 | EquipmentModeling(equipment); |
||
128 | |||
129 | // LineRun Symbol Modeling |
||
130 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling"); |
131 | 3939eebf | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
132 | foreach (LineRun run in lineNumber.RUNS) |
||
133 | SymbolModelingByRun(run); |
||
134 | // TrimLineRun Symbol Modeling |
||
135 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
136 | foreach (LineRun run in trimLine.RUNS) |
||
137 | SymbolModelingByRun(run); |
||
138 | |||
139 | // LineRun Line Modeling |
||
140 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling"); |
141 | 3939eebf | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
142 | foreach (LineRun run in lineNumber.RUNS) |
||
143 | LineModelingByRun(run); |
||
144 | // TrimLineRun Line Modeling |
||
145 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
146 | foreach (LineRun run in trimLine.RUNS) |
||
147 | LineModelingByRun(run); |
||
148 | |||
149 | // Branch Line Modeling |
||
150 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling"); |
151 | 3939eebf | gaqhf | foreach (var item in BranchLines) |
152 | BranchLineModeling(item); |
||
153 | |||
154 | // EndBreak Modeling |
||
155 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling"); |
156 | 3939eebf | gaqhf | foreach (var item in document.EndBreaks) |
157 | EndBreakModeling(item); |
||
158 | |||
159 | // LineNumber Modeling |
||
160 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling"); |
161 | 3939eebf | gaqhf | foreach (var item in document.LINENUMBERS) |
162 | LineNumberModeling(item); |
||
163 | |||
164 | // Note Modeling |
||
165 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling"); |
166 | 3939eebf | gaqhf | foreach (var item in document.NOTES) |
167 | NoteModeling(item); |
||
168 | |||
169 | // Text Modeling |
||
170 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling"); |
171 | 3939eebf | gaqhf | foreach (var item in document.TEXTINFOS) |
172 | TextModeling(item); |
||
173 | |||
174 | // LineRun Line Join |
||
175 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineRuns Join"); |
176 | 3939eebf | gaqhf | foreach (LineNumber lineNumber in document.LINENUMBERS) |
177 | foreach (LineRun run in lineNumber.RUNS) |
||
178 | JoinRunLine(run); |
||
179 | // TrimLineRun Line Join |
||
180 | foreach (TrimLine trimLine in document.TRIMLINES) |
||
181 | foreach (LineRun run in trimLine.RUNS) |
||
182 | JoinRunLine(run); |
||
183 | |||
184 | // Input LineNumber Attribute |
||
185 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Lines Attribute"); |
186 | 3939eebf | gaqhf | foreach (var item in document.LINENUMBERS) |
187 | InputLineNumberAttribute(item); |
||
188 | |||
189 | // Input Symbol Attribute |
||
190 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute"); |
191 | 3939eebf | gaqhf | foreach (var item in document.SYMBOLS) |
192 | InputSymbolAttribute(item); |
||
193 | |||
194 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling"); |
195 | 3939eebf | gaqhf | #region 임시 Label |
196 | foreach (var item in document.SYMBOLS) |
||
197 | 310aeb31 | gaqhf | { |
198 | 3939eebf | gaqhf | if (item.SPPID.MAPPINGNAME.Contains("Labels - ")) |
199 | 310aeb31 | gaqhf | { |
200 | 3939eebf | gaqhf | SPPIDSymbolInfo info = item.SPPID; |
201 | Array points = new double[] { 0, item.SPPID.ORIGINAL_X, item.SPPID.ORIGINAL_Y }; |
||
202 | BaseModel.Attribute itemAttribute = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL"); |
||
203 | if (itemAttribute == null) |
||
204 | continue; |
||
205 | string symbolUID = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL").VALUE; |
||
206 | object objectItem = SPPIDUtil.FindObjectByUID(document, symbolUID); |
||
207 | if (objectItem != null) |
||
208 | { |
||
209 | 8b069d9f | gaqhf | |
210 | 3939eebf | gaqhf | string sRep = null; |
211 | if (objectItem.GetType() == typeof(Symbol)) |
||
212 | sRep = ((Symbol)objectItem).SPPID.RepresentationId; |
||
213 | else if (objectItem.GetType() == typeof(Equipment)) |
||
214 | sRep = ((Equipment)objectItem).SPPID.RepresentationId; |
||
215 | 26c6f818 | gaqhf | |
216 | 3939eebf | gaqhf | if (!string.IsNullOrEmpty(sRep)) |
217 | 8b069d9f | gaqhf | { |
218 | cf924377 | gaqhf | bool leaderLine = false; |
219 | SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == item.DBUID); |
||
220 | if (symbolMapping != null) |
||
221 | leaderLine = symbolMapping.LEADERLINE; |
||
222 | |||
223 | 3939eebf | gaqhf | LMSymbol _TargetItem = dataSource.GetSymbol(sRep); |
224 | cf924377 | gaqhf | LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(item.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
225 | 3939eebf | gaqhf | LMModelItem _LMModelItem = _TargetItem.ModelItemObject; |
226 | LMAAttributes _Attributes = _LMModelItem.Attributes; |
||
227 | |||
228 | foreach (var attribute in item.ATTRIBUTES) |
||
229 | 26c6f818 | gaqhf | { |
230 | 3939eebf | gaqhf | if (!string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
231 | 26c6f818 | gaqhf | { |
232 | 3939eebf | gaqhf | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID); |
233 | if (mapping != null) |
||
234 | 26c6f818 | gaqhf | { |
235 | 3939eebf | gaqhf | LMAAttribute _LMAAttribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
236 | if (mapping.SPPIDATTRIBUTENAME.Contains("Description")) |
||
237 | 26c6f818 | gaqhf | { |
238 | 3939eebf | gaqhf | if (!DBNull.Value.Equals(_LMAAttribute.get_Value()) && !string.IsNullOrEmpty(_LMAAttribute.get_Value())) |
239 | { |
||
240 | string value = _LMAAttribute.get_Value() + "\n" + attribute.VALUE; |
||
241 | _LMAAttribute.set_Value(value); |
||
242 | } |
||
243 | else |
||
244 | { |
||
245 | _LMAAttribute.set_Value(attribute.VALUE); |
||
246 | } |
||
247 | 26c6f818 | gaqhf | } |
248 | 3939eebf | gaqhf | else if (_LMAAttribute != null) |
249 | 26c6f818 | gaqhf | _LMAAttribute.set_Value(attribute.VALUE); |
250 | } |
||
251 | } |
||
252 | } |
||
253 | f9125a54 | gaqhf | |
254 | cf924377 | gaqhf | //Leader 선 센터로 |
255 | 3939eebf | gaqhf | string OID = _LMLabelPresist.get_GraphicOID(); |
256 | DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject; |
||
257 | if (dependency != null) |
||
258 | 1f1b3a40 | gaqhf | { |
259 | 3939eebf | gaqhf | bool result = false; |
260 | foreach (var attributes in dependency.AttributeSets) |
||
261 | 1f1b3a40 | gaqhf | { |
262 | 3939eebf | gaqhf | foreach (var attribute in attributes) |
263 | 1f1b3a40 | gaqhf | { |
264 | 3939eebf | gaqhf | string name = attribute.Name; |
265 | string value = attribute.GetValue().ToString(); |
||
266 | if (name == "DrawingItemType" && value == "LabelPersist") |
||
267 | 1f1b3a40 | gaqhf | { |
268 | 3939eebf | gaqhf | foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects) |
269 | 1f1b3a40 | gaqhf | { |
270 | 3939eebf | gaqhf | if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d) |
271 | { |
||
272 | Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d; |
||
273 | double prevX = _TargetItem.get_XCoordinate(); |
||
274 | double prevY = _TargetItem.get_YCoordinate(); |
||
275 | lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY); |
||
276 | lineString2D.RemoveVertex(lineString2D.VertexCount); |
||
277 | result = true; |
||
278 | break; |
||
279 | } |
||
280 | 1f1b3a40 | gaqhf | } |
281 | } |
||
282 | 3939eebf | gaqhf | |
283 | if (result) |
||
284 | break; |
||
285 | 1f1b3a40 | gaqhf | } |
286 | |||
287 | if (result) |
||
288 | break; |
||
289 | } |
||
290 | } |
||
291 | |||
292 | f9125a54 | gaqhf | |
293 | 3939eebf | gaqhf | _LMModelItem.Commit(); |
294 | _LMLabelPresist.Commit(); |
||
295 | ReleaseCOMObjects(_TargetItem); |
||
296 | ReleaseCOMObjects(_LMLabelPresist); |
||
297 | ReleaseCOMObjects(_LMModelItem); |
||
298 | ReleaseCOMObjects(_Attributes); |
||
299 | } |
||
300 | 310aeb31 | gaqhf | } |
301 | } |
||
302 | f31645b6 | gaqhf | |
303 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
304 | 310aeb31 | gaqhf | } |
305 | 3939eebf | gaqhf | #endregion |
306 | f31645b6 | gaqhf | |
307 | |||
308 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount); |
||
309 | 310aeb31 | gaqhf | } |
310 | 809a7640 | gaqhf | } |
311 | 5e6ecf05 | gaqhf | catch (Exception ex) |
312 | { |
||
313 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
314 | } |
||
315 | finally |
||
316 | { |
||
317 | 1ba9c671 | gaqhf | application.ActiveWindow.Fit(); |
318 | 3939eebf | gaqhf | |
319 | 1ba9c671 | gaqhf | if (newDrawing != null) |
320 | 3939eebf | gaqhf | { |
321 | radApp.ActiveDocument.SaveOnClose = false; |
||
322 | radApp.ActiveDocument.Save(); |
||
323 | 1ba9c671 | gaqhf | ReleaseCOMObjects(newDrawing); |
324 | 3939eebf | gaqhf | } |
325 | 1ba9c671 | gaqhf | |
326 | 5e6ecf05 | gaqhf | ReleaseCOMObjects(dataSource); |
327 | ReleaseCOMObjects(_placement); |
||
328 | 965eb728 | gaqhf | |
329 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
330 | 965eb728 | gaqhf | SplashScreenManager.CloseForm(false); |
331 | 5e6ecf05 | gaqhf | } |
332 | 65a1ed4b | gaqhf | } |
333 | |||
334 | 8aa6f2db | gaqhf | private void LineModelingByRun(LineRun run) |
335 | 809a7640 | gaqhf | { |
336 | Line prevLine = null; |
||
337 | List<Line> lines = new List<Line>(); |
||
338 | foreach (var item in run.RUNITEMS) |
||
339 | { |
||
340 | // Line일 경우 |
||
341 | if (item.GetType() == typeof(Line)) |
||
342 | { |
||
343 | Line line = item as Line; |
||
344 | if (prevLine == null) |
||
345 | lines.Add(line); |
||
346 | else if (prevLine != null) |
||
347 | { |
||
348 | if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
||
349 | lines.Add(line); |
||
350 | else |
||
351 | f1c9dbaa | gaqhf | { |
352 | f2baa6a3 | gaqhf | if (lines.Count > 0) |
353 | { |
||
354 | LineModeling(lines); |
||
355 | lines.Clear(); |
||
356 | } |
||
357 | 809a7640 | gaqhf | lines.Add(line); |
358 | 5dfb8a24 | gaqhf | } |
359 | } |
||
360 | |||
361 | 809a7640 | gaqhf | prevLine = line; |
362 | f31645b6 | gaqhf | |
363 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
364 | 809a7640 | gaqhf | } |
365 | // Symbol 일 경우 |
||
366 | else if (item.GetType() == typeof(Symbol)) |
||
367 | { |
||
368 | f1c9dbaa | gaqhf | if (lines.Count > 0) |
369 | 809a7640 | gaqhf | { |
370 | f1c9dbaa | gaqhf | LineModeling(lines); |
371 | 809a7640 | gaqhf | lines.Clear(); |
372 | } |
||
373 | 5dfb8a24 | gaqhf | } |
374 | } |
||
375 | |||
376 | 809a7640 | gaqhf | if (lines.Count > 0) |
377 | LineModeling(lines); |
||
378 | } |
||
379 | 5dfb8a24 | gaqhf | |
380 | 8aa6f2db | gaqhf | private void SymbolModelingByRun(LineRun run) |
381 | 809a7640 | gaqhf | { |
382 | // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling |
||
383 | if (run.RUNITEMS.Count > 0) |
||
384 | { |
||
385 | if (run.RUNITEMS[0].GetType() == typeof(Symbol)) |
||
386 | SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run); |
||
387 | |||
388 | if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol)) |
||
389 | SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run); |
||
390 | } |
||
391 | |||
392 | Symbol prevSymbol = null; |
||
393 | Symbol targetSymbol = null; |
||
394 | foreach (var item in run.RUNITEMS) |
||
395 | { |
||
396 | if (item.GetType() == typeof(Symbol)) |
||
397 | { |
||
398 | Symbol symbol = item as Symbol; |
||
399 | SymbolModeling(symbol, targetSymbol, prevSymbol); |
||
400 | prevSymbol = symbol; |
||
401 | targetSymbol = symbol; |
||
402 | } |
||
403 | else |
||
404 | { |
||
405 | targetSymbol = null; |
||
406 | } |
||
407 | } |
||
408 | } |
||
409 | |||
410 | 8aa6f2db | gaqhf | private void SymbolModelingByRunStart(Symbol symbol, LineRun run) |
411 | 809a7640 | gaqhf | { |
412 | foreach (var connector in symbol.CONNECTORS) |
||
413 | { |
||
414 | object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
415 | if (targetItem != null && |
||
416 | (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
||
417 | !IsSameLineNumber(symbol, targetItem)) |
||
418 | { |
||
419 | SymbolModeling(symbol, targetItem as Symbol, null); |
||
420 | for (int i = 1; i < run.RUNITEMS.Count; i++) |
||
421 | { |
||
422 | object item = run.RUNITEMS[i]; |
||
423 | if (item.GetType() == typeof(Symbol)) |
||
424 | SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null); |
||
425 | else |
||
426 | break; |
||
427 | } |
||
428 | break; |
||
429 | } |
||
430 | } |
||
431 | |||
432 | |||
433 | } |
||
434 | |||
435 | 8aa6f2db | gaqhf | private void SymbolModelingByRunEnd(Symbol symbol, LineRun run) |
436 | 809a7640 | gaqhf | { |
437 | foreach (var connector in symbol.CONNECTORS) |
||
438 | { |
||
439 | object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
||
440 | if (targetItem != null && |
||
441 | (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
||
442 | !IsSameLineNumber(symbol, targetItem)) |
||
443 | { |
||
444 | SymbolModeling(symbol, targetItem as Symbol, null); |
||
445 | for (int i = run.RUNITEMS.Count - 2; i >= 0; i--) |
||
446 | { |
||
447 | object item = run.RUNITEMS[i]; |
||
448 | if (item.GetType() == typeof(Symbol)) |
||
449 | SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null); |
||
450 | else |
||
451 | break; |
||
452 | } |
||
453 | break; |
||
454 | } |
||
455 | } |
||
456 | 5dfb8a24 | gaqhf | } |
457 | cfda1fed | gaqhf | |
458 | 809a7640 | gaqhf | private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol) |
459 | { |
||
460 | c2fef4ca | gaqhf | // 임시 |
461 | c3d2e266 | gaqhf | if (symbol.SPPID.MAPPINGNAME.Contains("Labels - ")) |
462 | return; |
||
463 | c2fef4ca | gaqhf | |
464 | 809a7640 | gaqhf | if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
465 | return; |
||
466 | |||
467 | LMSymbol _LMSymbol = null; |
||
468 | |||
469 | string mappingPath = symbol.SPPID.MAPPINGNAME; |
||
470 | double x = symbol.SPPID.ORIGINAL_X; |
||
471 | double y = symbol.SPPID.ORIGINAL_Y; |
||
472 | int mirror = 0; |
||
473 | double angle = symbol.ANGLE; |
||
474 | c2fef4ca | gaqhf | // 임시 |
475 | if (mappingPath.Contains("Piping OPC's") && angle == Math.PI) |
||
476 | { |
||
477 | mirror = 1; |
||
478 | } |
||
479 | |||
480 | 809a7640 | gaqhf | |
481 | if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
||
482 | { |
||
483 | LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
||
484 | b9e9f4c8 | gaqhf | |
485 | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
||
486 | double x1 = 0; |
||
487 | double x2 = 0; |
||
488 | double y1 = 0; |
||
489 | double y2 = 0; |
||
490 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
491 | |||
492 | if (y2 < y) |
||
493 | y = y2; |
||
494 | else if (y1 > y) |
||
495 | y = y1; |
||
496 | |||
497 | if (x2 < x) |
||
498 | x = x2; |
||
499 | else if (x1 > x) |
||
500 | x = x1; |
||
501 | |||
502 | 809a7640 | gaqhf | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
503 | ReleaseCOMObjects(_TargetItem); |
||
504 | } |
||
505 | else if (prevSymbol != null) |
||
506 | { |
||
507 | LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
||
508 | SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
||
509 | double prevX = _PrevSymbol.get_XCoordinate(); |
||
510 | double prevY = _PrevSymbol.get_YCoordinate(); |
||
511 | if (slopeType == SlopeType.HORIZONTAL) |
||
512 | y = prevY; |
||
513 | else if (slopeType == SlopeType.VERTICAL) |
||
514 | x = prevX; |
||
515 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
516 | } |
||
517 | else |
||
518 | { |
||
519 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
520 | } |
||
521 | |||
522 | |||
523 | if (_LMSymbol != null) |
||
524 | { |
||
525 | _LMSymbol.Commit(); |
||
526 | symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
527 | ac78b508 | gaqhf | |
528 | 4b4dbca9 | gaqhf | foreach (var item in symbol.ChildSymbols) |
529 | CreateChildSymbol(item, _LMSymbol); |
||
530 | 809a7640 | gaqhf | } |
531 | |||
532 | ReleaseCOMObjects(_LMSymbol); |
||
533 | f31645b6 | gaqhf | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
534 | 809a7640 | gaqhf | } |
535 | |||
536 | b9e9f4c8 | gaqhf | private void EquipmentModeling(Equipment equipment) |
537 | { |
||
538 | if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId)) |
||
539 | return; |
||
540 | |||
541 | LMSymbol _LMSymbol = null; |
||
542 | LMSymbol targetItem = null; |
||
543 | string mappingPath = equipment.SPPID.MAPPINGNAME; |
||
544 | double x = equipment.SPPID.ORIGINAL_X; |
||
545 | double y = equipment.SPPID.ORIGINAL_Y; |
||
546 | int mirror = 0; |
||
547 | double angle = equipment.ANGLE; |
||
548 | |||
549 | Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None"); |
||
550 | if (connector != null) |
||
551 | { |
||
552 | Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment; |
||
553 | if (connEquipment != null) |
||
554 | { |
||
555 | if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
||
556 | EquipmentModeling(connEquipment); |
||
557 | |||
558 | if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
||
559 | { |
||
560 | targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId); |
||
561 | if (targetItem != null) |
||
562 | { |
||
563 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
||
564 | } |
||
565 | else |
||
566 | { |
||
567 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
568 | } |
||
569 | } |
||
570 | else |
||
571 | { |
||
572 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
573 | } |
||
574 | } |
||
575 | else |
||
576 | { |
||
577 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
578 | } |
||
579 | } |
||
580 | else |
||
581 | { |
||
582 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
583 | } |
||
584 | |||
585 | if (_LMSymbol != null) |
||
586 | { |
||
587 | _LMSymbol.Commit(); |
||
588 | equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
589 | ReleaseCOMObjects(_LMSymbol); |
||
590 | } |
||
591 | |||
592 | if (targetItem != null) |
||
593 | { |
||
594 | ReleaseCOMObjects(targetItem); |
||
595 | } |
||
596 | |||
597 | ReleaseCOMObjects(_LMSymbol); |
||
598 | f31645b6 | gaqhf | |
599 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
600 | b9e9f4c8 | gaqhf | } |
601 | |||
602 | 4b4dbca9 | gaqhf | private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol) |
603 | ac78b508 | gaqhf | { |
604 | 4b4dbca9 | gaqhf | Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()]; |
605 | double x1 = 0; |
||
606 | double x2 = 0; |
||
607 | double y1 = 0; |
||
608 | double y2 = 0; |
||
609 | symbol2d.Range(out x1, out y1, out x2, out y2); |
||
610 | |||
611 | LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol); |
||
612 | if (_LMSymbol != null) |
||
613 | { |
||
614 | childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
615 | foreach (var item in childSymbol.ChildSymbols) |
||
616 | CreateChildSymbol(item, _LMSymbol); |
||
617 | } |
||
618 | |||
619 | ac78b508 | gaqhf | |
620 | ReleaseCOMObjects(_LMSymbol); |
||
621 | } |
||
622 | |||
623 | 809a7640 | gaqhf | private bool IsSameLineNumber(object item, object targetItem) |
624 | { |
||
625 | foreach (var lineNumber in document.LINENUMBERS) |
||
626 | { |
||
627 | foreach (var run in lineNumber.RUNS) |
||
628 | { |
||
629 | foreach (var runItem in run.RUNITEMS) |
||
630 | { |
||
631 | if (runItem == item) |
||
632 | { |
||
633 | foreach (var findItem in run.RUNITEMS) |
||
634 | { |
||
635 | if (findItem == targetItem) |
||
636 | { |
||
637 | return true; |
||
638 | } |
||
639 | } |
||
640 | |||
641 | return false; |
||
642 | |||
643 | } |
||
644 | } |
||
645 | } |
||
646 | } |
||
647 | |||
648 | return false; |
||
649 | } |
||
650 | |||
651 | 1b261371 | gaqhf | private void LineModeling(List<Line> lines) |
652 | { |
||
653 | 335b7a24 | gaqhf | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
654 | 1b261371 | gaqhf | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
655 | f1c9dbaa | gaqhf | LMSymbol _LMSymbol1 = null; |
656 | LMSymbol _LMSymbol2 = null; |
||
657 | 5e6ecf05 | gaqhf | Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
658 | LMConnector targetConnector1 = null; |
||
659 | Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
||
660 | LMConnector targetConnector2 = null; |
||
661 | 335b7a24 | gaqhf | |
662 | Line startBranchLine = null; |
||
663 | Line endBranchLine = null; |
||
664 | |||
665 | 1b261371 | gaqhf | for (int i = 0; i < lines.Count; i++) |
666 | { |
||
667 | Line line = lines[i]; |
||
668 | f1c9dbaa | gaqhf | if (i == 0 || i + 1 != lines.Count) |
669 | { |
||
670 | 809a7640 | gaqhf | // 시작점에 연결된 Symbol 찾기 |
671 | f1c9dbaa | gaqhf | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
672 | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
||
673 | { |
||
674 | f2baa6a3 | gaqhf | _LMSymbol1 = GetTargetSymbol(connItem as Symbol, line); |
675 | f1c9dbaa | gaqhf | if (_LMSymbol1 != null) |
676 | placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y); |
||
677 | else |
||
678 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
679 | } |
||
680 | 335b7a24 | gaqhf | else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
681 | 5e6ecf05 | gaqhf | { |
682 | connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
||
683 | 56bc67e1 | gaqhf | targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
684 | 5e6ecf05 | gaqhf | |
685 | if (targetConnector1 != null) |
||
686 | placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y); |
||
687 | else |
||
688 | 335b7a24 | gaqhf | { |
689 | startBranchLine = connItem as Line; |
||
690 | 5e6ecf05 | gaqhf | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
691 | 335b7a24 | gaqhf | } |
692 | 5e6ecf05 | gaqhf | } |
693 | f1c9dbaa | gaqhf | else |
694 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
695 | } |
||
696 | |||
697 | if (i + 1 == lines.Count) |
||
698 | { |
||
699 | 809a7640 | gaqhf | // 끝점에 연결된 Symbol 찾기 |
700 | f1c9dbaa | gaqhf | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
701 | 5e6ecf05 | gaqhf | |
702 | if (i != 0) |
||
703 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
704 | |||
705 | f1c9dbaa | gaqhf | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
706 | { |
||
707 | f2baa6a3 | gaqhf | _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line); |
708 | f1c9dbaa | gaqhf | if (_LMSymbol2 != null) |
709 | placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y); |
||
710 | else |
||
711 | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
||
712 | |||
713 | } |
||
714 | 335b7a24 | gaqhf | else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
715 | 5e6ecf05 | gaqhf | { |
716 | connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
||
717 | 56bc67e1 | gaqhf | targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y); |
718 | 5e6ecf05 | gaqhf | |
719 | if (targetConnector2 != null) |
||
720 | placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y); |
||
721 | else |
||
722 | 335b7a24 | gaqhf | { |
723 | endBranchLine = connItem as Line; |
||
724 | 5e6ecf05 | gaqhf | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
725 | 335b7a24 | gaqhf | } |
726 | 5e6ecf05 | gaqhf | } |
727 | f1c9dbaa | gaqhf | else |
728 | { |
||
729 | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
||
730 | } |
||
731 | } |
||
732 | } |
||
733 | |||
734 | LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
735 | 335b7a24 | gaqhf | |
736 | f1c9dbaa | gaqhf | if (_lMConnector != null) |
737 | { |
||
738 | foreach (var line in lines) |
||
739 | 5e6ecf05 | gaqhf | line.SPPID.ModelItemId = _lMConnector.ModelItemID; |
740 | f1c9dbaa | gaqhf | _lMConnector.Commit(); |
741 | 335b7a24 | gaqhf | if (startBranchLine != null || endBranchLine != null) |
742 | { |
||
743 | 3165c259 | gaqhf | BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine)); |
744 | 335b7a24 | gaqhf | } |
745 | 1b261371 | gaqhf | } |
746 | 5e6ecf05 | gaqhf | |
747 | 1b261371 | gaqhf | |
748 | f1c9dbaa | gaqhf | if (_LMSymbol1 != null) |
749 | ReleaseCOMObjects(_LMSymbol1); |
||
750 | if (_LMSymbol2 != null) |
||
751 | ReleaseCOMObjects(_LMSymbol2); |
||
752 | 5e6ecf05 | gaqhf | if (targetConnector1 != null) |
753 | ReleaseCOMObjects(targetConnector1); |
||
754 | if (targetConnector2 != null) |
||
755 | ReleaseCOMObjects(targetConnector2); |
||
756 | foreach (var item in connectorVertices1) |
||
757 | ReleaseCOMObjects(item.Key); |
||
758 | foreach (var item in connectorVertices2) |
||
759 | ReleaseCOMObjects(item.Key); |
||
760 | 1b261371 | gaqhf | |
761 | f1c9dbaa | gaqhf | ReleaseCOMObjects(_lMConnector); |
762 | 1b261371 | gaqhf | ReleaseCOMObjects(placeRunInputs); |
763 | ReleaseCOMObjects(_LMAItem); |
||
764 | } |
||
765 | |||
766 | f2baa6a3 | gaqhf | private LMSymbol GetTargetSymbol(Symbol symbol, Line line) |
767 | { |
||
768 | LMSymbol _LMSymbol = null; |
||
769 | foreach (var connector in symbol.CONNECTORS) |
||
770 | { |
||
771 | if (connector.CONNECTEDITEM == line.UID) |
||
772 | { |
||
773 | if (connector.Index == 0) |
||
774 | _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
775 | else |
||
776 | { |
||
777 | ChildSymbol child = null; |
||
778 | foreach (var childSymbol in symbol.ChildSymbols) |
||
779 | { |
||
780 | if (childSymbol.Connectors.Contains(connector)) |
||
781 | child = childSymbol; |
||
782 | else |
||
783 | child = GetChildSymbolByConnector(childSymbol, connector); |
||
784 | |||
785 | if (child != null) |
||
786 | break; |
||
787 | } |
||
788 | |||
789 | if (child != null) |
||
790 | _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
||
791 | } |
||
792 | |||
793 | break; |
||
794 | } |
||
795 | } |
||
796 | |||
797 | return _LMSymbol; |
||
798 | } |
||
799 | |||
800 | private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
||
801 | { |
||
802 | foreach (var childSymbol in item.ChildSymbols) |
||
803 | { |
||
804 | if (childSymbol.Connectors.Contains(connector)) |
||
805 | return childSymbol; |
||
806 | else |
||
807 | return GetChildSymbolByConnector(childSymbol, connector); |
||
808 | } |
||
809 | |||
810 | return null; |
||
811 | } |
||
812 | |||
813 | 335b7a24 | gaqhf | private void BranchLineModeling(Tuple<string, Line, Line> branch) |
814 | { |
||
815 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
||
816 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
||
817 | |||
818 | 8b085570 | gaqhf | LMConnector _StartConnector = null; |
819 | LMConnector _EndConnector = null; |
||
820 | 335b7a24 | gaqhf | double lengthStart = double.MaxValue; |
821 | double lengthEnd = double.MaxValue; |
||
822 | List<double[]> startPoints = new List<double[]>(); |
||
823 | List<double[]> endPoints = new List<double[]>(); |
||
824 | |||
825 | foreach (var item in connectorVertices) |
||
826 | { |
||
827 | foreach (var point in item.Value) |
||
828 | { |
||
829 | // Start Point가 Branch |
||
830 | if (branch.Item2 != null) |
||
831 | { |
||
832 | Line targetLine = branch.Item2; |
||
833 | double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
||
834 | if (lengthStart > distance) |
||
835 | { |
||
836 | 8b085570 | gaqhf | _StartConnector = item.Key; |
837 | 335b7a24 | gaqhf | lengthStart = distance; |
838 | startPoints = item.Value; |
||
839 | } |
||
840 | } |
||
841 | // End Point가 Branch |
||
842 | if (branch.Item3 != null) |
||
843 | { |
||
844 | Line targetLine = branch.Item3; |
||
845 | double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
||
846 | if (lengthEnd > distance) |
||
847 | { |
||
848 | 8b085570 | gaqhf | _EndConnector = item.Key; |
849 | 335b7a24 | gaqhf | lengthEnd = distance; |
850 | endPoints = item.Value; |
||
851 | } |
||
852 | } |
||
853 | } |
||
854 | } |
||
855 | #region Branch가 양쪽 전부일 때 |
||
856 | 8b085570 | gaqhf | if (_StartConnector != null && _StartConnector == _EndConnector) |
857 | 335b7a24 | gaqhf | { |
858 | 8b085570 | gaqhf | _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
859 | 335b7a24 | gaqhf | |
860 | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
||
861 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
862 | |||
863 | Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
||
864 | 8b085570 | gaqhf | LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
865 | 335b7a24 | gaqhf | Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
866 | 8b085570 | gaqhf | LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices, |
867 | 335b7a24 | gaqhf | startPoints[startPoints.Count - 1][0], |
868 | startPoints[startPoints.Count - 1][1], |
||
869 | startPoints[startPoints.Count - 2][0], |
||
870 | startPoints[startPoints.Count - 2][1]); |
||
871 | |||
872 | for (int i = 0; i < startPoints.Count; i++) |
||
873 | { |
||
874 | double[] point = startPoints[i]; |
||
875 | if (i == 0) |
||
876 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
877 | 335b7a24 | gaqhf | else if (i == startPoints.Count - 1) |
878 | 8b085570 | gaqhf | placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
879 | 335b7a24 | gaqhf | else |
880 | placeRunInputs.AddPoint(point[0], point[1]); |
||
881 | } |
||
882 | |||
883 | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
884 | if (_LMConnector != null) |
||
885 | { |
||
886 | _LMConnector.Commit(); |
||
887 | foreach (var item in lines) |
||
888 | item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
889 | } |
||
890 | |||
891 | foreach (var item in startConnectorVertices) |
||
892 | ReleaseCOMObjects(item.Key); |
||
893 | foreach (var item in endConnectorVertices) |
||
894 | ReleaseCOMObjects(item.Key); |
||
895 | ReleaseCOMObjects(placeRunInputs); |
||
896 | ReleaseCOMObjects(_LMAItem); |
||
897 | ReleaseCOMObjects(_LMConnector); |
||
898 | } |
||
899 | #endregion |
||
900 | 8b085570 | gaqhf | #region 양쪽이 다른 Branch |
901 | 335b7a24 | gaqhf | else |
902 | { |
||
903 | // Branch 시작 Connector |
||
904 | 8b085570 | gaqhf | if (_StartConnector != null) |
905 | 6b298450 | gaqhf | BranchLineModelingByConnector(branch, _StartConnector, startPoints, true); |
906 | 335b7a24 | gaqhf | |
907 | 6b298450 | gaqhf | // Branch 끝 Connector |
908 | if (_EndConnector != null) |
||
909 | BranchLineModelingByConnector(branch, _EndConnector, endPoints, false); |
||
910 | } |
||
911 | #endregion |
||
912 | 335b7a24 | gaqhf | |
913 | 6b298450 | gaqhf | if (_StartConnector != null) |
914 | ReleaseCOMObjects(_StartConnector); |
||
915 | if (_EndConnector != null) |
||
916 | ReleaseCOMObjects(_EndConnector); |
||
917 | foreach (var item in connectorVertices) |
||
918 | ReleaseCOMObjects(item.Key); |
||
919 | } |
||
920 | 335b7a24 | gaqhf | |
921 | 6b298450 | gaqhf | private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart) |
922 | { |
||
923 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
||
924 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
||
925 | LMConnector _SameRunTargetConnector = null; |
||
926 | LMSymbol _SameRunTargetSymbol = null; |
||
927 | Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null; |
||
928 | LMConnector _BranchTargetConnector = null; |
||
929 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
930 | 335b7a24 | gaqhf | |
931 | 6b298450 | gaqhf | // 같은 Line Run의 Connector 찾기 |
932 | foreach (var item in connectorVertices) |
||
933 | { |
||
934 | if (item.Key == _Connector) |
||
935 | continue; |
||
936 | 335b7a24 | gaqhf | |
937 | 6b298450 | gaqhf | if (IsStart && |
938 | !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) && |
||
939 | !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& |
||
940 | item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID) |
||
941 | { |
||
942 | _SameRunTargetConnector = item.Key; |
||
943 | break; |
||
944 | } |
||
945 | else if (!IsStart && |
||
946 | !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) && |
||
947 | !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && |
||
948 | item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID) |
||
949 | { |
||
950 | _SameRunTargetConnector = item.Key; |
||
951 | break; |
||
952 | } |
||
953 | } |
||
954 | |||
955 | // Branch 반대편이 Symbol |
||
956 | if (_SameRunTargetConnector == null) |
||
957 | { |
||
958 | foreach (var line in lines) |
||
959 | { |
||
960 | foreach (var connector in line.CONNECTORS) |
||
961 | 335b7a24 | gaqhf | { |
962 | 6b298450 | gaqhf | Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
963 | if (symbol != null) |
||
964 | 335b7a24 | gaqhf | { |
965 | 6b298450 | gaqhf | _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
966 | break; |
||
967 | 335b7a24 | gaqhf | } |
968 | } |
||
969 | 6b298450 | gaqhf | } |
970 | } |
||
971 | 335b7a24 | gaqhf | |
972 | 6b298450 | gaqhf | // 기존 Connector 제거 |
973 | _placement.PIDRemovePlacement(_Connector.AsLMRepresentation()); |
||
974 | |||
975 | // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함 |
||
976 | if (IsStart) |
||
977 | { |
||
978 | branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
||
979 | _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]); |
||
980 | } |
||
981 | // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함 |
||
982 | else |
||
983 | { |
||
984 | branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
||
985 | _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, |
||
986 | points[points.Count - 1][0], |
||
987 | points[points.Count - 1][1], |
||
988 | points[points.Count - 2][0], |
||
989 | points[points.Count - 2][1]); |
||
990 | } |
||
991 | 335b7a24 | gaqhf | |
992 | 6b298450 | gaqhf | for (int i = 0; i < points.Count; i++) |
993 | { |
||
994 | double[] point = points[i]; |
||
995 | if (i == 0) |
||
996 | 335b7a24 | gaqhf | { |
997 | 6b298450 | gaqhf | if (IsStart) |
998 | 335b7a24 | gaqhf | { |
999 | 6b298450 | gaqhf | placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
1000 | 335b7a24 | gaqhf | } |
1001 | 6b298450 | gaqhf | else |
1002 | 335b7a24 | gaqhf | { |
1003 | 6b298450 | gaqhf | if (_SameRunTargetConnector != null) |
1004 | placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
||
1005 | 65a1ed4b | gaqhf | else if (_SameRunTargetSymbol != null) |
1006 | 6b298450 | gaqhf | placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
1007 | else |
||
1008 | placeRunInputs.AddPoint(point[0], point[1]); |
||
1009 | 335b7a24 | gaqhf | } |
1010 | 6b298450 | gaqhf | } |
1011 | else if (i == points.Count - 1) |
||
1012 | { |
||
1013 | if (IsStart) |
||
1014 | 335b7a24 | gaqhf | { |
1015 | 6b298450 | gaqhf | if (_SameRunTargetConnector != null) |
1016 | placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
||
1017 | else if (_SameRunTargetSymbol != null) |
||
1018 | placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
||
1019 | 335b7a24 | gaqhf | else |
1020 | placeRunInputs.AddPoint(point[0], point[1]); |
||
1021 | } |
||
1022 | 6b298450 | gaqhf | else |
1023 | 335b7a24 | gaqhf | { |
1024 | f9125a54 | gaqhf | if (_BranchTargetConnector != null) |
1025 | { |
||
1026 | placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
||
1027 | } |
||
1028 | 335b7a24 | gaqhf | } |
1029 | 6b298450 | gaqhf | } |
1030 | else |
||
1031 | placeRunInputs.AddPoint(point[0], point[1]); |
||
1032 | } |
||
1033 | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
||
1034 | LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
1035 | 335b7a24 | gaqhf | |
1036 | 6b298450 | gaqhf | if (_LMConnector != null) |
1037 | { |
||
1038 | if (_SameRunTargetConnector != null) |
||
1039 | { |
||
1040 | JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID); |
||
1041 | } |
||
1042 | else |
||
1043 | { |
||
1044 | foreach (var item in lines) |
||
1045 | item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
1046 | 335b7a24 | gaqhf | } |
1047 | |||
1048 | 6b298450 | gaqhf | _LMConnector.Commit(); |
1049 | ReleaseCOMObjects(_LMConnector); |
||
1050 | 335b7a24 | gaqhf | } |
1051 | |||
1052 | 6b298450 | gaqhf | ReleaseCOMObjects(placeRunInputs); |
1053 | ReleaseCOMObjects(_LMAItem); |
||
1054 | if (_BranchTargetConnector != null) |
||
1055 | ReleaseCOMObjects(_BranchTargetConnector); |
||
1056 | if (_SameRunTargetConnector != null) |
||
1057 | ReleaseCOMObjects(_SameRunTargetConnector); |
||
1058 | if (_SameRunTargetSymbol != null) |
||
1059 | ReleaseCOMObjects(_SameRunTargetSymbol); |
||
1060 | 335b7a24 | gaqhf | foreach (var item in connectorVertices) |
1061 | ReleaseCOMObjects(item.Key); |
||
1062 | 6b298450 | gaqhf | foreach (var item in branchConnectorVertices) |
1063 | ReleaseCOMObjects(item.Key); |
||
1064 | 335b7a24 | gaqhf | } |
1065 | |||
1066 | 3165c259 | gaqhf | private void EndBreakModeling(EndBreak endBreak) |
1067 | 335b7a24 | gaqhf | { |
1068 | 10c7195c | gaqhf | object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
1069 | 2a4872ec | gaqhf | LMConnector targetLMConnector = null; |
1070 | 10c7195c | gaqhf | if (ownerObj !=null && ownerObj.GetType() == typeof(Line)) |
1071 | 335b7a24 | gaqhf | { |
1072 | 10c7195c | gaqhf | Line ownerLine = ownerObj as Line; |
1073 | 3165c259 | gaqhf | LMLabelPersist _LmLabelPersist = null; |
1074 | ac78b508 | gaqhf | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId); |
1075 | 3165c259 | gaqhf | |
1076 | 2a4872ec | gaqhf | targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1077 | b9e9f4c8 | gaqhf | |
1078 | 2a4872ec | gaqhf | if (targetLMConnector != null) |
1079 | 335b7a24 | gaqhf | { |
1080 | c3d2e266 | gaqhf | //double[] point = connectorVertices[targetLMConnector][connectorVertices[targetLMConnector].Count - 1]; |
1081 | //Array array = new double[] { 0, point[0], point[1] }; |
||
1082 | ac78b508 | gaqhf | Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1083 | 2a4872ec | gaqhf | _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1084 | ac78b508 | gaqhf | } |
1085 | 3165c259 | gaqhf | |
1086 | ac78b508 | gaqhf | if (_LmLabelPersist != null) |
1087 | { |
||
1088 | _LmLabelPersist.Commit(); |
||
1089 | ReleaseCOMObjects(_LmLabelPersist); |
||
1090 | 335b7a24 | gaqhf | } |
1091 | b9e9f4c8 | gaqhf | else |
1092 | 2a4872ec | gaqhf | RetryEndBreakModeling(endBreak, targetLMConnector); |
1093 | b9e9f4c8 | gaqhf | |
1094 | ac78b508 | gaqhf | foreach (var item in connectorVertices) |
1095 | ReleaseCOMObjects(item.Key); |
||
1096 | 2a4872ec | gaqhf | |
1097 | 335b7a24 | gaqhf | } |
1098 | 10c7195c | gaqhf | else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol)) |
1099 | { |
||
1100 | Symbol ownerSymbol = ownerObj as Symbol; |
||
1101 | LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId); |
||
1102 | |||
1103 | 2a4872ec | gaqhf | targetLMConnector = null; |
1104 | 10c7195c | gaqhf | double distance = double.MaxValue; |
1105 | b9e9f4c8 | gaqhf | |
1106 | 10c7195c | gaqhf | foreach (LMConnector connector in _LMSymbol.Avoid1Connectors) |
1107 | { |
||
1108 | 26c6f818 | gaqhf | if (connector.get_ItemStatus() == "Active") |
1109 | 10c7195c | gaqhf | { |
1110 | 26c6f818 | gaqhf | dynamic OID = connector.get_GraphicOID(); |
1111 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
1112 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
1113 | int verticesCount = lineStringGeometry.VertexCount; |
||
1114 | double[] vertices = null; |
||
1115 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1116 | for (int i = 0; i < verticesCount; i++) |
||
1117 | 10c7195c | gaqhf | { |
1118 | 26c6f818 | gaqhf | double x = 0; |
1119 | double y = 0; |
||
1120 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
1121 | |||
1122 | b9e9f4c8 | gaqhf | double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1123 | 26c6f818 | gaqhf | if (result < distance) |
1124 | { |
||
1125 | targetLMConnector = connector; |
||
1126 | distance = result; |
||
1127 | } |
||
1128 | 10c7195c | gaqhf | } |
1129 | } |
||
1130 | } |
||
1131 | |||
1132 | foreach (LMConnector connector in _LMSymbol.Avoid2Connectors) |
||
1133 | { |
||
1134 | b9e9f4c8 | gaqhf | if (connector.get_ItemStatus() == "Active") |
1135 | 10c7195c | gaqhf | { |
1136 | b9e9f4c8 | gaqhf | dynamic OID = connector.get_GraphicOID(); |
1137 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
1138 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
1139 | int verticesCount = lineStringGeometry.VertexCount; |
||
1140 | double[] vertices = null; |
||
1141 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1142 | for (int i = 0; i < verticesCount; i++) |
||
1143 | 10c7195c | gaqhf | { |
1144 | b9e9f4c8 | gaqhf | double x = 0; |
1145 | double y = 0; |
||
1146 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
1147 | |||
1148 | double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
||
1149 | if (result < distance) |
||
1150 | { |
||
1151 | targetLMConnector = connector; |
||
1152 | distance = result; |
||
1153 | } |
||
1154 | 10c7195c | gaqhf | } |
1155 | } |
||
1156 | } |
||
1157 | |||
1158 | if (targetLMConnector != null) |
||
1159 | { |
||
1160 | LMLabelPersist _LmLabelPersist = null; |
||
1161 | Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
||
1162 | _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
||
1163 | if (_LmLabelPersist != null) |
||
1164 | { |
||
1165 | _LmLabelPersist.Commit(); |
||
1166 | ReleaseCOMObjects(_LmLabelPersist); |
||
1167 | } |
||
1168 | b9e9f4c8 | gaqhf | else |
1169 | 2a4872ec | gaqhf | RetryEndBreakModeling(endBreak, targetLMConnector); |
1170 | } |
||
1171 | |||
1172 | ReleaseCOMObjects(_LMSymbol); |
||
1173 | } |
||
1174 | f31645b6 | gaqhf | |
1175 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1176 | 2a4872ec | gaqhf | } |
1177 | b9e9f4c8 | gaqhf | |
1178 | 2a4872ec | gaqhf | private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector) |
1179 | { |
||
1180 | bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength()); |
||
1181 | Array array = null; |
||
1182 | LMLabelPersist _LMLabelPersist = null; |
||
1183 | LMConnector _LMConnector = null; |
||
1184 | dynamic OID = targetLMConnector.get_GraphicOID(); |
||
1185 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
1186 | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
||
1187 | int verticesCount = lineStringGeometry.VertexCount; |
||
1188 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
1189 | _LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym"); |
||
1190 | b9e9f4c8 | gaqhf | |
1191 | 2a4872ec | gaqhf | if (isZeroLength) |
1192 | { |
||
1193 | double[] vertices = null; |
||
1194 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1195 | double x = 0; |
||
1196 | double y = 0; |
||
1197 | lineStringGeometry.GetVertex(1, ref x, ref y); |
||
1198 | b9e9f4c8 | gaqhf | |
1199 | 2a4872ec | gaqhf | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y); |
1200 | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y); |
||
1201 | b9e9f4c8 | gaqhf | |
1202 | 2a4872ec | gaqhf | _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1203 | _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
1204 | |||
1205 | array = new double[] { 0, x, y }; |
||
1206 | _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
||
1207 | 5a83fda2 | gaqhf | |
1208 | AutoJoinPipeRun(_LMConnector.ModelItemID); |
||
1209 | 2a4872ec | gaqhf | } |
1210 | else |
||
1211 | { |
||
1212 | List<double[]> vertices = new List<double[]>(); |
||
1213 | for (int i = 1; i <= verticesCount; i++) |
||
1214 | { |
||
1215 | double x = 0; |
||
1216 | double y = 0; |
||
1217 | lineStringGeometry.GetVertex(i, ref x, ref y); |
||
1218 | vertices.Add(new double[] { x, y }); |
||
1219 | } |
||
1220 | |||
1221 | for (int i = 0; i < vertices.Count; i++) |
||
1222 | { |
||
1223 | double[] points = vertices[i]; |
||
1224 | if (i == 0) |
||
1225 | { |
||
1226 | if (targetLMConnector.ConnectItem1SymbolObject != null) |
||
1227 | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]); |
||
1228 | else |
||
1229 | placeRunInputs.AddPoint(points[0], points[1]); |
||
1230 | b9e9f4c8 | gaqhf | } |
1231 | 2a4872ec | gaqhf | else if (i == vertices.Count - 1) |
1232 | { |
||
1233 | if (targetLMConnector.ConnectItem2SymbolObject != null) |
||
1234 | placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]); |
||
1235 | else |
||
1236 | placeRunInputs.AddPoint(points[0], points[1]); |
||
1237 | } |
||
1238 | else |
||
1239 | placeRunInputs.AddPoint(points[0], points[1]); |
||
1240 | 10c7195c | gaqhf | } |
1241 | 2a4872ec | gaqhf | |
1242 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID); |
||
1243 | b9e9f4c8 | gaqhf | |
1244 | 2a4872ec | gaqhf | _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1245 | _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
1246 | |||
1247 | array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
||
1248 | _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
||
1249 | 3939eebf | gaqhf | |
1250 | AutoJoinPipeRun(_LMConnector.ModelItemID); |
||
1251 | foreach (var line in lines) |
||
1252 | line.SPPID.ModelItemId = _LMConnector.ModelItemID; |
||
1253 | 10c7195c | gaqhf | } |
1254 | 2a4872ec | gaqhf | |
1255 | |||
1256 | if (_LMLabelPersist != null) |
||
1257 | { |
||
1258 | _LMLabelPersist.Commit(); |
||
1259 | ReleaseCOMObjects(_LMLabelPersist); |
||
1260 | } |
||
1261 | else |
||
1262 | { |
||
1263 | |||
1264 | } |
||
1265 | |||
1266 | ReleaseCOMObjects(_LMConnector); |
||
1267 | ReleaseCOMObjects(placeRunInputs); |
||
1268 | ReleaseCOMObjects(_LMAItem); |
||
1269 | 3165c259 | gaqhf | } |
1270 | 10872260 | gaqhf | |
1271 | 335b7a24 | gaqhf | private void JoinPipeRun(string fromModelItemId, string toModelItemId) |
1272 | { |
||
1273 | 310aeb31 | gaqhf | LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId); |
1274 | _LMAItem item1 = modelItem1.AsLMAItem(); |
||
1275 | LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId); |
||
1276 | _LMAItem item2 = modelItem2.AsLMAItem(); |
||
1277 | |||
1278 | 335b7a24 | gaqhf | // item2가 item1으로 조인 |
1279 | try |
||
1280 | { |
||
1281 | _placement.PIDJoinRuns(ref item1, ref item2); |
||
1282 | 65a1ed4b | gaqhf | item1.Commit(); |
1283 | item2.Commit(); |
||
1284 | 3939eebf | gaqhf | |
1285 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId); |
||
1286 | foreach (var line in lines) |
||
1287 | line.SPPID.ModelItemId = toModelItemId; |
||
1288 | 335b7a24 | gaqhf | } |
1289 | catch (Exception ex) |
||
1290 | { |
||
1291 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
1292 | } |
||
1293 | finally |
||
1294 | { |
||
1295 | 310aeb31 | gaqhf | ReleaseCOMObjects(modelItem1); |
1296 | ReleaseCOMObjects(item1); |
||
1297 | ReleaseCOMObjects(modelItem2); |
||
1298 | ReleaseCOMObjects(item2); |
||
1299 | 335b7a24 | gaqhf | } |
1300 | } |
||
1301 | |||
1302 | private void AutoJoinPipeRun(string modelItemId) |
||
1303 | { |
||
1304 | 310aeb31 | gaqhf | LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
1305 | _LMAItem item = modelItem.AsLMAItem(); |
||
1306 | 65a1ed4b | gaqhf | try |
1307 | { |
||
1308 | string modelitemID = item.Id; |
||
1309 | _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
||
1310 | string afterModelItemID = item.Id; |
||
1311 | 5a83fda2 | gaqhf | |
1312 | 65a1ed4b | gaqhf | if (modelitemID != afterModelItemID) |
1313 | { |
||
1314 | List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID); |
||
1315 | foreach (var line in lines) |
||
1316 | line.SPPID.ModelItemId = afterModelItemID; |
||
1317 | } |
||
1318 | item.Commit(); |
||
1319 | } |
||
1320 | catch (Exception ex) |
||
1321 | { |
||
1322 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
1323 | } |
||
1324 | finally |
||
1325 | { |
||
1326 | 310aeb31 | gaqhf | ReleaseCOMObjects(modelItem); |
1327 | ReleaseCOMObjects(item); |
||
1328 | 65a1ed4b | gaqhf | } |
1329 | 335b7a24 | gaqhf | } |
1330 | |||
1331 | private void JoinRunLine(LineRun run) |
||
1332 | { |
||
1333 | string modelItemId = string.Empty; |
||
1334 | foreach (var item in run.RUNITEMS) |
||
1335 | { |
||
1336 | if (item.GetType() == typeof(Line)) |
||
1337 | { |
||
1338 | Line line = item as Line; |
||
1339 | 1ba9c671 | gaqhf | AutoJoinPipeRun(line.SPPID.ModelItemId); |
1340 | modelItemId = line.SPPID.ModelItemId; |
||
1341 | f31645b6 | gaqhf | |
1342 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1343 | 335b7a24 | gaqhf | } |
1344 | } |
||
1345 | } |
||
1346 | |||
1347 | 5e6ecf05 | gaqhf | private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
1348 | { |
||
1349 | Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
||
1350 | 310aeb31 | gaqhf | LMModelItem modelItem = dataSource.GetModelItem(modelId); |
1351 | |||
1352 | if (modelItem != null) |
||
1353 | 5e6ecf05 | gaqhf | { |
1354 | 310aeb31 | gaqhf | foreach (LMRepresentation rep in modelItem.Representations) |
1355 | 5e6ecf05 | gaqhf | { |
1356 | if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
||
1357 | { |
||
1358 | LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
||
1359 | connectorVertices.Add(_LMConnector, new List<double[]>()); |
||
1360 | dynamic OID = rep.get_GraphicOID(); |
||
1361 | 335b7a24 | gaqhf | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1362 | 5e6ecf05 | gaqhf | Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1363 | int verticesCount = lineStringGeometry.VertexCount; |
||
1364 | double[] vertices = null; |
||
1365 | lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
||
1366 | for (int i = 0; i < verticesCount; i++) |
||
1367 | { |
||
1368 | double x = 0; |
||
1369 | double y = 0; |
||
1370 | lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
||
1371 | 335b7a24 | gaqhf | connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) }); |
1372 | 5e6ecf05 | gaqhf | } |
1373 | } |
||
1374 | } |
||
1375 | |||
1376 | 310aeb31 | gaqhf | ReleaseCOMObjects(modelItem); |
1377 | 5e6ecf05 | gaqhf | } |
1378 | |||
1379 | return connectorVertices; |
||
1380 | } |
||
1381 | |||
1382 | 56bc67e1 | gaqhf | private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2) |
1383 | 5e6ecf05 | gaqhf | { |
1384 | double length = double.MaxValue; |
||
1385 | LMConnector targetConnector = null; |
||
1386 | foreach (var item in connectorVertices) |
||
1387 | { |
||
1388 | List<double[]> points = item.Value; |
||
1389 | for (int i = 0; i < points.Count - 1; i++) |
||
1390 | { |
||
1391 | double[] point1 = points[i]; |
||
1392 | double[] point2 = points[i + 1]; |
||
1393 | |||
1394 | 335b7a24 | gaqhf | double maxLineX = Math.Max(point1[0], point2[0]); |
1395 | double minLineX = Math.Min(point1[0], point2[0]); |
||
1396 | double maxLineY = Math.Max(point1[1], point2[1]); |
||
1397 | double minLineY = Math.Min(point1[1], point2[1]); |
||
1398 | |||
1399 | SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
||
1400 | |||
1401 | 56bc67e1 | gaqhf | // 두직선의 교차점 |
1402 | double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
||
1403 | if (crossingPoint != null) |
||
1404 | 5e6ecf05 | gaqhf | { |
1405 | 30a9ffce | gaqhf | double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]); |
1406 | 335b7a24 | gaqhf | if (length >= distance) |
1407 | 30a9ffce | gaqhf | { |
1408 | 335b7a24 | gaqhf | if (slope == SlopeType.Slope && |
1409 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
||
1410 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
1411 | { |
||
1412 | targetConnector = item.Key; |
||
1413 | length = distance; |
||
1414 | } |
||
1415 | else if (slope == SlopeType.HORIZONTAL && |
||
1416 | minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
||
1417 | { |
||
1418 | targetConnector = item.Key; |
||
1419 | length = distance; |
||
1420 | } |
||
1421 | else if (slope == SlopeType.VERTICAL && |
||
1422 | minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
||
1423 | { |
||
1424 | targetConnector = item.Key; |
||
1425 | length = distance; |
||
1426 | } |
||
1427 | 30a9ffce | gaqhf | } |
1428 | 5e6ecf05 | gaqhf | } |
1429 | } |
||
1430 | c3d2e266 | gaqhf | |
1431 | |||
1432 | } |
||
1433 | |||
1434 | if (targetConnector == null) |
||
1435 | { |
||
1436 | foreach (var item in connectorVertices) |
||
1437 | { |
||
1438 | List<double[]> points = item.Value; |
||
1439 | foreach (var point in points) |
||
1440 | { |
||
1441 | double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]); |
||
1442 | if (length >= distance) |
||
1443 | { |
||
1444 | targetConnector = item.Key; |
||
1445 | length = distance; |
||
1446 | } |
||
1447 | } |
||
1448 | } |
||
1449 | |||
1450 | 5e6ecf05 | gaqhf | } |
1451 | |||
1452 | return targetConnector; |
||
1453 | } |
||
1454 | |||
1455 | ac78b508 | gaqhf | private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
1456 | { |
||
1457 | double length = double.MaxValue; |
||
1458 | LMConnector targetConnector = null; |
||
1459 | foreach (var item in connectorVertices) |
||
1460 | { |
||
1461 | List<double[]> points = item.Value; |
||
1462 | |||
1463 | foreach (double[] point in points) |
||
1464 | { |
||
1465 | double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
||
1466 | if (length >= distance) |
||
1467 | { |
||
1468 | targetConnector = item.Key; |
||
1469 | length = distance; |
||
1470 | } |
||
1471 | } |
||
1472 | } |
||
1473 | |||
1474 | return targetConnector; |
||
1475 | } |
||
1476 | |||
1477 | 68464385 | gaqhf | private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
1478 | { |
||
1479 | double length = double.MaxValue; |
||
1480 | LMConnector targetConnector = null; |
||
1481 | foreach (var item in connectorVertices) |
||
1482 | { |
||
1483 | List<double[]> points = item.Value; |
||
1484 | for (int i = 0; i < points.Count - 1; i++) |
||
1485 | { |
||
1486 | double[] point1 = points[i]; |
||
1487 | double[] point2 = points[i + 1]; |
||
1488 | double x1 = Math.Min(point1[0], point2[0]); |
||
1489 | double y1 = Math.Min(point1[1], point2[1]); |
||
1490 | double x2 = Math.Max(point1[0], point2[0]); |
||
1491 | double y2 = Math.Max(point1[1], point2[1]); |
||
1492 | |||
1493 | if ((x1 <= connX && x2 >= connX) || |
||
1494 | (y1 <= connY && y2 >= connY)) |
||
1495 | { |
||
1496 | double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
||
1497 | if (length >= distance) |
||
1498 | { |
||
1499 | targetConnector = item.Key; |
||
1500 | length = distance; |
||
1501 | } |
||
1502 | |||
1503 | distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
||
1504 | if (length >= distance) |
||
1505 | { |
||
1506 | targetConnector = item.Key; |
||
1507 | length = distance; |
||
1508 | } |
||
1509 | } |
||
1510 | } |
||
1511 | } |
||
1512 | |||
1513 | // 못찾았을때. |
||
1514 | length = double.MaxValue; |
||
1515 | if (targetConnector == null) |
||
1516 | { |
||
1517 | foreach (var item in connectorVertices) |
||
1518 | { |
||
1519 | List<double[]> points = item.Value; |
||
1520 | |||
1521 | foreach (double[] point in points) |
||
1522 | { |
||
1523 | double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
||
1524 | if (length >= distance) |
||
1525 | { |
||
1526 | targetConnector = item.Key; |
||
1527 | length = distance; |
||
1528 | } |
||
1529 | } |
||
1530 | } |
||
1531 | } |
||
1532 | |||
1533 | return targetConnector; |
||
1534 | } |
||
1535 | |||
1536 | cfda1fed | gaqhf | private void LineNumberModeling(LineNumber lineNumber) |
1537 | { |
||
1538 | f4880c6a | gaqhf | Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
1539 | Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
||
1540 | 68464385 | gaqhf | LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y); |
1541 | f4880c6a | gaqhf | if (connectedLMConnector != null) |
1542 | 10872260 | gaqhf | { |
1543 | b65a7e32 | gaqhf | double x = 0; |
1544 | double y = 0; |
||
1545 | CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation); |
||
1546 | |||
1547 | Array points = new double[] { 0, x, y }; |
||
1548 | f4880c6a | gaqhf | LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false); |
1549 | cfda1fed | gaqhf | |
1550 | f4880c6a | gaqhf | foreach (var item in connectorVertices) |
1551 | ReleaseCOMObjects(item.Key); |
||
1552 | if (_LmLabelPresist != null) |
||
1553 | { |
||
1554 | c3d2e266 | gaqhf | _LmLabelPresist.Commit(); |
1555 | f4880c6a | gaqhf | lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
1556 | ReleaseCOMObjects(_LmLabelPresist); |
||
1557 | 10872260 | gaqhf | } |
1558 | c3d2e266 | gaqhf | else |
1559 | { |
||
1560 | |||
1561 | } |
||
1562 | 10872260 | gaqhf | } |
1563 | f31645b6 | gaqhf | |
1564 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1565 | cfda1fed | gaqhf | } |
1566 | |||
1567 | a7e9beec | gaqhf | private void InputLineNumberAttribute(LineNumber lineNumber) |
1568 | { |
||
1569 | 8634af60 | gaqhf | foreach (LineRun run in lineNumber.RUNS) |
1570 | a7e9beec | gaqhf | { |
1571 | 8634af60 | gaqhf | foreach (var item in run.RUNITEMS) |
1572 | a7e9beec | gaqhf | { |
1573 | 8634af60 | gaqhf | if (item.GetType() == typeof(Symbol)) |
1574 | a7e9beec | gaqhf | { |
1575 | 8634af60 | gaqhf | Symbol symbol = item as Symbol; |
1576 | LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1577 | LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
||
1578 | |||
1579 | if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
||
1580 | { |
||
1581 | foreach (var attribute in lineNumber.ATTRIBUTES) |
||
1582 | { |
||
1583 | LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
||
1584 | if (mapping != null) |
||
1585 | { |
||
1586 | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
1587 | if (_LMAAttribute != null) |
||
1588 | { |
||
1589 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
1590 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1591 | else if (_LMAAttribute.get_Value() != attribute.VALUE) |
||
1592 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1593 | } |
||
1594 | } |
||
1595 | } |
||
1596 | _LMModelItem.Commit(); |
||
1597 | } |
||
1598 | if (_LMModelItem != null) |
||
1599 | ReleaseCOMObjects(_LMModelItem); |
||
1600 | if (_LMSymbol != null) |
||
1601 | ReleaseCOMObjects(_LMSymbol); |
||
1602 | } |
||
1603 | else if (item.GetType() == typeof(Line)) |
||
1604 | { |
||
1605 | Line line = item as Line; |
||
1606 | if (line != null) |
||
1607 | a7e9beec | gaqhf | { |
1608 | 8634af60 | gaqhf | LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
1609 | if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
||
1610 | a7e9beec | gaqhf | { |
1611 | 8634af60 | gaqhf | foreach (var attribute in lineNumber.ATTRIBUTES) |
1612 | { |
||
1613 | LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
||
1614 | if (mapping != null) |
||
1615 | { |
||
1616 | LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
1617 | if (_LMAAttribute != null) |
||
1618 | { |
||
1619 | if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
||
1620 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1621 | else if (_LMAAttribute.get_Value() != attribute.VALUE) |
||
1622 | _LMAAttribute.set_Value(attribute.VALUE); |
||
1623 | |||
1624 | } |
||
1625 | } |
||
1626 | } |
||
1627 | 68464385 | gaqhf | _LMModelItem.Commit(); |
1628 | a7e9beec | gaqhf | } |
1629 | 8634af60 | gaqhf | if (_LMModelItem != null) |
1630 | ReleaseCOMObjects(_LMModelItem); |
||
1631 | a7e9beec | gaqhf | } |
1632 | } |
||
1633 | } |
||
1634 | } |
||
1635 | f31645b6 | gaqhf | |
1636 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1637 | a7e9beec | gaqhf | } |
1638 | |||
1639 | 1efc25a3 | gaqhf | private void InputSymbolAttribute(Symbol symbol) |
1640 | { |
||
1641 | ac78b508 | gaqhf | try |
1642 | 1efc25a3 | gaqhf | { |
1643 | ac78b508 | gaqhf | if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
1644 | 402ef5b1 | gaqhf | { |
1645 | ac78b508 | gaqhf | LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1646 | 310aeb31 | gaqhf | LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
1647 | ea80efaa | gaqhf | LMAAttributes _Attributes = _LMModelItem.Attributes; |
1648 | 402ef5b1 | gaqhf | |
1649 | ac78b508 | gaqhf | foreach (var item in symbol.PROPERTIES) |
1650 | { |
||
1651 | 1efc25a3 | gaqhf | |
1652 | |||
1653 | ac78b508 | gaqhf | } |
1654 | |||
1655 | foreach (var item in symbol.ATTRIBUTES) |
||
1656 | 65a1ed4b | gaqhf | { |
1657 | ac78b508 | gaqhf | AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
1658 | 26c6f818 | gaqhf | if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
1659 | ac78b508 | gaqhf | { |
1660 | LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
||
1661 | if (_Attribute != null) |
||
1662 | 8b069d9f | gaqhf | { |
1663 | // 임시 |
||
1664 | if (item.ATTRIBUTETYPE == "String") |
||
1665 | { |
||
1666 | if (!string.IsNullOrEmpty(item.VALUE)) |
||
1667 | { |
||
1668 | if (!DBNull.Value.Equals(_Attribute.get_Value()) && !string.IsNullOrEmpty(_Attribute.get_Value())) |
||
1669 | { |
||
1670 | string value = _Attribute.get_Value() + "\n" + item.VALUE; |
||
1671 | _Attribute.set_Value(value); |
||
1672 | } |
||
1673 | else |
||
1674 | { |
||
1675 | _Attribute.set_Value(item.VALUE); |
||
1676 | } |
||
1677 | } |
||
1678 | } |
||
1679 | else |
||
1680 | { |
||
1681 | _Attribute.set_Value(item.VALUE); |
||
1682 | } |
||
1683 | } |
||
1684 | ac78b508 | gaqhf | } |
1685 | 65a1ed4b | gaqhf | } |
1686 | 1efc25a3 | gaqhf | |
1687 | ac78b508 | gaqhf | foreach (var item in symbol.ASSOCIATIONS) |
1688 | { |
||
1689 | 1efc25a3 | gaqhf | |
1690 | ac78b508 | gaqhf | } |
1691 | 402ef5b1 | gaqhf | |
1692 | ac78b508 | gaqhf | ReleaseCOMObjects(_LMSymbol); |
1693 | ea80efaa | gaqhf | ReleaseCOMObjects(_Attributes); |
1694 | ReleaseCOMObjects(_LMModelItem); |
||
1695 | ac78b508 | gaqhf | } |
1696 | } |
||
1697 | catch (Exception ex) |
||
1698 | { |
||
1699 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
1700 | 1efc25a3 | gaqhf | } |
1701 | f31645b6 | gaqhf | |
1702 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1703 | 1efc25a3 | gaqhf | } |
1704 | |||
1705 | cfda1fed | gaqhf | private void TextModeling(Text text) |
1706 | { |
||
1707 | 6b298450 | gaqhf | LMSymbol _LMSymbol = null; |
1708 | try |
||
1709 | { |
||
1710 | 8b069d9f | gaqhf | //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None") |
1711 | if (text.ASSOCIATION) |
||
1712 | ea80efaa | gaqhf | { |
1713 | object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
||
1714 | if (owner.GetType() == typeof(Symbol)) |
||
1715 | { |
||
1716 | Symbol symbol = owner as Symbol; |
||
1717 | _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
||
1718 | if (_LMSymbol != null) |
||
1719 | { |
||
1720 | Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID); |
||
1721 | List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE); |
||
1722 | AttributeMapping mapping = null; |
||
1723 | foreach (var attribute in attributes) |
||
1724 | { |
||
1725 | 26c6f818 | gaqhf | if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None") |
1726 | continue; |
||
1727 | |||
1728 | ea80efaa | gaqhf | mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
1729 | if (mapping != null) |
||
1730 | break; |
||
1731 | } |
||
1732 | |||
1733 | if (mapping != null) |
||
1734 | { |
||
1735 | 1a3a74a8 | gaqhf | double x = 0; |
1736 | double y = 0; |
||
1737 | |||
1738 | b65a7e32 | gaqhf | CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
1739 | Array array = new double[] { 0, x, y }; |
||
1740 | 1a3a74a8 | gaqhf | |
1741 | 1ba9c671 | gaqhf | LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
1742 | ea80efaa | gaqhf | if (_LMLabelPersist!=null) |
1743 | { |
||
1744 | f9125a54 | gaqhf | _LMLabelPersist.Commit(); |
1745 | ea80efaa | gaqhf | ReleaseCOMObjects(_LMLabelPersist); |
1746 | } |
||
1747 | } |
||
1748 | } |
||
1749 | } |
||
1750 | else if (owner.GetType() == typeof(Line)) |
||
1751 | { |
||
1752 | |||
1753 | } |
||
1754 | } |
||
1755 | else |
||
1756 | { |
||
1757 | LMItemNote _LMItemNote = null; |
||
1758 | LMAAttribute _LMAAttribute = null; |
||
1759 | |||
1760 | b65a7e32 | gaqhf | double x = 0; |
1761 | double y = 0; |
||
1762 | |||
1763 | CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation); |
||
1764 | |||
1765 | _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y); |
||
1766 | ea80efaa | gaqhf | _LMSymbol.Commit(); |
1767 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
1768 | _LMItemNote.Commit(); |
||
1769 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
1770 | _LMAAttribute.set_Value(text.VALUE); |
||
1771 | _LMItemNote.Commit(); |
||
1772 | |||
1773 | if (_LMAAttribute != null) |
||
1774 | ReleaseCOMObjects(_LMAAttribute); |
||
1775 | if (_LMItemNote != null) |
||
1776 | ReleaseCOMObjects(_LMItemNote); |
||
1777 | } |
||
1778 | 6b298450 | gaqhf | } |
1779 | catch (Exception ex) |
||
1780 | { |
||
1781 | cfda1fed | gaqhf | |
1782 | 6b298450 | gaqhf | } |
1783 | finally |
||
1784 | { |
||
1785 | if (_LMSymbol != null) |
||
1786 | ReleaseCOMObjects(_LMSymbol); |
||
1787 | } |
||
1788 | f31645b6 | gaqhf | |
1789 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1790 | cfda1fed | gaqhf | } |
1791 | |||
1792 | private void NoteModeling(Note note) |
||
1793 | { |
||
1794 | 6b298450 | gaqhf | LMSymbol _LMSymbol = null; |
1795 | LMItemNote _LMItemNote = null; |
||
1796 | LMAAttribute _LMAAttribute = null; |
||
1797 | |||
1798 | try |
||
1799 | { |
||
1800 | b65a7e32 | gaqhf | double x = 0; |
1801 | double y = 0; |
||
1802 | |||
1803 | CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation); |
||
1804 | |||
1805 | _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y); |
||
1806 | 6b298450 | gaqhf | _LMSymbol.Commit(); |
1807 | _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
||
1808 | _LMItemNote.Commit(); |
||
1809 | _LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
||
1810 | _LMAAttribute.set_Value(note.VALUE); |
||
1811 | _LMItemNote.Commit(); |
||
1812 | } |
||
1813 | catch (Exception ex) |
||
1814 | { |
||
1815 | cfda1fed | gaqhf | |
1816 | 6b298450 | gaqhf | } |
1817 | finally |
||
1818 | { |
||
1819 | if (_LMAAttribute != null) |
||
1820 | ReleaseCOMObjects(_LMAAttribute); |
||
1821 | if (_LMItemNote != null) |
||
1822 | ReleaseCOMObjects(_LMItemNote); |
||
1823 | if (_LMSymbol != null) |
||
1824 | ReleaseCOMObjects(_LMSymbol); |
||
1825 | } |
||
1826 | f31645b6 | gaqhf | |
1827 | SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
||
1828 | cfda1fed | gaqhf | } |
1829 | |||
1830 | b65a7e32 | gaqhf | private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location) |
1831 | { |
||
1832 | if (location == Location.None) |
||
1833 | { |
||
1834 | x = originX; |
||
1835 | y = originY; |
||
1836 | } |
||
1837 | else |
||
1838 | { |
||
1839 | if (location.HasFlag(Location.Center)) |
||
1840 | { |
||
1841 | x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2; |
||
1842 | y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2; |
||
1843 | } |
||
1844 | |||
1845 | if (location.HasFlag(Location.Left)) |
||
1846 | x = SPPIDLabelLocation.X1; |
||
1847 | else if (location.HasFlag(Location.Right)) |
||
1848 | x = SPPIDLabelLocation.X2; |
||
1849 | |||
1850 | if (location.HasFlag(Location.Down)) |
||
1851 | y = SPPIDLabelLocation.Y1; |
||
1852 | else if (location.HasFlag(Location.Up)) |
||
1853 | y = SPPIDLabelLocation.Y2; |
||
1854 | } |
||
1855 | } |
||
1856 | 5a4b8f32 | gaqhf | |
1857 | public void ReleaseCOMObjects(params object[] objVars) |
||
1858 | { |
||
1859 | int intNewRefCount = 0; |
||
1860 | foreach (object obj in objVars) |
||
1861 | { |
||
1862 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
1863 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
1864 | } |
||
1865 | } |
||
1866 | cfda1fed | gaqhf | } |
1867 | } |