hytos / DTI_PID / APIDConverter / AutoModeling.cs @ 932933ed
이력 | 보기 | 이력해설 | 다운로드 (31.4 KB)
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 |
|
10 |
using Autodesk.AutoCAD.ApplicationServices; |
11 |
using Autodesk.AutoCAD.ApplicationServices.Core; |
12 |
using Autodesk.AutoCAD.DatabaseServices; |
13 |
using Autodesk.AutoCAD.EditorInput; |
14 |
using Autodesk.AutoCAD.Geometry; |
15 |
using Autodesk.AutoCAD.Interop; |
16 |
using Autodesk.AutoCAD.Interop.Common; |
17 |
using Autodesk.AutoCAD.Runtime; |
18 |
using Autodesk.AutoCAD.Windows; |
19 |
|
20 |
using AVEVA.PID.Components; |
21 |
using AVEVA.PID.GUI; |
22 |
using AVEVA.PID.Common; |
23 |
using AVEVA.PID.DWGSelector; |
24 |
using AVEVA.PID.Utilities; |
25 |
|
26 |
using AVEVA.PID.CustomizationUtility.DB; |
27 |
using AVEVA.PID.CustomizationUtility.Model; |
28 |
using AVEVA.PID.CustomizationUtility.Properties; |
29 |
|
30 |
using DevExpress.XtraSplashScreen; |
31 |
|
32 |
namespace AVEVA.PID.CustomizationUtility |
33 |
{ |
34 |
public class AutoModeling |
35 |
{ |
36 |
public static AutoModeling Running { get; set; } |
37 |
Model.Document document; |
38 |
|
39 |
System.Data.DataTable AvevaSymbolTable = null; |
40 |
|
41 |
private void SetConvertRule() |
42 |
{ |
43 |
#region OPC Setting |
44 |
document.OPCs.Sort(SortOPC); |
45 |
int SortOPC(OPC a, OPC b) |
46 |
{ |
47 |
if (a.FlowType == FlowType.In) |
48 |
return 1; |
49 |
else |
50 |
return 0; |
51 |
} |
52 |
#endregion |
53 |
} |
54 |
|
55 |
public AutoModeling(Model.Document document, System.Data.DataTable AvevaSymbolTable) |
56 |
{ |
57 |
this.document = document; |
58 |
this.AvevaSymbolTable = AvevaSymbolTable; |
59 |
} |
60 |
|
61 |
public void CreateDrawing() |
62 |
{ |
63 |
string outPath = Project_DB.GetDirectiveValue("DRGPTH"); |
64 |
string tempPath = Path.GetTempPath(); |
65 |
string selectedFullPath = Path.Combine(tempPath, document.AvevaTemplateName + ".DWT"); |
66 |
|
67 |
DWTSelector.strDrawingNumber = document.AvevaDrawingNumber; |
68 |
DWTSelector.strSheetNumber = document.AvevaSheetNumber; |
69 |
DWTSelector.strCadFileName = document.AvevaDrawingNumber + document.AvevaSheetNumber; |
70 |
DWTSelector.strCadFilePath = outPath; |
71 |
|
72 |
try |
73 |
{ |
74 |
string text = ReadWriteDrawingData.ReadTemplateData(document.AvevaTemplateName, document.AvevaTemplateID, selectedFullPath, false); |
75 |
Autodesk.AutoCAD.Interop.AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication; |
76 |
Autodesk.AutoCAD.Interop.AcadDocument acadDocument = acadApplication.Documents.Add(text); |
77 |
|
78 |
Commands.addLatestPidvesrionToDictionary(); |
79 |
AVVPropCmd.ActivateAcad(); |
80 |
|
81 |
if (acadDocument != null) |
82 |
{ |
83 |
Running = this; |
84 |
acadApplication.ActiveDocument = acadDocument; |
85 |
acadDocument.SendCommand("QSAVE "); |
86 |
acadDocument.SendCommand("APPIDRun "); |
87 |
acadDocument.SendCommand("QSAVE "); |
88 |
Running = null; |
89 |
} |
90 |
} |
91 |
catch (System.Exception ex) |
92 |
{ |
93 |
|
94 |
} |
95 |
|
96 |
GC.Collect(); |
97 |
} |
98 |
public void Run() |
99 |
{ |
100 |
try |
101 |
{ |
102 |
SplashScreenManager.ShowForm(typeof(APIDSplashScreen), true, true); |
103 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllStepCount, 3); |
104 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetDocumentName, document.AvevaDrawingNumber + document.AvevaSheetNumber); |
105 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetParent, Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle); |
106 |
|
107 |
SetConvertRule(); |
108 |
|
109 |
RunLineModeling(); |
110 |
RunOPCModeling(); |
111 |
RunSymbolModeling(); |
112 |
|
113 |
|
114 |
} |
115 |
catch (System.Exception ex) |
116 |
{ |
117 |
System.Windows.Forms.MessageBox.Show(ex.Message + @"\n" + ex.StackTrace); |
118 |
} |
119 |
finally |
120 |
{ |
121 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.ClearParent, null); |
122 |
SplashScreenManager.CloseForm(false); |
123 |
} |
124 |
} |
125 |
|
126 |
#region Run Method |
127 |
private void RunLineModeling() |
128 |
{ |
129 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count); |
130 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling"); |
131 |
foreach (var item in document.LINES) |
132 |
{ |
133 |
if (item.Aveva.Handle == 0) |
134 |
LineModeling(item); |
135 |
|
136 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
137 |
} |
138 |
} |
139 |
private void RunOPCModeling() |
140 |
{ |
141 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.OPCs.Count); |
142 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "OPC Modeling"); |
143 |
foreach (var item in document.OPCs) |
144 |
{ |
145 |
if (item.Aveva.Handle == 0) |
146 |
SymbolModeling(item); |
147 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
148 |
} |
149 |
} |
150 |
private void RunSymbolModeling() |
151 |
{ |
152 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
153 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling"); |
154 |
foreach (var item in document.SYMBOLS) |
155 |
{ |
156 |
if (item.Aveva.Handle == 0) |
157 |
SymbolModeling(item); |
158 |
SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null); |
159 |
} |
160 |
} |
161 |
#endregion |
162 |
|
163 |
#region Modeling Method |
164 |
private void LineModeling(Model.Line line) |
165 |
{ |
166 |
List<Model.Line> groupLine = new List<Model.Line>(); |
167 |
List<string> points = new List<string>(); |
168 |
GetConnectedGroupLine(line, groupLine, false); |
169 |
GetGroupLinePoints(groupLine, points); |
170 |
|
171 |
LineNumber lineNumber = null; |
172 |
if (line.Aveva.Type == Model.Type.Pipe) |
173 |
{ |
174 |
foreach (var item in groupLine) |
175 |
{ |
176 |
lineNumber = document.LINENUMBERS.Find(x => x.CONNLINE == item.UID); |
177 |
if (lineNumber != null) |
178 |
{ |
179 |
GUIUtils.SetAutoLabelCheck(true); |
180 |
break; |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
|
186 |
long handle = 0; |
187 |
if (line.Aveva.Type == Model.Type.Pipe) |
188 |
handle = DrawPipe(line.Aveva.Name, points, lineNumber); |
189 |
else if (line.Aveva.Type == Model.Type.Signal) |
190 |
handle = DrawSignal(line.Aveva.Name, points); |
191 |
|
192 |
if (lineNumber != null) |
193 |
GUIUtils.SetAutoLabelCheck(false); |
194 |
|
195 |
foreach (var item in groupLine) |
196 |
item.Aveva.Handle = handle; |
197 |
} |
198 |
private void SymbolModeling(Symbol symbol) |
199 |
{ |
200 |
DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name)); |
201 |
if (allRows.Length == 1) |
202 |
{ |
203 |
DataRow symbolRow = allRows[0]; |
204 |
bool bAngle = CheckAngle(symbolRow); |
205 |
bool bBalloon = CheckBalloon(symbol); |
206 |
|
207 |
long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon); |
208 |
if (handle != 0) |
209 |
{ |
210 |
symbol.Aveva.Handle = handle; |
211 |
|
212 |
if (!bAngle) |
213 |
{ |
214 |
ObjectId objectId = GetObjectIdByHandle(handle); |
215 |
if (objectId != ObjectId.Null) |
216 |
{ |
217 |
SetBlockReferenceRotation(objectId, symbol.ANGLE); |
218 |
} |
219 |
} |
220 |
} |
221 |
} |
222 |
} |
223 |
#endregion |
224 |
|
225 |
#region Drawing Method |
226 |
private long DrawPipe(string style, List<string> coordinates, LineNumber lineNumber = null) |
227 |
{ |
228 |
List<long> prevHandles = GetAllGroupHandles(); |
229 |
|
230 |
GUIUtils.SetPipeStyle(style); |
231 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
232 |
Editor editor = acDoc.Editor; |
233 |
List<object> commandParam = new List<object>(); |
234 |
//command name |
235 |
commandParam.Add("DRPIPE"); |
236 |
//coordinate |
237 |
foreach (var item in coordinates) |
238 |
commandParam.Add(item); |
239 |
|
240 |
//enter Parent(null) |
241 |
commandParam.Add(null); |
242 |
|
243 |
if (lineNumber != null) |
244 |
{ |
245 |
Point3d point = new Point3d(lineNumber.Aveva.X, lineNumber.Aveva.Y, 0); |
246 |
commandParam.Add(point); |
247 |
commandParam.Add(lineNumber.ANGLE); |
248 |
|
249 |
commandParam.Add(null); |
250 |
} |
251 |
else |
252 |
commandParam.Add(null); |
253 |
|
254 |
editor.Command(commandParam.ToArray()); |
255 |
|
256 |
List<long> newHandles = GetAllGroupHandles(); |
257 |
List<long> otherHandles = new List<long>(); |
258 |
foreach (var item in newHandles) |
259 |
if (!prevHandles.Contains(item)) |
260 |
otherHandles.Add(item); |
261 |
|
262 |
if (otherHandles.Count == 1) |
263 |
return otherHandles[0]; |
264 |
else |
265 |
return 0; |
266 |
} |
267 |
private long DrawPipe(string style, List<string> coordinates, ObjectId objectId) |
268 |
{ |
269 |
List<long> prevHandles = GetAllGroupHandles(); |
270 |
GUIUtils.SetPipeStyle(style); |
271 |
|
272 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
273 |
Editor editor = acDoc.Editor; |
274 |
List<object> commandParam = new List<object>(); |
275 |
//command name |
276 |
commandParam.Add("DRPIPE"); |
277 |
//coordinate |
278 |
foreach (var item in coordinates) |
279 |
commandParam.Add(item); |
280 |
//enter |
281 |
commandParam.Add(null); |
282 |
|
283 |
//Input Object ID |
284 |
commandParam.Add(objectId); |
285 |
|
286 |
//enter |
287 |
commandParam.Add(null); |
288 |
|
289 |
editor.Command(commandParam.ToArray()); |
290 |
|
291 |
List<long> newHandles = GetAllGroupHandles(); |
292 |
List<long> otherHandles = new List<long>(); |
293 |
foreach (var item in newHandles) |
294 |
if (!prevHandles.Contains(item)) |
295 |
otherHandles.Add(item); |
296 |
|
297 |
if (otherHandles.Count == 1) |
298 |
return otherHandles[0]; |
299 |
else |
300 |
return 0; |
301 |
} |
302 |
private long DrawSignal(string style, List<string> coordinates) |
303 |
{ |
304 |
List<long> prevHandles = GetAllGroupHandles(); |
305 |
|
306 |
GUIUtils.SetPipeStyle(style); |
307 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
308 |
Editor editor = acDoc.Editor; |
309 |
List<object> commandParam = new List<object>(); |
310 |
//command name |
311 |
commandParam.Add("VPESIGNAL"); |
312 |
//coordinate |
313 |
foreach (var item in coordinates) |
314 |
commandParam.Add(item); |
315 |
//enter |
316 |
commandParam.Add(null); |
317 |
|
318 |
editor.Command(commandParam.ToArray()); |
319 |
|
320 |
List<long> newHandles = GetAllGroupHandles(); |
321 |
List<long> otherHandles = new List<long>(); |
322 |
foreach (var item in newHandles) |
323 |
if (!prevHandles.Contains(item)) |
324 |
otherHandles.Add(item); |
325 |
|
326 |
if (otherHandles.Count == 1) |
327 |
return otherHandles[0]; |
328 |
else |
329 |
return 0; |
330 |
} |
331 |
private long InsertSymbol(Symbol symbol, DataRow symbolRow, bool needAngle, bool needBalloon) |
332 |
{ |
333 |
long handle = 0; |
334 |
try |
335 |
{ |
336 |
string insertSymbolName = symbol.Aveva.Name; |
337 |
double x = symbol.Aveva.X; |
338 |
double y = symbol.Aveva.Y; |
339 |
|
340 |
List<long> prevHandles = GetAllBlockHandlesByName(insertSymbolName); |
341 |
|
342 |
AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData(); |
343 |
drawingData.InsertSymbolName = insertSymbolName; |
344 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
345 |
Editor editor = acDoc.Editor; |
346 |
List<object> commandParam = new List<object>(); |
347 |
commandParam.Add("INSSYM"); |
348 |
|
349 |
// Insert Point |
350 |
Point3d point = new Point3d(x, y, 0); |
351 |
commandParam.Add(point); |
352 |
|
353 |
// Check Insert Point |
354 |
if (needAngle) |
355 |
commandParam.Add(symbol.ANGLE); |
356 |
|
357 |
// Check Balloon |
358 |
if (needBalloon) |
359 |
{ |
360 |
point = new Point3d(x + 20, y + 20, 0); |
361 |
commandParam.Add(point); |
362 |
|
363 |
// Check LeaderLine |
364 |
if (GraphicalUtility.IsLeaderReqOnSymbolBalloons()) |
365 |
commandParam.Add(x + "," + y); |
366 |
} |
367 |
|
368 |
for (int i = 0; i < 8; i++) |
369 |
commandParam.Add(null); |
370 |
|
371 |
editor.Command(commandParam.ToArray()); |
372 |
|
373 |
List<long> newHandles = GetAllBlockHandlesByName(insertSymbolName); |
374 |
List<long> otherHandles = new List<long>(); |
375 |
foreach (var item in newHandles) |
376 |
if (!prevHandles.Contains(item)) |
377 |
otherHandles.Add(item); |
378 |
|
379 |
if (otherHandles.Count == 1) |
380 |
return otherHandles[0]; |
381 |
else |
382 |
return 0; |
383 |
} |
384 |
catch (System.Exception ex) |
385 |
{ |
386 |
|
387 |
} |
388 |
|
389 |
return handle; |
390 |
} |
391 |
#endregion |
392 |
|
393 |
#region Autocad Utils |
394 |
private List<long> GetAllBlockHandlesByName(string name) |
395 |
{ |
396 |
List<long> handles = new List<long>(); |
397 |
|
398 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
399 |
Database acCurDb = acDoc.Database; |
400 |
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
401 |
{ |
402 |
BlockTable gd = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead); |
403 |
foreach (var entry in gd) |
404 |
{ |
405 |
BlockTableRecord blockTableRecord = acTrans.GetObject(entry, OpenMode.ForRead, true) as BlockTableRecord; |
406 |
if (blockTableRecord != null) |
407 |
{ |
408 |
IEnumerable<BlockReference> records = AcDbLinqExtensionMethods.GetBlockReferences(blockTableRecord); |
409 |
foreach (var item in records) |
410 |
{ |
411 |
if (item.Name == name) |
412 |
handles.Add(item.Handle.Value); |
413 |
} |
414 |
} |
415 |
} |
416 |
|
417 |
acTrans.Commit(); |
418 |
} |
419 |
return handles; |
420 |
} |
421 |
private List<long> GetAllGroupHandles() |
422 |
{ |
423 |
List<long> handles = new List<long>(); |
424 |
|
425 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
426 |
Database acCurDb = acDoc.Database; |
427 |
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
428 |
{ |
429 |
DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead); |
430 |
foreach (var entry in gd) |
431 |
handles.Add(entry.Value.Handle.Value); |
432 |
acTrans.Commit(); |
433 |
} |
434 |
return handles; |
435 |
} |
436 |
private ObjectId GetFirstPolyLine(long groupHandle) |
437 |
{ |
438 |
ObjectId result = ObjectId.Null; |
439 |
|
440 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
441 |
Database acCurDb = acDoc.Database; |
442 |
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
443 |
{ |
444 |
DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead); |
445 |
foreach (var entry in gd) |
446 |
{ |
447 |
if (entry.Value.Handle.Value == groupHandle) |
448 |
{ |
449 |
Autodesk.AutoCAD.DatabaseServices.Group group = acTrans.GetObject(entry.Value, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Group; |
450 |
foreach (var item in group.GetAllEntityIds()) |
451 |
{ |
452 |
if (acTrans.GetObject(item, OpenMode.ForRead).GetType() == typeof(Autodesk.AutoCAD.DatabaseServices.Polyline)) |
453 |
{ |
454 |
result = item; |
455 |
break; |
456 |
} |
457 |
} |
458 |
break; |
459 |
} |
460 |
} |
461 |
acTrans.Commit(); |
462 |
} |
463 |
|
464 |
return result; |
465 |
} |
466 |
private ObjectId GetObjectIdByHandle(long lHandle) |
467 |
{ |
468 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
469 |
Database acCurDb = acDoc.Database; |
470 |
Handle handle = new Handle(lHandle); |
471 |
|
472 |
return acCurDb.GetObjectId(false, handle, 0); |
473 |
} |
474 |
private void SetBlockReferenceRotation(ObjectId objectId, double rotation) |
475 |
{ |
476 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
477 |
Database acCurDb = acDoc.Database; |
478 |
Editor acDocEd = acDoc.Editor; |
479 |
|
480 |
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
481 |
{ |
482 |
DBObject objDB = acTrans.GetObject(objectId, OpenMode.ForWrite); |
483 |
if (objDB != null) |
484 |
{ |
485 |
if (objDB.GetType() == typeof(BlockReference)) |
486 |
{ |
487 |
BlockReference block = objDB as BlockReference; |
488 |
block.Rotation = rotation; |
489 |
} |
490 |
} |
491 |
acTrans.Commit(); |
492 |
} |
493 |
} |
494 |
#endregion |
495 |
|
496 |
#region Modeling Utils |
497 |
private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert) |
498 |
{ |
499 |
if (!group.Contains(line)) |
500 |
{ |
501 |
if (isInsert) |
502 |
group.Insert(0, line); |
503 |
else |
504 |
group.Add(line); |
505 |
|
506 |
if (line.CONNECTORS[0].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[0].ConnectedObject)) |
507 |
{ |
508 |
object connObj = line.CONNECTORS[0].ConnectedObject; |
509 |
if (connObj.GetType() == typeof(Model.Line) && |
510 |
APIDUtils.IsConnectedLine(connObj as Model.Line, line)) |
511 |
GetConnectedGroupLine(connObj as Model.Line, group, true); |
512 |
else if (connObj.GetType() == typeof(Model.Symbol)) |
513 |
{ |
514 |
Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol); |
515 |
if (connLine != null) |
516 |
GetConnectedGroupLine(connLine as Model.Line, group, true); |
517 |
} |
518 |
} |
519 |
if (line.CONNECTORS[1].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[1].ConnectedObject)) |
520 |
{ |
521 |
object connObj = line.CONNECTORS[1].ConnectedObject; |
522 |
if (connObj.GetType() == typeof(Model.Line) && |
523 |
APIDUtils.IsConnectedLine(connObj as Model.Line, line)) |
524 |
GetConnectedGroupLine(connObj as Model.Line, group, false); |
525 |
else if (connObj.GetType() == typeof(Model.Symbol)) |
526 |
{ |
527 |
Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol); |
528 |
if (connLine != null) |
529 |
GetConnectedGroupLine(connLine as Model.Line, group, false); |
530 |
} |
531 |
} |
532 |
} |
533 |
} |
534 |
private void GetGroupLinePoints(List<Model.Line> groupLine, List<string> points) |
535 |
{ |
536 |
for (int i = 0; i < groupLine.Count; i++) |
537 |
{ |
538 |
Model.Line line = groupLine[i]; |
539 |
if (i == 0) |
540 |
{ |
541 |
object connObj = line.CONNECTORS[0].ConnectedObject; |
542 |
if (connObj != null) |
543 |
{ |
544 |
string point = GetPointByConnectedItem(connObj, line, true); |
545 |
if (string.IsNullOrEmpty(point)) |
546 |
points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y); |
547 |
else |
548 |
points.Add(point); |
549 |
} |
550 |
else |
551 |
points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y); |
552 |
} |
553 |
else |
554 |
{ |
555 |
Model.Line prevLine = groupLine[i - 1]; |
556 |
if (line.SlopeType == SlopeType.HORIZONTAL && |
557 |
prevLine.SlopeType == SlopeType.VERTICAL) |
558 |
points.Add(prevLine.Aveva.End_X + "," + line.Aveva.Start_Y); |
559 |
else if (line.SlopeType == SlopeType.VERTICAL && |
560 |
prevLine.SlopeType == SlopeType.HORIZONTAL) |
561 |
points.Add(line.Aveva.Start_X + "," + prevLine.Aveva.End_Y); |
562 |
else |
563 |
points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y); |
564 |
} |
565 |
|
566 |
if (i == groupLine.Count - 1) |
567 |
{ |
568 |
object connObj = line.CONNECTORS[1].ConnectedObject; |
569 |
if (connObj != null && connObj.GetType() == typeof(Symbol)) |
570 |
{ |
571 |
string point = GetPointByConnectedItem(connObj, line, false); |
572 |
if (string.IsNullOrEmpty(point)) |
573 |
points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y); |
574 |
else |
575 |
points.Add(point); |
576 |
} |
577 |
else |
578 |
points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y); |
579 |
} |
580 |
} |
581 |
} |
582 |
private string GetPointByConnectedItem(object connObj, Model.Line line, bool isStart) |
583 |
{ |
584 |
string result = string.Empty; |
585 |
double x; |
586 |
double y; |
587 |
if (isStart) |
588 |
{ |
589 |
x = line.Aveva.Start_X; |
590 |
y = line.Aveva.Start_Y; |
591 |
} |
592 |
else |
593 |
{ |
594 |
x = line.Aveva.End_X; |
595 |
y = line.Aveva.End_Y; |
596 |
} |
597 |
|
598 |
if (connObj.GetType() == typeof(Symbol)) |
599 |
{ |
600 |
Symbol connSymbol = connObj as Symbol; |
601 |
Connector connector = connSymbol.CONNECTORS.Find(loop => loop.ConnectedObject == line); |
602 |
|
603 |
SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y); |
604 |
if (slopeType == SlopeType.HORIZONTAL) |
605 |
result = connSymbol.Aveva.X + "," + y; |
606 |
else if (slopeType == SlopeType.VERTICAL) |
607 |
result = x + "," + connSymbol.Aveva.Y; |
608 |
else |
609 |
result = x + "," + y; |
610 |
} |
611 |
else if (connObj.GetType() == typeof(OPC)) |
612 |
{ |
613 |
OPC connOPC = connObj as OPC; |
614 |
Connector connector = connOPC.CONNECTORS.Find(loop => loop.ConnectedObject == line); |
615 |
|
616 |
double locX = 0, locY = 0, sizeWidth = 0, sizeHeight = 0, aX = 0, aY = 0; |
617 |
APIDUtils.ConvertPointBystring(connOPC.LOCATION, ref locX, ref locY); |
618 |
APIDUtils.ConvertPointBystring(connOPC.SIZE, ref sizeWidth, ref sizeHeight); |
619 |
locX = locX + sizeWidth / 2; |
620 |
locY = locY + sizeHeight / 2; |
621 |
aX = locX; |
622 |
aY = locY; |
623 |
document.ConvertAvevaPoint(ref aX, ref aY); |
624 |
|
625 |
SlopeType slopeType = APIDUtils.CalcSlope(locX, locY, connector.X, connector.Y); |
626 |
if (slopeType == SlopeType.HORIZONTAL) |
627 |
result = aX + "," + y; |
628 |
else if (slopeType == SlopeType.VERTICAL) |
629 |
result = x + "," + aY; |
630 |
else |
631 |
result = x + "," + y; |
632 |
} |
633 |
|
634 |
return result; |
635 |
} |
636 |
private bool IsExistEndBreak(object item1, object item2) |
637 |
{ |
638 |
bool result = false; |
639 |
if (item1 != null && item2 != null) |
640 |
{ |
641 |
EndBreak endBreak = document.EndBreaks.Find(x => |
642 |
(APIDUtils.FindObjectByUID(document, x.OWNER) == item1 && |
643 |
APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item2) || |
644 |
(APIDUtils.FindObjectByUID(document, x.OWNER) == item2 && |
645 |
APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item1)); |
646 |
|
647 |
if (endBreak != null) |
648 |
result = true; |
649 |
} |
650 |
|
651 |
return result; |
652 |
} |
653 |
private LineRun FindLineRun(Model.Line line) |
654 |
{ |
655 |
List<LineRun> allLineRun = new List<LineRun>(); |
656 |
foreach (var item in document.LINENUMBERS) |
657 |
allLineRun.AddRange(item.RUNS); |
658 |
foreach (var item in document.TRIMLINES) |
659 |
allLineRun.AddRange(item.RUNS); |
660 |
|
661 |
return allLineRun.Find(x => x.RUNITEMS.Contains(line)); |
662 |
} |
663 |
private Model.Line FindOtherLineByRun(Model.Line line, Symbol symbol) |
664 |
{ |
665 |
Model.Line result = null; |
666 |
LineRun run = FindLineRun(line); |
667 |
Connector connector = symbol.CONNECTORS.Find(x => |
668 |
x.ConnectedObject != null && |
669 |
x.ConnectedObject != line && |
670 |
run.RUNITEMS.Contains(x.ConnectedObject) && |
671 |
x.ConnectedObject.GetType() == typeof(Model.Line)); |
672 |
|
673 |
if (connector != null) |
674 |
result = connector.ConnectedObject as Model.Line; |
675 |
|
676 |
return result; |
677 |
} |
678 |
private bool CheckAngle(DataRow symbolRow) |
679 |
{ |
680 |
return int.Parse(symbolRow["Insert_Points"].ToString()).Equals(2); |
681 |
} |
682 |
private bool CheckBalloon(Symbol symbol) |
683 |
{ |
684 |
bool result = false; |
685 |
|
686 |
string text = string.Empty; |
687 |
Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name); |
688 |
if (symbolDefinitions.Count != 0) |
689 |
{ |
690 |
text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper(); |
691 |
|
692 |
if (text.Equals("VLP")) |
693 |
text = "VPO"; |
694 |
else if (text.Equals("IVP")) |
695 |
text = "IPO"; |
696 |
|
697 |
if (SymbolCategory.astrLabelBalloonBlockNames.Contains(text)) |
698 |
result = true;//dumbDwgUpgrade.addLabelBalloon(symbolForInsertion, objectId); |
699 |
} |
700 |
|
701 |
return result; |
702 |
} |
703 |
#endregion |
704 |
|
705 |
#region Test Source |
706 |
public void test() |
707 |
{ |
708 |
//InitGUI(); |
709 |
//DrawSignal("SONIC", new List<string>() { "2,100", "100,100" }); |
710 |
|
711 |
DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" }, null); |
712 |
return; |
713 |
Symbol symbol = new Symbol(); |
714 |
symbol.Aveva = new AvevaSymbolInfo(); |
715 |
symbol.Aveva.Name = "INVB"; |
716 |
symbol.Aveva.X = 50; |
717 |
symbol.Aveva.Y = 100; |
718 |
|
719 |
DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name)); |
720 |
if (allRows.Length == 1) |
721 |
{ |
722 |
DataRow symbolRow = allRows[0]; |
723 |
bool bAngle = CheckAngle(symbolRow); |
724 |
bool bBalloon = CheckBalloon(symbol); |
725 |
bBalloon = false; |
726 |
long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon); |
727 |
} |
728 |
|
729 |
Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name); |
730 |
string text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper(); |
731 |
if (int.Parse(symbolDefinitions[SymbolDefinition.symNoOfInsertPoints].ToString()).Equals(2)) |
732 |
{ |
733 |
bool bIsPromptRotate = true; |
734 |
} |
735 |
int num = int.Parse(symbolDefinitions[SymbolDefinition.symFixedOrUserDefined].ToString()); |
736 |
|
737 |
AssociateSymbolType eAssosiateSym = AssociateSymbolType.None; |
738 |
bool bIsSymbolHasAssociation = GraphicalUtility.FindSymbolHasAssociation(text, ref eAssosiateSym); |
739 |
bool bPlaceSimpleBlocks = SymbolCategory.astrSimplePlacedBlocks.Contains(text); |
740 |
|
741 |
//DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" }); |
742 |
|
743 |
//DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" }); |
744 |
} |
745 |
public static void TESTStatic() |
746 |
{ |
747 |
System.Data.DataTable avevaSymbolTable = Project_DB.SelectSymbolTable(); |
748 |
AutoModeling auto = new AutoModeling(null, avevaSymbolTable); |
749 |
auto.test(); |
750 |
} |
751 |
#endregion |
752 |
} |
753 |
|
754 |
|
755 |
public static class AcDbLinqExtensionMethods |
756 |
{ |
757 |
/// <summary> |
758 |
/// Get all references to the given BlockTableRecord, including |
759 |
/// references to anonymous dynamic BlockTableRecords. |
760 |
/// </summary> |
761 |
|
762 |
public static IEnumerable<BlockReference> GetBlockReferences( |
763 |
this BlockTableRecord btr, |
764 |
OpenMode mode = OpenMode.ForRead, |
765 |
bool directOnly = true) |
766 |
{ |
767 |
if (btr == null) |
768 |
throw new ArgumentNullException("btr"); |
769 |
var tr = btr.Database.TransactionManager.TopTransaction; |
770 |
if (tr == null) |
771 |
throw new InvalidOperationException("No transaction"); |
772 |
var ids = btr.GetBlockReferenceIds(directOnly, true); |
773 |
int cnt = ids.Count; |
774 |
for (int i = 0; i < cnt; i++) |
775 |
{ |
776 |
yield return (BlockReference) |
777 |
tr.GetObject(ids[i], mode, false, false); |
778 |
} |
779 |
if (btr.IsDynamicBlock) |
780 |
{ |
781 |
BlockTableRecord btr2 = null; |
782 |
var blockIds = btr.GetAnonymousBlockIds(); |
783 |
cnt = blockIds.Count; |
784 |
for (int i = 0; i < cnt; i++) |
785 |
{ |
786 |
btr2 = (BlockTableRecord)tr.GetObject(blockIds[i], |
787 |
OpenMode.ForRead, false, false); |
788 |
ids = btr2.GetBlockReferenceIds(directOnly, true); |
789 |
int cnt2 = ids.Count; |
790 |
for (int j = 0; j < cnt2; j++) |
791 |
{ |
792 |
yield return (BlockReference) |
793 |
tr.GetObject(ids[j], mode, false, false); |
794 |
} |
795 |
} |
796 |
} |
797 |
} |
798 |
} |
799 |
} |