개정판 73152510
dev issue #1231 : Symbol Modeling
Change-Id: Ic999efe8e79f42dd5d374fcc25affdb07c4cb802
DTI_PID/APIDConverter/AutoModeling.cs | ||
---|---|---|
126 | 126 |
} |
127 | 127 |
private void SymbolModeling(Symbol symbol) |
128 | 128 |
{ |
129 |
|
|
129 |
long handle = InsertSymbol(symbol.Aveva.Name, symbol.Aveva.X, symbol.Aveva.Y); |
|
130 |
if (handle != 0) |
|
131 |
symbol.Aveva.Handle = handle; |
|
130 | 132 |
} |
131 | 133 |
#endregion |
132 | 134 |
|
... | ... | |
226 | 228 |
else |
227 | 229 |
return 0; |
228 | 230 |
} |
229 |
private void InsertSymbol(string insertSymbolName, double x, double y)
|
|
231 |
private long InsertSymbol(string insertSymbolName, double x, double y)
|
|
230 | 232 |
{ |
233 |
long handle = 0; |
|
231 | 234 |
try |
232 | 235 |
{ |
236 |
List<long> prevHandles = GetAllBlockHandlesByName(insertSymbolName); |
|
237 |
|
|
233 | 238 |
AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData(); |
234 | 239 |
drawingData.InsertSymbolName = insertSymbolName; |
235 | 240 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
... | ... | |
241 | 246 |
commandParam.Add(null); |
242 | 247 |
|
243 | 248 |
editor.Command(commandParam.ToArray()); |
249 |
|
|
250 |
List<long> newHandles = GetAllBlockHandlesByName(insertSymbolName); |
|
251 |
List<long> otherHandles = new List<long>(); |
|
252 |
foreach (var item in newHandles) |
|
253 |
if (!prevHandles.Contains(item)) |
|
254 |
otherHandles.Add(item); |
|
255 |
|
|
256 |
if (otherHandles.Count == 1) |
|
257 |
return otherHandles[0]; |
|
258 |
else |
|
259 |
return 0; |
|
244 | 260 |
} |
245 | 261 |
catch (System.Exception ex) |
246 | 262 |
{ |
247 | 263 |
|
248 | 264 |
} |
265 |
|
|
266 |
return handle; |
|
249 | 267 |
} |
250 | 268 |
#endregion |
251 | 269 |
|
252 |
#region |
|
270 |
#region Autocad Utils |
|
271 |
private List<long> GetAllBlockHandlesByName(string name) |
|
272 |
{ |
|
273 |
List<long> handles = new List<long>(); |
|
274 |
|
|
275 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
|
276 |
Database acCurDb = acDoc.Database; |
|
277 |
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
|
278 |
{ |
|
279 |
BlockTable gd = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead); |
|
280 |
foreach (var entry in gd) |
|
281 |
{ |
|
282 |
BlockTableRecord blockTableRecord = acTrans.GetObject(entry, OpenMode.ForRead, true) as BlockTableRecord; |
|
283 |
if (blockTableRecord != null) |
|
284 |
{ |
|
285 |
IEnumerable<BlockReference> records = AcDbLinqExtensionMethods.GetBlockReferences(blockTableRecord); |
|
286 |
foreach (var item in records) |
|
287 |
{ |
|
288 |
if (item.Name == name) |
|
289 |
handles.Add(item.Handle.Value); |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
293 |
|
|
294 |
acTrans.Commit(); |
|
295 |
} |
|
296 |
return handles; |
|
297 |
} |
|
253 | 298 |
private List<long> GetAllGroupHandles() |
254 | 299 |
{ |
255 | 300 |
List<long> handles = new List<long>(); |
... | ... | |
295 | 340 |
|
296 | 341 |
return result; |
297 | 342 |
} |
298 |
|
|
299 |
|
|
300 |
|
|
301 | 343 |
#endregion |
302 | 344 |
|
303 |
#region |
|
345 |
#region Modeling Utils
|
|
304 | 346 |
private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert) |
305 | 347 |
{ |
306 | 348 |
if (!group.Contains(line)) |
... | ... | |
413 | 455 |
//DrawSignal("SONIC", new List<string>() { "2,100", "100,100" }); |
414 | 456 |
|
415 | 457 |
DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" }); |
416 |
|
|
458 |
InsertSymbol("BAVA", 50, 100); |
|
417 | 459 |
//DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" }); |
418 | 460 |
|
419 | 461 |
//DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" }); |
420 | 462 |
} |
463 |
|
|
464 |
|
|
421 | 465 |
public static void TESTStatic() |
422 | 466 |
{ |
423 | 467 |
AutoModeling auto = new AutoModeling(null); |
... | ... | |
425 | 469 |
} |
426 | 470 |
#endregion |
427 | 471 |
} |
472 |
|
|
473 |
|
|
474 |
public static class AcDbLinqExtensionMethods |
|
475 |
{ |
|
476 |
/// <summary> |
|
477 |
/// Get all references to the given BlockTableRecord, including |
|
478 |
/// references to anonymous dynamic BlockTableRecords. |
|
479 |
/// </summary> |
|
480 |
|
|
481 |
public static IEnumerable<BlockReference> GetBlockReferences( |
|
482 |
this BlockTableRecord btr, |
|
483 |
OpenMode mode = OpenMode.ForRead, |
|
484 |
bool directOnly = true) |
|
485 |
{ |
|
486 |
if (btr == null) |
|
487 |
throw new ArgumentNullException("btr"); |
|
488 |
var tr = btr.Database.TransactionManager.TopTransaction; |
|
489 |
if (tr == null) |
|
490 |
throw new InvalidOperationException("No transaction"); |
|
491 |
var ids = btr.GetBlockReferenceIds(directOnly, true); |
|
492 |
int cnt = ids.Count; |
|
493 |
for (int i = 0; i < cnt; i++) |
|
494 |
{ |
|
495 |
yield return (BlockReference) |
|
496 |
tr.GetObject(ids[i], mode, false, false); |
|
497 |
} |
|
498 |
if (btr.IsDynamicBlock) |
|
499 |
{ |
|
500 |
BlockTableRecord btr2 = null; |
|
501 |
var blockIds = btr.GetAnonymousBlockIds(); |
|
502 |
cnt = blockIds.Count; |
|
503 |
for (int i = 0; i < cnt; i++) |
|
504 |
{ |
|
505 |
btr2 = (BlockTableRecord)tr.GetObject(blockIds[i], |
|
506 |
OpenMode.ForRead, false, false); |
|
507 |
ids = btr2.GetBlockReferenceIds(directOnly, true); |
|
508 |
int cnt2 = ids.Count; |
|
509 |
for (int j = 0; j < cnt2; j++) |
|
510 |
{ |
|
511 |
yield return (BlockReference) |
|
512 |
tr.GetObject(ids[j], mode, false, false); |
|
513 |
} |
|
514 |
} |
|
515 |
} |
|
516 |
} |
|
517 |
} |
|
428 | 518 |
} |
내보내기 Unified diff