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 |
20dd244c
|
gaqhf
|
Zoom(0, 0, 10, 10);
|
116 |
016701e5
|
gaqhf
|
RunLineModeling();
|
117 |
20dd244c
|
gaqhf
|
|
118 |
|
|
ZoomAll();
|
119 |
a19bd6e2
|
gaqhf
|
RunOPCModeling();
|
120 |
016701e5
|
gaqhf
|
RunSymbolModeling();
|
121 |
475071f2
|
gaqhf
|
RunTextModeling();
|
122 |
6503fec8
|
gaqhf
|
RunNoteModeling();
|
123 |
c6df982b
|
gaqhf
|
|
124 |
|
|
Zoom(0, 0, 10, 10);
|
125 |
dfb760ef
|
gaqhf
|
RunInputLineAttribute();
|
126 |
|
|
RunInputLineNumberAttribute();
|
127 |
|
|
RunInputSymbolAttribute();
|
128 |
c6df982b
|
gaqhf
|
ZoomAll();
|
129 |
016701e5
|
gaqhf
|
}
|
130 |
|
|
catch (System.Exception ex)
|
131 |
|
|
{
|
132 |
|
|
System.Windows.Forms.MessageBox.Show(ex.Message + @"\n" + ex.StackTrace);
|
133 |
|
|
}
|
134 |
aba318eb
|
gaqhf
|
finally
|
135 |
|
|
{
|
136 |
932933ed
|
gaqhf
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.ClearParent, null);
|
137 |
aba318eb
|
gaqhf
|
SplashScreenManager.CloseForm(false);
|
138 |
|
|
}
|
139 |
46756c13
|
gaqhf
|
}
|
140 |
|
|
|
141 |
20dd244c
|
gaqhf
|
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 |
9dab7146
|
gaqhf
|
#region Run Method
|
157 |
|
|
private void RunLineModeling()
|
158 |
74a0c9d6
|
gaqhf
|
{
|
159 |
aba318eb
|
gaqhf
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
|
160 |
|
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling");
|
161 |
9dab7146
|
gaqhf
|
foreach (var item in document.LINES)
|
162 |
74a0c9d6
|
gaqhf
|
{
|
163 |
53344e2c
|
gaqhf
|
if (item.Aveva.Handle == 0)
|
164 |
|
|
LineModeling(item);
|
165 |
aba318eb
|
gaqhf
|
|
166 |
|
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
|
167 |
74a0c9d6
|
gaqhf
|
}
|
168 |
9dab7146
|
gaqhf
|
}
|
169 |
a19bd6e2
|
gaqhf
|
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 |
016701e5
|
gaqhf
|
private void RunSymbolModeling()
|
181 |
|
|
{
|
182 |
aba318eb
|
gaqhf
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
|
183 |
|
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
|
184 |
b90890eb
|
gaqhf
|
foreach (var item in document.SYMBOLS)
|
185 |
|
|
{
|
186 |
|
|
if (item.Aveva.Handle == 0)
|
187 |
|
|
SymbolModeling(item);
|
188 |
aba318eb
|
gaqhf
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
|
189 |
b90890eb
|
gaqhf
|
}
|
190 |
016701e5
|
gaqhf
|
}
|
191 |
475071f2
|
gaqhf
|
private void RunTextModeling()
|
192 |
|
|
{
|
193 |
0a8db7fe
|
gaqhf
|
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 |
6503fec8
|
gaqhf
|
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 |
7a8645c9
|
gaqhf
|
foreach (var item in document.Notes)
|
206 |
6503fec8
|
gaqhf
|
{
|
207 |
7a8645c9
|
gaqhf
|
NoteModeling(item);
|
208 |
0a8db7fe
|
gaqhf
|
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
|
209 |
|
|
}
|
210 |
475071f2
|
gaqhf
|
}
|
211 |
5c05308b
|
gaqhf
|
private void RunInputLineAttribute()
|
212 |
|
|
{
|
213 |
dfb760ef
|
gaqhf
|
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 |
5c05308b
|
gaqhf
|
}
|
221 |
|
|
private void RunInputSymbolAttribute()
|
222 |
|
|
{
|
223 |
dfb760ef
|
gaqhf
|
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 |
5c05308b
|
gaqhf
|
}
|
241 |
9dab7146
|
gaqhf
|
#endregion
|
242 |
74a0c9d6
|
gaqhf
|
|
243 |
9dab7146
|
gaqhf
|
#region Modeling Method
|
244 |
|
|
private void LineModeling(Model.Line line)
|
245 |
|
|
{
|
246 |
53344e2c
|
gaqhf
|
List<Model.Line> groupLine = new List<Model.Line>();
|
247 |
9dab7146
|
gaqhf
|
List<string> points = new List<string>();
|
248 |
016701e5
|
gaqhf
|
GetConnectedGroupLine(line, groupLine, false);
|
249 |
20dd244c
|
gaqhf
|
CoordinateCorrection(groupLine);
|
250 |
53344e2c
|
gaqhf
|
GetGroupLinePoints(groupLine, points);
|
251 |
9dab7146
|
gaqhf
|
|
252 |
932933ed
|
gaqhf
|
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 |
c94252bf
|
gaqhf
|
AvevaThread.Run(ThreadType.LineNumberModeling, null);
|
262 |
932933ed
|
gaqhf
|
break;
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
|
|
}
|
266 |
|
|
|
267 |
53344e2c
|
gaqhf
|
long handle = 0;
|
268 |
9dab7146
|
gaqhf
|
if (line.Aveva.Type == Model.Type.Pipe)
|
269 |
932933ed
|
gaqhf
|
handle = DrawPipe(line.Aveva.Name, points, lineNumber);
|
270 |
9dab7146
|
gaqhf
|
else if (line.Aveva.Type == Model.Type.Signal)
|
271 |
53344e2c
|
gaqhf
|
handle = DrawSignal(line.Aveva.Name, points);
|
272 |
|
|
|
273 |
932933ed
|
gaqhf
|
if (lineNumber != null)
|
274 |
c8b025e0
|
gaqhf
|
{
|
275 |
932933ed
|
gaqhf
|
GUIUtils.SetAutoLabelCheck(false);
|
276 |
c94252bf
|
gaqhf
|
AvevaThread.Stop(ThreadType.LineNumberModeling);
|
277 |
c8b025e0
|
gaqhf
|
}
|
278 |
932933ed
|
gaqhf
|
|
279 |
53344e2c
|
gaqhf
|
foreach (var item in groupLine)
|
280 |
|
|
item.Aveva.Handle = handle;
|
281 |
74a0c9d6
|
gaqhf
|
}
|
282 |
b90890eb
|
gaqhf
|
private void SymbolModeling(Symbol symbol)
|
283 |
|
|
{
|
284 |
dfb760ef
|
gaqhf
|
DataRow[] allRows = avevaInfo.AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
|
285 |
495bb8f5
|
gaqhf
|
if (allRows.Length == 1)
|
286 |
2d09df82
|
gaqhf
|
{
|
287 |
495bb8f5
|
gaqhf
|
DataRow symbolRow = allRows[0];
|
288 |
|
|
bool bAngle = CheckAngle(symbolRow);
|
289 |
|
|
bool bBalloon = CheckBalloon(symbol);
|
290 |
|
|
|
291 |
20dd244c
|
gaqhf
|
long handle = DrawSymbol(symbol, symbolRow, bAngle, bBalloon);
|
292 |
495bb8f5
|
gaqhf
|
if (handle != 0)
|
293 |
2d09df82
|
gaqhf
|
{
|
294 |
495bb8f5
|
gaqhf
|
symbol.Aveva.Handle = handle;
|
295 |
|
|
|
296 |
|
|
if (!bAngle)
|
297 |
|
|
{
|
298 |
d03dde83
|
gaqhf
|
ObjectId objectId = APIDUtils.GetObjectIdByHandle(handle);
|
299 |
495bb8f5
|
gaqhf
|
if (objectId != ObjectId.Null)
|
300 |
|
|
SetBlockReferenceRotation(objectId, symbol.ANGLE);
|
301 |
|
|
}
|
302 |
2d09df82
|
gaqhf
|
}
|
303 |
|
|
}
|
304 |
b90890eb
|
gaqhf
|
}
|
305 |
6503fec8
|
gaqhf
|
private void TextModeling(Text text)
|
306 |
|
|
{
|
307 |
20dd244c
|
gaqhf
|
if (text.TextAngle == TextAngle.None || text.ASSOCIATION)
|
308 |
6503fec8
|
gaqhf
|
return;
|
309 |
|
|
|
310 |
|
|
if (text.Aveva.LabelType == LabelType.SingleText)
|
311 |
a03f7b94
|
gaqhf
|
DrawText(text.Aveva.X, text.Aveva.Y, text.Aveva.Height, text.VALUE, text.Aveva.Angle);
|
312 |
6503fec8
|
gaqhf
|
else if (text.Aveva.LabelType == LabelType.MultiText)
|
313 |
7a8645c9
|
gaqhf
|
{
|
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 |
a03f7b94
|
gaqhf
|
DrawText(x, y, text.Aveva.Height, values[i], text.Aveva.Angle);
|
331 |
7a8645c9
|
gaqhf
|
}
|
332 |
|
|
}
|
333 |
|
|
|
334 |
6503fec8
|
gaqhf
|
|
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 |
a03f7b94
|
gaqhf
|
DrawText(note.Aveva.X, note.Aveva.Y, note.Aveva.Height, note.VALUE, note.Aveva.Angle);
|
343 |
6503fec8
|
gaqhf
|
else if (note.Aveva.LabelType == LabelType.MultiNote)
|
344 |
7a8645c9
|
gaqhf
|
{
|
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 |
6503fec8
|
gaqhf
|
|
361 |
a03f7b94
|
gaqhf
|
DrawText(x, y, note.Aveva.Height, values[i], note.Aveva.Angle);
|
362 |
7a8645c9
|
gaqhf
|
}
|
363 |
|
|
}
|
364 |
6503fec8
|
gaqhf
|
}
|
365 |
5c05308b
|
gaqhf
|
private void SetLineAttribute(Model.Line line)
|
366 |
|
|
{
|
367 |
|
|
|
368 |
|
|
}
|
369 |
dfb760ef
|
gaqhf
|
private void SetLineNumberAttribute(Model.LineNumber lineNumber)
|
370 |
|
|
{
|
371 |
c8b025e0
|
gaqhf
|
Model.Line line = APIDUtils.FindObjectByUID(document, lineNumber.CONNLINE) as Model.Line;
|
372 |
c94252bf
|
gaqhf
|
if (line != null && line.Aveva.Handle != 0)
|
373 |
c8b025e0
|
gaqhf
|
{
|
374 |
c94252bf
|
gaqhf
|
List<Tuple<string, string>> datas = new List<Tuple<string, string>>();
|
375 |
c8b025e0
|
gaqhf
|
foreach (Model.Attribute attribute in lineNumber.ATTRIBUTES)
|
376 |
|
|
{
|
377 |
|
|
AttributeInfo info = avevaInfo.AttributeInfo.Find(x => x.UID == attribute.UID);
|
378 |
c94252bf
|
gaqhf
|
if (info != null && !string.IsNullOrEmpty(info.APID_ATTRIBUTE))
|
379 |
faba1fc7
|
gaqhf
|
datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE));
|
380 |
c94252bf
|
gaqhf
|
}
|
381 |
|
|
if (datas.Count > 0)
|
382 |
|
|
{
|
383 |
c6df982b
|
gaqhf
|
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 |
c94252bf
|
gaqhf
|
ObjectId objectId = GetFirstPolyLineObjectId(line.Aveva.Handle);
|
385 |
|
|
if (!objectId.IsNull)
|
386 |
c6df982b
|
gaqhf
|
SetAttributeByAvevaForm(objectId.Handle.Value, datas, x, y);
|
387 |
c8b025e0
|
gaqhf
|
}
|
388 |
|
|
}
|
389 |
dfb760ef
|
gaqhf
|
}
|
390 |
5c05308b
|
gaqhf
|
private void SetSymbolAttribute(Model.Symbol symbol)
|
391 |
|
|
{
|
392 |
c8b025e0
|
gaqhf
|
if (symbol.Aveva.Handle != 0)
|
393 |
4328cb06
|
gaqhf
|
{
|
394 |
c94252bf
|
gaqhf
|
List<Tuple<string, string>> datas = new List<Tuple<string, string>>();
|
395 |
c8b025e0
|
gaqhf
|
foreach (var attribute in symbol.ATTRIBUTES)
|
396 |
4328cb06
|
gaqhf
|
{
|
397 |
c8b025e0
|
gaqhf
|
AttributeInfo info = avevaInfo.AttributeInfo.Find(x => x.UID == attribute.UID);
|
398 |
c94252bf
|
gaqhf
|
if (info != null && !string.IsNullOrEmpty(info.APID_ATTRIBUTE))
|
399 |
faba1fc7
|
gaqhf
|
datas.Add(new Tuple<string, string>(info.APID_ATTRIBUTE, attribute.VALUE));
|
400 |
c94252bf
|
gaqhf
|
}
|
401 |
|
|
if (datas.Count > 0)
|
402 |
|
|
{
|
403 |
c6df982b
|
gaqhf
|
double x = symbol.Aveva.X, y = symbol.Aveva.Y;
|
404 |
d03dde83
|
gaqhf
|
ObjectId objectId = APIDUtils.GetObjectIdByHandle(symbol.Aveva.Handle);
|
405 |
c94252bf
|
gaqhf
|
if (!objectId.IsNull)
|
406 |
c6df982b
|
gaqhf
|
SetAttributeByAvevaForm(objectId.Handle.Value, datas, x, y);
|
407 |
4328cb06
|
gaqhf
|
}
|
408 |
|
|
}
|
409 |
5c05308b
|
gaqhf
|
}
|
410 |
c6df982b
|
gaqhf
|
private void ConvertBranchPipe(Model.Line branchLine, Model.Line mainLine)
|
411 |
|
|
{
|
412 |
|
|
|
413 |
|
|
}
|
414 |
9dab7146
|
gaqhf
|
#endregion
|
415 |
74a0c9d6
|
gaqhf
|
|
416 |
|
|
#region Drawing Method
|
417 |
932933ed
|
gaqhf
|
private long DrawPipe(string style, List<string> coordinates, LineNumber lineNumber = null)
|
418 |
74a0c9d6
|
gaqhf
|
{
|
419 |
9dab7146
|
gaqhf
|
List<long> prevHandles = GetAllGroupHandles();
|
420 |
74a0c9d6
|
gaqhf
|
|
421 |
9dab7146
|
gaqhf
|
GUIUtils.SetPipeStyle(style);
|
422 |
14540282
|
gaqhf
|
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
|
423 |
74a0c9d6
|
gaqhf
|
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 |
932933ed
|
gaqhf
|
|
431 |
|
|
//enter Parent(null)
|
432 |
74a0c9d6
|
gaqhf
|
commandParam.Add(null);
|
433 |
|
|
|
434 |
932933ed
|
gaqhf
|
if (lineNumber != null)
|
435 |
|
|
{
|
436 |
|
|
Point3d point = new Point3d(lineNumber.Aveva.X, lineNumber.Aveva.Y, 0);
|
437 |
|
|
commandParam.Add(point);
|
438 |
475071f2
|
gaqhf
|
commandParam.Add(lineNumber.Aveva.Angle);
|
439 |
932933ed
|
gaqhf
|
|
440 |
|
|
commandParam.Add(null);
|
441 |
|
|
}
|
442 |
|
|
else
|
443 |
|
|
commandParam.Add(null);
|
444 |
|
|
|
445 |
74a0c9d6
|
gaqhf
|
editor.Command(commandParam.ToArray());
|
446 |
|
|
|
447 |
9dab7146
|
gaqhf
|
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 |
74a0c9d6
|
gaqhf
|
|
453 |
9dab7146
|
gaqhf
|
if (otherHandles.Count == 1)
|
454 |
|
|
return otherHandles[0];
|
455 |
|
|
else
|
456 |
|
|
return 0;
|
457 |
74a0c9d6
|
gaqhf
|
}
|
458 |
9dab7146
|
gaqhf
|
private long DrawPipe(string style, List<string> coordinates, ObjectId objectId)
|
459 |
74a0c9d6
|
gaqhf
|
{
|
460 |
9dab7146
|
gaqhf
|
List<long> prevHandles = GetAllGroupHandles();
|
461 |
14540282
|
gaqhf
|
GUIUtils.SetPipeStyle(style);
|
462 |
74a0c9d6
|
gaqhf
|
|
463 |
14540282
|
gaqhf
|
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
|
464 |
74a0c9d6
|
gaqhf
|
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 |
9dab7146
|
gaqhf
|
|
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 |
74a0c9d6
|
gaqhf
|
}
|
522 |
20dd244c
|
gaqhf
|
private long DrawSymbol(Symbol symbol, DataRow symbolRow, bool needAngle, bool needBalloon)
|
523 |
6b3cb476
|
gaqhf
|
{
|
524 |
73152510
|
gaqhf
|
long handle = 0;
|
525 |
6b3cb476
|
gaqhf
|
try
|
526 |
|
|
{
|
527 |
495bb8f5
|
gaqhf
|
string insertSymbolName = symbol.Aveva.Name;
|
528 |
|
|
double x = symbol.Aveva.X;
|
529 |
|
|
double y = symbol.Aveva.Y;
|
530 |
|
|
|
531 |
c6df982b
|
gaqhf
|
if (symbol.GetType() != typeof(OPC))
|
532 |
|
|
Zoom(x - 50, y - 50, x + 50, y + 50);
|
533 |
|
|
|
534 |
73152510
|
gaqhf
|
List<long> prevHandles = GetAllBlockHandlesByName(insertSymbolName);
|
535 |
|
|
|
536 |
6b3cb476
|
gaqhf
|
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 |
495bb8f5
|
gaqhf
|
|
543 |
|
|
// Insert Point
|
544 |
6b3cb476
|
gaqhf
|
Point3d point = new Point3d(x, y, 0);
|
545 |
|
|
commandParam.Add(point);
|
546 |
495bb8f5
|
gaqhf
|
|
547 |
|
|
// Check Insert Point
|
548 |
|
|
if (needAngle)
|
549 |
20dd244c
|
gaqhf
|
{
|
550 |
|
|
double degree = RadianToDegree(symbol.ANGLE);
|
551 |
|
|
commandParam.Add(degree);
|
552 |
|
|
}
|
553 |
|
|
|
554 |
495bb8f5
|
gaqhf
|
|
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 |
6b3cb476
|
gaqhf
|
|
569 |
|
|
editor.Command(commandParam.ToArray());
|
570 |
73152510
|
gaqhf
|
|
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 |
6b3cb476
|
gaqhf
|
}
|
582 |
|
|
catch (System.Exception ex)
|
583 |
|
|
{
|
584 |
74a0c9d6
|
gaqhf
|
|
585 |
6b3cb476
|
gaqhf
|
}
|
586 |
73152510
|
gaqhf
|
|
587 |
|
|
return handle;
|
588 |
6b3cb476
|
gaqhf
|
}
|
589 |
a03f7b94
|
gaqhf
|
private void DrawText(double x, double y, double height, string text, double rotation)
|
590 |
6503fec8
|
gaqhf
|
{
|
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 |
a03f7b94
|
gaqhf
|
acText.Rotation = rotation;
|
615 |
6503fec8
|
gaqhf
|
|
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 |
74a0c9d6
|
gaqhf
|
#endregion
|
625 |
|
|
|
626 |
73152510
|
gaqhf
|
#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 |
9dab7146
|
gaqhf
|
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 |
c94252bf
|
gaqhf
|
private ObjectId GetFirstPolyLineObjectId(long groupHandle)
|
670 |
9dab7146
|
gaqhf
|
{
|
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 |
2d09df82
|
gaqhf
|
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 |
c8b025e0
|
gaqhf
|
#endregion
|
720 |
|
|
|
721 |
|
|
#region For Aveva
|
722 |
c6df982b
|
gaqhf
|
double labelX, labelY;
|
723 |
|
|
private void SetAttributeByAvevaForm(long handle, List<Tuple<string, string>> datas, double x, double y)
|
724 |
c8b025e0
|
gaqhf
|
{
|
725 |
c6df982b
|
gaqhf
|
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 |
c8b025e0
|
gaqhf
|
|
739 |
c6df982b
|
gaqhf
|
}
|
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 |
c8b025e0
|
gaqhf
|
}
|
769 |
016701e5
|
gaqhf
|
#endregion
|
770 |
|
|
|
771 |
73152510
|
gaqhf
|
#region Modeling Utils
|
772 |
016701e5
|
gaqhf
|
private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert)
|
773 |
53344e2c
|
gaqhf
|
{
|
774 |
|
|
if (!group.Contains(line))
|
775 |
|
|
{
|
776 |
016701e5
|
gaqhf
|
if (isInsert)
|
777 |
53344e2c
|
gaqhf
|
group.Insert(0, line);
|
778 |
|
|
else
|
779 |
|
|
group.Add(line);
|
780 |
|
|
|
781 |
016701e5
|
gaqhf
|
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 |
53344e2c
|
gaqhf
|
}
|
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 |
016701e5
|
gaqhf
|
if (i == 0)
|
815 |
f7e09e14
|
gaqhf
|
{
|
816 |
|
|
object connObj = line.CONNECTORS[0].ConnectedObject;
|
817 |
ff4941b2
|
gaqhf
|
if (connObj != null)
|
818 |
f7e09e14
|
gaqhf
|
{
|
819 |
ff4941b2
|
gaqhf
|
string point = GetPointByConnectedItem(connObj, line, true);
|
820 |
|
|
if (string.IsNullOrEmpty(point))
|
821 |
f7e09e14
|
gaqhf
|
points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
|
822 |
ff4941b2
|
gaqhf
|
else
|
823 |
|
|
points.Add(point);
|
824 |
f7e09e14
|
gaqhf
|
}
|
825 |
|
|
else
|
826 |
|
|
points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
|
827 |
|
|
}
|
828 |
016701e5
|
gaqhf
|
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 |
c6df982b
|
gaqhf
|
else if (line.SlopeType == SlopeType.Slope ||
|
838 |
|
|
prevLine.SlopeType == SlopeType.Slope)
|
839 |
016701e5
|
gaqhf
|
points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
|
840 |
|
|
}
|
841 |
|
|
|
842 |
53344e2c
|
gaqhf
|
if (i == groupLine.Count - 1)
|
843 |
f7e09e14
|
gaqhf
|
{
|
844 |
|
|
object connObj = line.CONNECTORS[1].ConnectedObject;
|
845 |
20dd244c
|
gaqhf
|
if (connObj != null)
|
846 |
f7e09e14
|
gaqhf
|
{
|
847 |
ff4941b2
|
gaqhf
|
string point = GetPointByConnectedItem(connObj, line, false);
|
848 |
|
|
if (string.IsNullOrEmpty(point))
|
849 |
f7e09e14
|
gaqhf
|
points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
|
850 |
ff4941b2
|
gaqhf
|
else
|
851 |
|
|
points.Add(point);
|
852 |
f7e09e14
|
gaqhf
|
}
|
853 |
|
|
else
|
854 |
|
|
points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
|
855 |
|
|
}
|
856 |
53344e2c
|
gaqhf
|
}
|
857 |
|
|
}
|
858 |
20dd244c
|
gaqhf
|
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 |
ff4941b2
|
gaqhf
|
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 |
016701e5
|
gaqhf
|
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 |
ad983925
|
gaqhf
|
|
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 |
2d09df82
|
gaqhf
|
|
1061 |
016701e5
|
gaqhf
|
return result;
|
1062 |
|
|
}
|
1063 |
495bb8f5
|
gaqhf
|
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 |
20dd244c
|
gaqhf
|
private double RadianToDegree(double angle)
|
1089 |
|
|
{
|
1090 |
|
|
return angle * (180.0 / Math.PI);
|
1091 |
|
|
}
|
1092 |
53344e2c
|
gaqhf
|
#endregion
|
1093 |
9dab7146
|
gaqhf
|
|
1094 |
74a0c9d6
|
gaqhf
|
#region Test Source
|
1095 |
|
|
public void test()
|
1096 |
|
|
{
|
1097 |
495bb8f5
|
gaqhf
|
|
1098 |
74a0c9d6
|
gaqhf
|
}
|
1099 |
c8b025e0
|
gaqhf
|
public static void TESTStatic(long handle)
|
1100 |
74a0c9d6
|
gaqhf
|
{
|
1101 |
d03dde83
|
gaqhf
|
|
1102 |
74a0c9d6
|
gaqhf
|
}
|
1103 |
|
|
#endregion
|
1104 |
|
|
}
|
1105 |
73152510
|
gaqhf
|
|
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 |
74a0c9d6
|
gaqhf
|
} |