hytos / DTI_PID / APIDConverter / AutoModeling.cs @ 87f22597
이력 | 보기 | 이력해설 | 다운로드 (41.1 KB)
1 | 74a0c9d6 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | 016701e5 | gaqhf | using System.Collections; |
4 | 74a0c9d6 | gaqhf | using System.Configuration; |
5 | using System.Data; |
||
6 | using System.Data.Common; |
||
7 | using System.Data.SqlClient; |
||
8 | using System.IO; |
||
9 | 5c05308b | gaqhf | using System.Runtime.CompilerServices; |
10 | using Microsoft.VisualBasic.CompilerServices; |
||
11 | c8b025e0 | gaqhf | using System.Runtime.InteropServices; |
12 | using System.Threading; |
||
13 | 74a0c9d6 | gaqhf | |
14 | using Autodesk.AutoCAD.ApplicationServices; |
||
15 | using Autodesk.AutoCAD.ApplicationServices.Core; |
||
16 | using Autodesk.AutoCAD.DatabaseServices; |
||
17 | using Autodesk.AutoCAD.EditorInput; |
||
18 | using Autodesk.AutoCAD.Geometry; |
||
19 | using Autodesk.AutoCAD.Interop; |
||
20 | using Autodesk.AutoCAD.Interop.Common; |
||
21 | using Autodesk.AutoCAD.Runtime; |
||
22 | using Autodesk.AutoCAD.Windows; |
||
23 | |||
24 | 1c5bd296 | gaqhf | using AVEVA.PID.Components; |
25 | using AVEVA.PID.GUI; |
||
26 | using AVEVA.PID.Common; |
||
27 | using AVEVA.PID.DWGSelector; |
||
28 | 495bb8f5 | gaqhf | using AVEVA.PID.Utilities; |
29 | 1c5bd296 | gaqhf | |
30 | 14540282 | gaqhf | using AVEVA.PID.CustomizationUtility.DB; |
31 | using AVEVA.PID.CustomizationUtility.Model; |
||
32 | using AVEVA.PID.CustomizationUtility.Properties; |
||
33 | 74a0c9d6 | gaqhf | |
34 | aba318eb | gaqhf | using DevExpress.XtraSplashScreen; |
35 | |||
36 | 74a0c9d6 | gaqhf | namespace AVEVA.PID.CustomizationUtility |
37 | { |
||
38 | public class AutoModeling |
||
39 | { |
||
40 | c8b025e0 | gaqhf | [DllImport("user32")] |
41 | public static extern int FindWindow(string lpClassName, string lpWindowName); |
||
42 | |||
43 | 1c5bd296 | gaqhf | public static AutoModeling Running { get; set; } |
44 | 14540282 | gaqhf | Model.Document document; |
45 | dfb760ef | gaqhf | AvevaInfo avevaInfo; |
46 | 495bb8f5 | gaqhf | |
47 | a19bd6e2 | gaqhf | private void SetConvertRule() |
48 | { |
||
49 | #region OPC Setting |
||
50 | document.OPCs.Sort(SortOPC); |
||
51 | int SortOPC(OPC a, OPC b) |
||
52 | { |
||
53 | if (a.FlowType == FlowType.In) |
||
54 | return 1; |
||
55 | else |
||
56 | return 0; |
||
57 | } |
||
58 | #endregion |
||
59 | } |
||
60 | |||
61 | dfb760ef | gaqhf | public AutoModeling(Model.Document document) |
62 | 74a0c9d6 | gaqhf | { |
63 | 14540282 | gaqhf | this.document = document; |
64 | dfb760ef | gaqhf | avevaInfo = AvevaInfo.GetInstance(); |
65 | 74a0c9d6 | gaqhf | } |
66 | |||
67 | 1c5bd296 | gaqhf | public void CreateDrawing() |
68 | 46756c13 | gaqhf | { |
69 | 1c5bd296 | gaqhf | string outPath = Project_DB.GetDirectiveValue("DRGPTH"); |
70 | string tempPath = Path.GetTempPath(); |
||
71 | string selectedFullPath = Path.Combine(tempPath, document.AvevaTemplateName + ".DWT"); |
||
72 | |||
73 | DWTSelector.strDrawingNumber = document.AvevaDrawingNumber; |
||
74 | DWTSelector.strSheetNumber = document.AvevaSheetNumber; |
||
75 | DWTSelector.strCadFileName = document.AvevaDrawingNumber + document.AvevaSheetNumber; |
||
76 | DWTSelector.strCadFilePath = outPath; |
||
77 | |||
78 | try |
||
79 | 46756c13 | gaqhf | { |
80 | 1c5bd296 | gaqhf | string text = ReadWriteDrawingData.ReadTemplateData(document.AvevaTemplateName, document.AvevaTemplateID, selectedFullPath, false); |
81 | Autodesk.AutoCAD.Interop.AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication; |
||
82 | Autodesk.AutoCAD.Interop.AcadDocument acadDocument = acadApplication.Documents.Add(text); |
||
83 | |||
84 | Commands.addLatestPidvesrionToDictionary(); |
||
85 | AVVPropCmd.ActivateAcad(); |
||
86 | |||
87 | if (acadDocument != null) |
||
88 | { |
||
89 | Running = this; |
||
90 | acadApplication.ActiveDocument = acadDocument; |
||
91 | acadDocument.SendCommand("QSAVE "); |
||
92 | acadDocument.SendCommand("APPIDRun "); |
||
93 | 9dab7146 | gaqhf | acadDocument.SendCommand("QSAVE "); |
94 | 1c5bd296 | gaqhf | Running = null; |
95 | } |
||
96 | 46756c13 | gaqhf | } |
97 | 1c5bd296 | gaqhf | catch (System.Exception ex) |
98 | { |
||
99 | |||
100 | } |
||
101 | |||
102 | GC.Collect(); |
||
103 | } |
||
104 | public void Run() |
||
105 | { |
||
106 | 016701e5 | gaqhf | try |
107 | { |
||
108 | aba318eb | gaqhf | SplashScreenManager.ShowForm(typeof(APIDSplashScreen), true, true); |
109 | dfb760ef | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllStepCount, 8); |
110 | aba318eb | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetDocumentName, document.AvevaDrawingNumber + document.AvevaSheetNumber); |
111 | 932933ed | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetParent, Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle); |
112 | |||
113 | a19bd6e2 | gaqhf | SetConvertRule(); |
114 | aba318eb | gaqhf | |
115 | 016701e5 | gaqhf | RunLineModeling(); |
116 | a19bd6e2 | gaqhf | RunOPCModeling(); |
117 | 016701e5 | gaqhf | RunSymbolModeling(); |
118 | 475071f2 | gaqhf | RunTextModeling(); |
119 | 6503fec8 | gaqhf | RunNoteModeling(); |
120 | dfb760ef | gaqhf | RunInputLineAttribute(); |
121 | RunInputLineNumberAttribute(); |
||
122 | RunInputSymbolAttribute(); |
||
123 | 016701e5 | gaqhf | } |
124 | catch (System.Exception ex) |
||
125 | { |
||
126 | System.Windows.Forms.MessageBox.Show(ex.Message + @"\n" + ex.StackTrace); |
||
127 | } |
||
128 | aba318eb | gaqhf | finally |
129 | { |
||
130 | 932933ed | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.ClearParent, null); |
131 | aba318eb | gaqhf | SplashScreenManager.CloseForm(false); |
132 | } |
||
133 | 46756c13 | gaqhf | } |
134 | |||
135 | 9dab7146 | gaqhf | #region Run Method |
136 | private void RunLineModeling() |
||
137 | 74a0c9d6 | gaqhf | { |
138 | aba318eb | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count); |
139 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling"); |
||
140 | 9dab7146 | gaqhf | foreach (var item in document.LINES) |
141 | 74a0c9d6 | gaqhf | { |
142 | 53344e2c | gaqhf | if (item.Aveva.Handle == 0) |
143 | LineModeling(item); |
||
144 | aba318eb | gaqhf | |
145 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
146 | 74a0c9d6 | gaqhf | } |
147 | 9dab7146 | gaqhf | } |
148 | a19bd6e2 | gaqhf | private void RunOPCModeling() |
149 | { |
||
150 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.OPCs.Count); |
||
151 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "OPC Modeling"); |
||
152 | foreach (var item in document.OPCs) |
||
153 | { |
||
154 | if (item.Aveva.Handle == 0) |
||
155 | SymbolModeling(item); |
||
156 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
157 | } |
||
158 | } |
||
159 | 016701e5 | gaqhf | private void RunSymbolModeling() |
160 | { |
||
161 | aba318eb | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
162 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling"); |
||
163 | b90890eb | gaqhf | foreach (var item in document.SYMBOLS) |
164 | { |
||
165 | if (item.Aveva.Handle == 0) |
||
166 | SymbolModeling(item); |
||
167 | aba318eb | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
168 | b90890eb | gaqhf | } |
169 | 016701e5 | gaqhf | } |
170 | 475071f2 | gaqhf | private void RunTextModeling() |
171 | { |
||
172 | 0a8db7fe | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Texts.Count); |
173 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Text Modeling"); |
||
174 | foreach (var item in document.Texts) |
||
175 | { |
||
176 | 6503fec8 | gaqhf | TextModeling(item); |
177 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
178 | } |
||
179 | } |
||
180 | private void RunNoteModeling() |
||
181 | { |
||
182 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Notes.Count); |
||
183 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Note Modeling"); |
||
184 | 7a8645c9 | gaqhf | foreach (var item in document.Notes) |
185 | 6503fec8 | gaqhf | { |
186 | 7a8645c9 | gaqhf | NoteModeling(item); |
187 | 0a8db7fe | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
188 | } |
||
189 | 475071f2 | gaqhf | } |
190 | 5c05308b | gaqhf | private void RunInputLineAttribute() |
191 | { |
||
192 | dfb760ef | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count); |
193 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Input Line Attribute"); |
||
194 | foreach (var item in document.LINES) |
||
195 | { |
||
196 | SetLineAttribute(item); |
||
197 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
198 | } |
||
199 | 5c05308b | gaqhf | } |
200 | private void RunInputSymbolAttribute() |
||
201 | { |
||
202 | dfb760ef | gaqhf | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
203 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Input Symbol Attribute"); |
||
204 | foreach (var item in document.SYMBOLS) |
||
205 | { |
||
206 | SetSymbolAttribute(item); |
||
207 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
208 | } |
||
209 | } |
||
210 | private void RunInputLineNumberAttribute() |
||
211 | { |
||
212 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count); |
||
213 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Input LineNumber Attribute"); |
||
214 | foreach (var item in document.LINENUMBERS) |
||
215 | { |
||
216 | SetLineNumberAttribute(item); |
||
217 | SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
||
218 | } |
||
219 | 5c05308b | gaqhf | } |
220 | 9dab7146 | gaqhf | #endregion |
221 | 74a0c9d6 | gaqhf | |
222 | 9dab7146 | gaqhf | #region Modeling Method |
223 | private void LineModeling(Model.Line line) |
||
224 | { |
||
225 | 53344e2c | gaqhf | List<Model.Line> groupLine = new List<Model.Line>(); |
226 | 9dab7146 | gaqhf | List<string> points = new List<string>(); |
227 | 016701e5 | gaqhf | GetConnectedGroupLine(line, groupLine, false); |
228 | 53344e2c | gaqhf | GetGroupLinePoints(groupLine, points); |
229 | 9dab7146 | gaqhf | |
230 | 932933ed | gaqhf | LineNumber lineNumber = null; |
231 | if (line.Aveva.Type == Model.Type.Pipe) |
||
232 | { |
||
233 | foreach (var item in groupLine) |
||
234 | { |
||
235 | lineNumber = document.LINENUMBERS.Find(x => x.CONNLINE == item.UID); |
||
236 | if (lineNumber != null) |
||
237 | { |
||
238 | GUIUtils.SetAutoLabelCheck(true); |
||
239 | c94252bf | gaqhf | AvevaThread.Run(ThreadType.LineNumberModeling, null); |
240 | 932933ed | gaqhf | break; |
241 | } |
||
242 | } |
||
243 | } |
||
244 | |||
245 | 53344e2c | gaqhf | long handle = 0; |
246 | 9dab7146 | gaqhf | if (line.Aveva.Type == Model.Type.Pipe) |
247 | 932933ed | gaqhf | handle = DrawPipe(line.Aveva.Name, points, lineNumber); |
248 | 9dab7146 | gaqhf | else if (line.Aveva.Type == Model.Type.Signal) |
249 | 53344e2c | gaqhf | handle = DrawSignal(line.Aveva.Name, points); |
250 | |||
251 | 932933ed | gaqhf | if (lineNumber != null) |
252 | c8b025e0 | gaqhf | { |
253 | 932933ed | gaqhf | GUIUtils.SetAutoLabelCheck(false); |
254 | c94252bf | gaqhf | AvevaThread.Stop(ThreadType.LineNumberModeling); |
255 | c8b025e0 | gaqhf | } |
256 | 932933ed | gaqhf | |
257 | 53344e2c | gaqhf | foreach (var item in groupLine) |
258 | item.Aveva.Handle = handle; |
||
259 | 74a0c9d6 | gaqhf | } |
260 | b90890eb | gaqhf | private void SymbolModeling(Symbol symbol) |
261 | { |
||
262 | dfb760ef | gaqhf | DataRow[] allRows = avevaInfo.AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name)); |
263 | 495bb8f5 | gaqhf | if (allRows.Length == 1) |
264 | 2d09df82 | gaqhf | { |
265 | 495bb8f5 | gaqhf | DataRow symbolRow = allRows[0]; |
266 | bool bAngle = CheckAngle(symbolRow); |
||
267 | bool bBalloon = CheckBalloon(symbol); |
||
268 | |||
269 | long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon); |
||
270 | if (handle != 0) |
||
271 | 2d09df82 | gaqhf | { |
272 | 495bb8f5 | gaqhf | symbol.Aveva.Handle = handle; |
273 | |||
274 | if (!bAngle) |
||
275 | { |
||
276 | ObjectId objectId = GetObjectIdByHandle(handle); |
||
277 | if (objectId != ObjectId.Null) |
||
278 | { |
||
279 | SetBlockReferenceRotation(objectId, symbol.ANGLE); |
||
280 | } |
||
281 | } |
||
282 | 2d09df82 | gaqhf | } |
283 | } |
||
284 | b90890eb | gaqhf | } |
285 | 6503fec8 | gaqhf | private void TextModeling(Text text) |
286 | { |
||
287 | if (text.TextAngle == TextAngle.None) |
||
288 | return; |
||
289 | |||
290 | if (text.Aveva.LabelType == LabelType.SingleText) |
||
291 | a03f7b94 | gaqhf | DrawText(text.Aveva.X, text.Aveva.Y, text.Aveva.Height, text.VALUE, text.Aveva.Angle); |
292 | 6503fec8 | gaqhf | else if (text.Aveva.LabelType == LabelType.MultiText) |
293 | 7a8645c9 | gaqhf | { |
294 | string[] valueArray = text.VALUE.Split(new string[] { "\n" }, StringSplitOptions.None); |
||
295 | List<string> values = new List<string>(); |
||
296 | for (int i = 0; i < valueArray.Length; i++) |
||
297 | values.Insert(0, valueArray[i]); |
||
298 | |||
299 | for (int i = 0; i < values.Count; i++) |
||
300 | { |
||
301 | double x = text.Aveva.X; |
||
302 | double y = text.Aveva.Y; |
||
303 | int heightIndex = i; |
||
304 | |||
305 | if (text.TextAngle == TextAngle.Degree0 || text.TextAngle == TextAngle.Degree180) |
||
306 | y = y + text.Aveva.Height * i; |
||
307 | else if (text.TextAngle == TextAngle.Degree90 || text.TextAngle == TextAngle.Degree270) |
||
308 | x = x + text.Aveva.Height * i; |
||
309 | |||
310 | a03f7b94 | gaqhf | DrawText(x, y, text.Aveva.Height, values[i], text.Aveva.Angle); |
311 | 7a8645c9 | gaqhf | } |
312 | } |
||
313 | |||
314 | 6503fec8 | gaqhf | |
315 | } |
||
316 | private void NoteModeling(Model.Note note) |
||
317 | { |
||
318 | if (note.TextAngle == TextAngle.None) |
||
319 | return; |
||
320 | |||
321 | if (note.Aveva.LabelType == LabelType.SingleNote) |
||
322 | a03f7b94 | gaqhf | DrawText(note.Aveva.X, note.Aveva.Y, note.Aveva.Height, note.VALUE, note.Aveva.Angle); |
323 | 6503fec8 | gaqhf | else if (note.Aveva.LabelType == LabelType.MultiNote) |
324 | 7a8645c9 | gaqhf | { |
325 | string[] valueArray = note.VALUE.Split(new string[] { "\n" }, StringSplitOptions.None); |
||
326 | List<string> values = new List<string>(); |
||
327 | for (int i = 0; i < valueArray.Length; i++) |
||
328 | values.Insert(0, valueArray[i]); |
||
329 | |||
330 | for (int i = 0; i < values.Count; i++) |
||
331 | { |
||
332 | double x = note.Aveva.X; |
||
333 | double y = note.Aveva.Y; |
||
334 | int heightIndex = i; |
||
335 | |||
336 | if (note.TextAngle == TextAngle.Degree0 || note.TextAngle == TextAngle.Degree180) |
||
337 | y = y + note.Aveva.Height * i; |
||
338 | else if (note.TextAngle == TextAngle.Degree90 || note.TextAngle == TextAngle.Degree270) |
||
339 | x = x + note.Aveva.Height * i; |
||
340 | 6503fec8 | gaqhf | |
341 | a03f7b94 | gaqhf | DrawText(x, y, note.Aveva.Height, values[i], note.Aveva.Angle); |
342 | 7a8645c9 | gaqhf | } |
343 | } |
||
344 | 6503fec8 | gaqhf | } |
345 | 5c05308b | gaqhf | private void SetLineAttribute(Model.Line line) |
346 | { |
||
347 | |||
348 | } |
||
349 | dfb760ef | gaqhf | private void SetLineNumberAttribute(Model.LineNumber lineNumber) |
350 | { |
||
351 | c8b025e0 | gaqhf | Model.Line line = APIDUtils.FindObjectByUID(document, lineNumber.CONNLINE) as Model.Line; |
352 | c94252bf | gaqhf | if (line != null && line.Aveva.Handle != 0) |
353 | c8b025e0 | gaqhf | { |
354 | c94252bf | gaqhf | List<Tuple<string, string>> datas = new List<Tuple<string, string>>(); |
355 | c8b025e0 | gaqhf | foreach (Model.Attribute attribute in lineNumber.ATTRIBUTES) |
356 | { |
||
357 | AttributeInfo info = avevaInfo.AttributeInfo.Find(x => x.UID == attribute.UID); |
||
358 | c94252bf | gaqhf | if (info != null && !string.IsNullOrEmpty(info.APID_ATTRIBUTE)) |
359 | 87f22597 | gaqhf | { |
360 | if (info.APID_ATTRIBUTE_TYPE == AvevaAttributeType.UDA) |
||
361 | datas.Add(new Tuple<string, string>("UDA" + info.APID_ATTRIBUTE, attribute.VALUE)); |
||
362 | else |
||
363 | datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE)); |
||
364 | } |
||
365 | c94252bf | gaqhf | } |
366 | if (datas.Count > 0) |
||
367 | { |
||
368 | datas.Add(new Tuple<string, string>("AddLabel", "No")); |
||
369 | ObjectId objectId = GetFirstPolyLineObjectId(line.Aveva.Handle); |
||
370 | if (!objectId.IsNull) |
||
371 | SetAttributeByAvevaForm(objectId.Handle.Value, datas); |
||
372 | c8b025e0 | gaqhf | } |
373 | } |
||
374 | dfb760ef | gaqhf | } |
375 | 5c05308b | gaqhf | private void SetSymbolAttribute(Model.Symbol symbol) |
376 | { |
||
377 | c8b025e0 | gaqhf | if (symbol.Aveva.Handle != 0) |
378 | 4328cb06 | gaqhf | { |
379 | c94252bf | gaqhf | List<Tuple<string, string>> datas = new List<Tuple<string, string>>(); |
380 | c8b025e0 | gaqhf | foreach (var attribute in symbol.ATTRIBUTES) |
381 | 4328cb06 | gaqhf | { |
382 | c8b025e0 | gaqhf | AttributeInfo info = avevaInfo.AttributeInfo.Find(x => x.UID == attribute.UID); |
383 | c94252bf | gaqhf | if (info != null && !string.IsNullOrEmpty(info.APID_ATTRIBUTE)) |
384 | 87f22597 | gaqhf | { |
385 | if (info.APID_ATTRIBUTE_TYPE == AvevaAttributeType.UDA) |
||
386 | datas.Add(new Tuple<string, string>("UDA" + info.APID_ATTRIBUTE, attribute.VALUE)); |
||
387 | else |
||
388 | datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE)); |
||
389 | } |
||
390 | c94252bf | gaqhf | } |
391 | if (datas.Count > 0) |
||
392 | { |
||
393 | ObjectId objectId = GetObjectIdByHandle(symbol.Aveva.Handle); |
||
394 | if (!objectId.IsNull) |
||
395 | SetAttributeByAvevaForm(objectId.Handle.Value, datas); |
||
396 | 4328cb06 | gaqhf | } |
397 | } |
||
398 | 5c05308b | gaqhf | } |
399 | 9dab7146 | gaqhf | #endregion |
400 | 74a0c9d6 | gaqhf | |
401 | #region Drawing Method |
||
402 | 932933ed | gaqhf | private long DrawPipe(string style, List<string> coordinates, LineNumber lineNumber = null) |
403 | 74a0c9d6 | gaqhf | { |
404 | 9dab7146 | gaqhf | List<long> prevHandles = GetAllGroupHandles(); |
405 | 74a0c9d6 | gaqhf | |
406 | 9dab7146 | gaqhf | GUIUtils.SetPipeStyle(style); |
407 | 14540282 | gaqhf | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
408 | 74a0c9d6 | gaqhf | Editor editor = acDoc.Editor; |
409 | List<object> commandParam = new List<object>(); |
||
410 | //command name |
||
411 | commandParam.Add("DRPIPE"); |
||
412 | //coordinate |
||
413 | foreach (var item in coordinates) |
||
414 | commandParam.Add(item); |
||
415 | 932933ed | gaqhf | |
416 | //enter Parent(null) |
||
417 | 74a0c9d6 | gaqhf | commandParam.Add(null); |
418 | |||
419 | 932933ed | gaqhf | if (lineNumber != null) |
420 | { |
||
421 | Point3d point = new Point3d(lineNumber.Aveva.X, lineNumber.Aveva.Y, 0); |
||
422 | commandParam.Add(point); |
||
423 | 475071f2 | gaqhf | commandParam.Add(lineNumber.Aveva.Angle); |
424 | 932933ed | gaqhf | |
425 | commandParam.Add(null); |
||
426 | } |
||
427 | else |
||
428 | commandParam.Add(null); |
||
429 | |||
430 | 74a0c9d6 | gaqhf | editor.Command(commandParam.ToArray()); |
431 | |||
432 | 9dab7146 | gaqhf | List<long> newHandles = GetAllGroupHandles(); |
433 | List<long> otherHandles = new List<long>(); |
||
434 | foreach (var item in newHandles) |
||
435 | if (!prevHandles.Contains(item)) |
||
436 | otherHandles.Add(item); |
||
437 | 74a0c9d6 | gaqhf | |
438 | 9dab7146 | gaqhf | if (otherHandles.Count == 1) |
439 | return otherHandles[0]; |
||
440 | else |
||
441 | return 0; |
||
442 | 74a0c9d6 | gaqhf | } |
443 | 9dab7146 | gaqhf | private long DrawPipe(string style, List<string> coordinates, ObjectId objectId) |
444 | 74a0c9d6 | gaqhf | { |
445 | 9dab7146 | gaqhf | List<long> prevHandles = GetAllGroupHandles(); |
446 | 14540282 | gaqhf | GUIUtils.SetPipeStyle(style); |
447 | 74a0c9d6 | gaqhf | |
448 | 14540282 | gaqhf | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
449 | 74a0c9d6 | gaqhf | Editor editor = acDoc.Editor; |
450 | List<object> commandParam = new List<object>(); |
||
451 | //command name |
||
452 | commandParam.Add("DRPIPE"); |
||
453 | //coordinate |
||
454 | foreach (var item in coordinates) |
||
455 | commandParam.Add(item); |
||
456 | //enter |
||
457 | commandParam.Add(null); |
||
458 | |||
459 | //Input Object ID |
||
460 | commandParam.Add(objectId); |
||
461 | |||
462 | //enter |
||
463 | commandParam.Add(null); |
||
464 | |||
465 | editor.Command(commandParam.ToArray()); |
||
466 | 9dab7146 | gaqhf | |
467 | List<long> newHandles = GetAllGroupHandles(); |
||
468 | List<long> otherHandles = new List<long>(); |
||
469 | foreach (var item in newHandles) |
||
470 | if (!prevHandles.Contains(item)) |
||
471 | otherHandles.Add(item); |
||
472 | |||
473 | if (otherHandles.Count == 1) |
||
474 | return otherHandles[0]; |
||
475 | else |
||
476 | return 0; |
||
477 | } |
||
478 | private long DrawSignal(string style, List<string> coordinates) |
||
479 | { |
||
480 | List<long> prevHandles = GetAllGroupHandles(); |
||
481 | |||
482 | GUIUtils.SetPipeStyle(style); |
||
483 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
484 | Editor editor = acDoc.Editor; |
||
485 | List<object> commandParam = new List<object>(); |
||
486 | //command name |
||
487 | commandParam.Add("VPESIGNAL"); |
||
488 | //coordinate |
||
489 | foreach (var item in coordinates) |
||
490 | commandParam.Add(item); |
||
491 | //enter |
||
492 | commandParam.Add(null); |
||
493 | |||
494 | editor.Command(commandParam.ToArray()); |
||
495 | |||
496 | List<long> newHandles = GetAllGroupHandles(); |
||
497 | List<long> otherHandles = new List<long>(); |
||
498 | foreach (var item in newHandles) |
||
499 | if (!prevHandles.Contains(item)) |
||
500 | otherHandles.Add(item); |
||
501 | |||
502 | if (otherHandles.Count == 1) |
||
503 | return otherHandles[0]; |
||
504 | else |
||
505 | return 0; |
||
506 | 74a0c9d6 | gaqhf | } |
507 | 495bb8f5 | gaqhf | private long InsertSymbol(Symbol symbol, DataRow symbolRow, bool needAngle, bool needBalloon) |
508 | 6b3cb476 | gaqhf | { |
509 | 73152510 | gaqhf | long handle = 0; |
510 | 6b3cb476 | gaqhf | try |
511 | { |
||
512 | 495bb8f5 | gaqhf | string insertSymbolName = symbol.Aveva.Name; |
513 | double x = symbol.Aveva.X; |
||
514 | double y = symbol.Aveva.Y; |
||
515 | |||
516 | 73152510 | gaqhf | List<long> prevHandles = GetAllBlockHandlesByName(insertSymbolName); |
517 | |||
518 | 6b3cb476 | gaqhf | AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData(); |
519 | drawingData.InsertSymbolName = insertSymbolName; |
||
520 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
521 | Editor editor = acDoc.Editor; |
||
522 | List<object> commandParam = new List<object>(); |
||
523 | commandParam.Add("INSSYM"); |
||
524 | 495bb8f5 | gaqhf | |
525 | // Insert Point |
||
526 | 6b3cb476 | gaqhf | Point3d point = new Point3d(x, y, 0); |
527 | commandParam.Add(point); |
||
528 | 495bb8f5 | gaqhf | |
529 | // Check Insert Point |
||
530 | if (needAngle) |
||
531 | commandParam.Add(symbol.ANGLE); |
||
532 | |||
533 | // Check Balloon |
||
534 | if (needBalloon) |
||
535 | { |
||
536 | point = new Point3d(x + 20, y + 20, 0); |
||
537 | commandParam.Add(point); |
||
538 | |||
539 | // Check LeaderLine |
||
540 | if (GraphicalUtility.IsLeaderReqOnSymbolBalloons()) |
||
541 | commandParam.Add(x + "," + y); |
||
542 | } |
||
543 | |||
544 | for (int i = 0; i < 8; i++) |
||
545 | commandParam.Add(null); |
||
546 | 6b3cb476 | gaqhf | |
547 | editor.Command(commandParam.ToArray()); |
||
548 | 73152510 | gaqhf | |
549 | List<long> newHandles = GetAllBlockHandlesByName(insertSymbolName); |
||
550 | List<long> otherHandles = new List<long>(); |
||
551 | foreach (var item in newHandles) |
||
552 | if (!prevHandles.Contains(item)) |
||
553 | otherHandles.Add(item); |
||
554 | |||
555 | if (otherHandles.Count == 1) |
||
556 | return otherHandles[0]; |
||
557 | else |
||
558 | return 0; |
||
559 | 6b3cb476 | gaqhf | } |
560 | catch (System.Exception ex) |
||
561 | { |
||
562 | 74a0c9d6 | gaqhf | |
563 | 6b3cb476 | gaqhf | } |
564 | 73152510 | gaqhf | |
565 | return handle; |
||
566 | 6b3cb476 | gaqhf | } |
567 | a03f7b94 | gaqhf | private void DrawText(double x, double y, double height, string text, double rotation) |
568 | 6503fec8 | gaqhf | { |
569 | // Get the current document and database |
||
570 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
571 | Database acCurDb = acDoc.Database; |
||
572 | |||
573 | // Start a transaction |
||
574 | using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
||
575 | { |
||
576 | // Open the Block table for read |
||
577 | BlockTable acBlkTbl; |
||
578 | acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, |
||
579 | OpenMode.ForRead) as BlockTable; |
||
580 | |||
581 | // Open the Block table record Model space for write |
||
582 | BlockTableRecord acBlkTblRec; |
||
583 | acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], |
||
584 | OpenMode.ForWrite) as BlockTableRecord; |
||
585 | |||
586 | // Create a single-line text object |
||
587 | using (DBText acText = new DBText()) |
||
588 | { |
||
589 | acText.Position = new Point3d(x, y, 0); |
||
590 | acText.Height = height; |
||
591 | acText.TextString = text; |
||
592 | a03f7b94 | gaqhf | acText.Rotation = rotation; |
593 | 6503fec8 | gaqhf | |
594 | acBlkTblRec.AppendEntity(acText); |
||
595 | acTrans.AddNewlyCreatedDBObject(acText, true); |
||
596 | } |
||
597 | |||
598 | // Save the changes and dispose of the transaction |
||
599 | acTrans.Commit(); |
||
600 | } |
||
601 | } |
||
602 | 74a0c9d6 | gaqhf | #endregion |
603 | |||
604 | 73152510 | gaqhf | #region Autocad Utils |
605 | private List<long> GetAllBlockHandlesByName(string name) |
||
606 | { |
||
607 | List<long> handles = new List<long>(); |
||
608 | |||
609 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
610 | Database acCurDb = acDoc.Database; |
||
611 | using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
||
612 | { |
||
613 | BlockTable gd = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead); |
||
614 | foreach (var entry in gd) |
||
615 | { |
||
616 | BlockTableRecord blockTableRecord = acTrans.GetObject(entry, OpenMode.ForRead, true) as BlockTableRecord; |
||
617 | if (blockTableRecord != null) |
||
618 | { |
||
619 | IEnumerable<BlockReference> records = AcDbLinqExtensionMethods.GetBlockReferences(blockTableRecord); |
||
620 | foreach (var item in records) |
||
621 | { |
||
622 | if (item.Name == name) |
||
623 | handles.Add(item.Handle.Value); |
||
624 | } |
||
625 | } |
||
626 | } |
||
627 | |||
628 | acTrans.Commit(); |
||
629 | } |
||
630 | return handles; |
||
631 | } |
||
632 | 9dab7146 | gaqhf | private List<long> GetAllGroupHandles() |
633 | { |
||
634 | List<long> handles = new List<long>(); |
||
635 | |||
636 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
637 | Database acCurDb = acDoc.Database; |
||
638 | using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
||
639 | { |
||
640 | DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead); |
||
641 | foreach (var entry in gd) |
||
642 | handles.Add(entry.Value.Handle.Value); |
||
643 | acTrans.Commit(); |
||
644 | } |
||
645 | return handles; |
||
646 | } |
||
647 | c94252bf | gaqhf | private ObjectId GetFirstPolyLineObjectId(long groupHandle) |
648 | 9dab7146 | gaqhf | { |
649 | ObjectId result = ObjectId.Null; |
||
650 | |||
651 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
652 | Database acCurDb = acDoc.Database; |
||
653 | using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
||
654 | { |
||
655 | DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead); |
||
656 | foreach (var entry in gd) |
||
657 | { |
||
658 | if (entry.Value.Handle.Value == groupHandle) |
||
659 | { |
||
660 | Autodesk.AutoCAD.DatabaseServices.Group group = acTrans.GetObject(entry.Value, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Group; |
||
661 | foreach (var item in group.GetAllEntityIds()) |
||
662 | { |
||
663 | if (acTrans.GetObject(item, OpenMode.ForRead).GetType() == typeof(Autodesk.AutoCAD.DatabaseServices.Polyline)) |
||
664 | { |
||
665 | result = item; |
||
666 | break; |
||
667 | } |
||
668 | } |
||
669 | break; |
||
670 | } |
||
671 | } |
||
672 | acTrans.Commit(); |
||
673 | } |
||
674 | |||
675 | return result; |
||
676 | } |
||
677 | 2d09df82 | gaqhf | private ObjectId GetObjectIdByHandle(long lHandle) |
678 | { |
||
679 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
680 | Database acCurDb = acDoc.Database; |
||
681 | Handle handle = new Handle(lHandle); |
||
682 | c8b025e0 | gaqhf | ObjectId result = ObjectId.Null; |
683 | try |
||
684 | { |
||
685 | result = acCurDb.GetObjectId(false, handle, 0); |
||
686 | } |
||
687 | catch (System.Exception ex) |
||
688 | { |
||
689 | 2d09df82 | gaqhf | |
690 | c8b025e0 | gaqhf | } |
691 | return result; |
||
692 | } |
||
693 | private Entity GetEntityByHandle(long handle) |
||
694 | { |
||
695 | Entity entity = null; |
||
696 | ObjectId objectId = GetObjectIdByHandle(handle); |
||
697 | if (objectId != ObjectId.Null) |
||
698 | { |
||
699 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
700 | Database acCurDb = acDoc.Database; |
||
701 | using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
||
702 | { |
||
703 | entity = (Entity)acTrans.GetObject(objectId, OpenMode.ForRead); |
||
704 | acTrans.Commit(); |
||
705 | } |
||
706 | } |
||
707 | |||
708 | return entity; |
||
709 | 2d09df82 | gaqhf | } |
710 | private void SetBlockReferenceRotation(ObjectId objectId, double rotation) |
||
711 | { |
||
712 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
713 | Database acCurDb = acDoc.Database; |
||
714 | Editor acDocEd = acDoc.Editor; |
||
715 | |||
716 | using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
||
717 | { |
||
718 | DBObject objDB = acTrans.GetObject(objectId, OpenMode.ForWrite); |
||
719 | if (objDB != null) |
||
720 | { |
||
721 | if (objDB.GetType() == typeof(BlockReference)) |
||
722 | { |
||
723 | BlockReference block = objDB as BlockReference; |
||
724 | block.Rotation = rotation; |
||
725 | } |
||
726 | } |
||
727 | acTrans.Commit(); |
||
728 | } |
||
729 | } |
||
730 | c8b025e0 | gaqhf | #endregion |
731 | |||
732 | #region For Aveva |
||
733 | private void SetAttributeByAvevaForm(long handle, List<Tuple<string, string>> datas) |
||
734 | { |
||
735 | Entity entity = GetEntityByHandle(handle); |
||
736 | |||
737 | ComponentPropertiesHelper componentPropertiesHelper = new ComponentPropertiesHelper(); |
||
738 | AvevaThread.Run(ThreadType.AddProperty, datas); |
||
739 | if (!componentPropertiesHelper.DisplayComponentProperties(entity)) |
||
740 | AvevaThread.Stop(ThreadType.AddProperty); |
||
741 | } |
||
742 | 016701e5 | gaqhf | #endregion |
743 | |||
744 | 73152510 | gaqhf | #region Modeling Utils |
745 | 016701e5 | gaqhf | private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert) |
746 | 53344e2c | gaqhf | { |
747 | if (!group.Contains(line)) |
||
748 | { |
||
749 | 016701e5 | gaqhf | if (isInsert) |
750 | 53344e2c | gaqhf | group.Insert(0, line); |
751 | else |
||
752 | group.Add(line); |
||
753 | |||
754 | 016701e5 | gaqhf | if (line.CONNECTORS[0].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[0].ConnectedObject)) |
755 | { |
||
756 | object connObj = line.CONNECTORS[0].ConnectedObject; |
||
757 | if (connObj.GetType() == typeof(Model.Line) && |
||
758 | APIDUtils.IsConnectedLine(connObj as Model.Line, line)) |
||
759 | GetConnectedGroupLine(connObj as Model.Line, group, true); |
||
760 | else if (connObj.GetType() == typeof(Model.Symbol)) |
||
761 | { |
||
762 | Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol); |
||
763 | if (connLine != null) |
||
764 | GetConnectedGroupLine(connLine as Model.Line, group, true); |
||
765 | } |
||
766 | } |
||
767 | if (line.CONNECTORS[1].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[1].ConnectedObject)) |
||
768 | { |
||
769 | object connObj = line.CONNECTORS[1].ConnectedObject; |
||
770 | if (connObj.GetType() == typeof(Model.Line) && |
||
771 | APIDUtils.IsConnectedLine(connObj as Model.Line, line)) |
||
772 | GetConnectedGroupLine(connObj as Model.Line, group, false); |
||
773 | else if (connObj.GetType() == typeof(Model.Symbol)) |
||
774 | { |
||
775 | Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol); |
||
776 | if (connLine != null) |
||
777 | GetConnectedGroupLine(connLine as Model.Line, group, false); |
||
778 | } |
||
779 | } |
||
780 | 53344e2c | gaqhf | } |
781 | } |
||
782 | private void GetGroupLinePoints(List<Model.Line> groupLine, List<string> points) |
||
783 | { |
||
784 | for (int i = 0; i < groupLine.Count; i++) |
||
785 | { |
||
786 | Model.Line line = groupLine[i]; |
||
787 | 016701e5 | gaqhf | if (i == 0) |
788 | f7e09e14 | gaqhf | { |
789 | object connObj = line.CONNECTORS[0].ConnectedObject; |
||
790 | ff4941b2 | gaqhf | if (connObj != null) |
791 | f7e09e14 | gaqhf | { |
792 | ff4941b2 | gaqhf | string point = GetPointByConnectedItem(connObj, line, true); |
793 | if (string.IsNullOrEmpty(point)) |
||
794 | f7e09e14 | gaqhf | points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y); |
795 | ff4941b2 | gaqhf | else |
796 | points.Add(point); |
||
797 | f7e09e14 | gaqhf | } |
798 | else |
||
799 | points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y); |
||
800 | } |
||
801 | 016701e5 | gaqhf | else |
802 | { |
||
803 | Model.Line prevLine = groupLine[i - 1]; |
||
804 | if (line.SlopeType == SlopeType.HORIZONTAL && |
||
805 | prevLine.SlopeType == SlopeType.VERTICAL) |
||
806 | points.Add(prevLine.Aveva.End_X + "," + line.Aveva.Start_Y); |
||
807 | else if (line.SlopeType == SlopeType.VERTICAL && |
||
808 | prevLine.SlopeType == SlopeType.HORIZONTAL) |
||
809 | points.Add(line.Aveva.Start_X + "," + prevLine.Aveva.End_Y); |
||
810 | else |
||
811 | points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y); |
||
812 | } |
||
813 | |||
814 | 53344e2c | gaqhf | if (i == groupLine.Count - 1) |
815 | f7e09e14 | gaqhf | { |
816 | object connObj = line.CONNECTORS[1].ConnectedObject; |
||
817 | if (connObj != null && connObj.GetType() == typeof(Symbol)) |
||
818 | { |
||
819 | ff4941b2 | gaqhf | string point = GetPointByConnectedItem(connObj, line, false); |
820 | if (string.IsNullOrEmpty(point)) |
||
821 | f7e09e14 | gaqhf | points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y); |
822 | ff4941b2 | gaqhf | else |
823 | points.Add(point); |
||
824 | f7e09e14 | gaqhf | } |
825 | else |
||
826 | points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y); |
||
827 | } |
||
828 | 53344e2c | gaqhf | } |
829 | } |
||
830 | ff4941b2 | gaqhf | private string GetPointByConnectedItem(object connObj, Model.Line line, bool isStart) |
831 | { |
||
832 | string result = string.Empty; |
||
833 | double x; |
||
834 | double y; |
||
835 | if (isStart) |
||
836 | { |
||
837 | x = line.Aveva.Start_X; |
||
838 | y = line.Aveva.Start_Y; |
||
839 | } |
||
840 | else |
||
841 | { |
||
842 | x = line.Aveva.End_X; |
||
843 | y = line.Aveva.End_Y; |
||
844 | } |
||
845 | |||
846 | if (connObj.GetType() == typeof(Symbol)) |
||
847 | { |
||
848 | Symbol connSymbol = connObj as Symbol; |
||
849 | Connector connector = connSymbol.CONNECTORS.Find(loop => loop.ConnectedObject == line); |
||
850 | |||
851 | SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y); |
||
852 | if (slopeType == SlopeType.HORIZONTAL) |
||
853 | result = connSymbol.Aveva.X + "," + y; |
||
854 | else if (slopeType == SlopeType.VERTICAL) |
||
855 | result = x + "," + connSymbol.Aveva.Y; |
||
856 | else |
||
857 | result = x + "," + y; |
||
858 | } |
||
859 | else if (connObj.GetType() == typeof(OPC)) |
||
860 | { |
||
861 | OPC connOPC = connObj as OPC; |
||
862 | Connector connector = connOPC.CONNECTORS.Find(loop => loop.ConnectedObject == line); |
||
863 | |||
864 | double locX = 0, locY = 0, sizeWidth = 0, sizeHeight = 0, aX = 0, aY = 0; |
||
865 | APIDUtils.ConvertPointBystring(connOPC.LOCATION, ref locX, ref locY); |
||
866 | APIDUtils.ConvertPointBystring(connOPC.SIZE, ref sizeWidth, ref sizeHeight); |
||
867 | locX = locX + sizeWidth / 2; |
||
868 | locY = locY + sizeHeight / 2; |
||
869 | aX = locX; |
||
870 | aY = locY; |
||
871 | document.ConvertAvevaPoint(ref aX, ref aY); |
||
872 | |||
873 | SlopeType slopeType = APIDUtils.CalcSlope(locX, locY, connector.X, connector.Y); |
||
874 | if (slopeType == SlopeType.HORIZONTAL) |
||
875 | result = aX + "," + y; |
||
876 | else if (slopeType == SlopeType.VERTICAL) |
||
877 | result = x + "," + aY; |
||
878 | else |
||
879 | result = x + "," + y; |
||
880 | } |
||
881 | |||
882 | return result; |
||
883 | } |
||
884 | 016701e5 | gaqhf | private bool IsExistEndBreak(object item1, object item2) |
885 | { |
||
886 | bool result = false; |
||
887 | if (item1 != null && item2 != null) |
||
888 | { |
||
889 | EndBreak endBreak = document.EndBreaks.Find(x => |
||
890 | (APIDUtils.FindObjectByUID(document, x.OWNER) == item1 && |
||
891 | APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item2) || |
||
892 | (APIDUtils.FindObjectByUID(document, x.OWNER) == item2 && |
||
893 | APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item1)); |
||
894 | |||
895 | if (endBreak != null) |
||
896 | result = true; |
||
897 | } |
||
898 | |||
899 | return result; |
||
900 | } |
||
901 | private LineRun FindLineRun(Model.Line line) |
||
902 | { |
||
903 | List<LineRun> allLineRun = new List<LineRun>(); |
||
904 | foreach (var item in document.LINENUMBERS) |
||
905 | allLineRun.AddRange(item.RUNS); |
||
906 | foreach (var item in document.TRIMLINES) |
||
907 | allLineRun.AddRange(item.RUNS); |
||
908 | |||
909 | return allLineRun.Find(x => x.RUNITEMS.Contains(line)); |
||
910 | } |
||
911 | private Model.Line FindOtherLineByRun(Model.Line line, Symbol symbol) |
||
912 | { |
||
913 | Model.Line result = null; |
||
914 | LineRun run = FindLineRun(line); |
||
915 | Connector connector = symbol.CONNECTORS.Find(x => |
||
916 | x.ConnectedObject != null && |
||
917 | x.ConnectedObject != line && |
||
918 | run.RUNITEMS.Contains(x.ConnectedObject) && |
||
919 | x.ConnectedObject.GetType() == typeof(Model.Line)); |
||
920 | |||
921 | if (connector != null) |
||
922 | result = connector.ConnectedObject as Model.Line; |
||
923 | 2d09df82 | gaqhf | |
924 | 016701e5 | gaqhf | return result; |
925 | } |
||
926 | 495bb8f5 | gaqhf | private bool CheckAngle(DataRow symbolRow) |
927 | { |
||
928 | return int.Parse(symbolRow["Insert_Points"].ToString()).Equals(2); |
||
929 | } |
||
930 | private bool CheckBalloon(Symbol symbol) |
||
931 | { |
||
932 | bool result = false; |
||
933 | |||
934 | string text = string.Empty; |
||
935 | Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name); |
||
936 | if (symbolDefinitions.Count != 0) |
||
937 | { |
||
938 | text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper(); |
||
939 | |||
940 | if (text.Equals("VLP")) |
||
941 | text = "VPO"; |
||
942 | else if (text.Equals("IVP")) |
||
943 | text = "IPO"; |
||
944 | |||
945 | if (SymbolCategory.astrLabelBalloonBlockNames.Contains(text)) |
||
946 | result = true;//dumbDwgUpgrade.addLabelBalloon(symbolForInsertion, objectId); |
||
947 | } |
||
948 | |||
949 | return result; |
||
950 | } |
||
951 | 53344e2c | gaqhf | #endregion |
952 | 9dab7146 | gaqhf | |
953 | 74a0c9d6 | gaqhf | #region Test Source |
954 | public void test() |
||
955 | { |
||
956 | 495bb8f5 | gaqhf | |
957 | 74a0c9d6 | gaqhf | } |
958 | c8b025e0 | gaqhf | public static void TESTStatic(long handle) |
959 | 74a0c9d6 | gaqhf | { |
960 | c94252bf | gaqhf | AutoModeling auto = new AutoModeling(null); |
961 | auto.SetAttributeByAvevaForm(handle, new List<Tuple<string, string>>() { new Tuple<string, string>("Size", "100") }); |
||
962 | 74a0c9d6 | gaqhf | } |
963 | #endregion |
||
964 | } |
||
965 | 73152510 | gaqhf | |
966 | |||
967 | public static class AcDbLinqExtensionMethods |
||
968 | { |
||
969 | /// <summary> |
||
970 | /// Get all references to the given BlockTableRecord, including |
||
971 | /// references to anonymous dynamic BlockTableRecords. |
||
972 | /// </summary> |
||
973 | |||
974 | public static IEnumerable<BlockReference> GetBlockReferences( |
||
975 | this BlockTableRecord btr, |
||
976 | OpenMode mode = OpenMode.ForRead, |
||
977 | bool directOnly = true) |
||
978 | { |
||
979 | if (btr == null) |
||
980 | throw new ArgumentNullException("btr"); |
||
981 | var tr = btr.Database.TransactionManager.TopTransaction; |
||
982 | if (tr == null) |
||
983 | throw new InvalidOperationException("No transaction"); |
||
984 | var ids = btr.GetBlockReferenceIds(directOnly, true); |
||
985 | int cnt = ids.Count; |
||
986 | for (int i = 0; i < cnt; i++) |
||
987 | { |
||
988 | yield return (BlockReference) |
||
989 | tr.GetObject(ids[i], mode, false, false); |
||
990 | } |
||
991 | if (btr.IsDynamicBlock) |
||
992 | { |
||
993 | BlockTableRecord btr2 = null; |
||
994 | var blockIds = btr.GetAnonymousBlockIds(); |
||
995 | cnt = blockIds.Count; |
||
996 | for (int i = 0; i < cnt; i++) |
||
997 | { |
||
998 | btr2 = (BlockTableRecord)tr.GetObject(blockIds[i], |
||
999 | OpenMode.ForRead, false, false); |
||
1000 | ids = btr2.GetBlockReferenceIds(directOnly, true); |
||
1001 | int cnt2 = ids.Count; |
||
1002 | for (int j = 0; j < cnt2; j++) |
||
1003 | { |
||
1004 | yield return (BlockReference) |
||
1005 | tr.GetObject(ids[j], mode, false, false); |
||
1006 | } |
||
1007 | } |
||
1008 | } |
||
1009 | } |
||
1010 | } |
||
1011 | 74a0c9d6 | gaqhf | } |