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