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