hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ fdcf00d4
이력 | 보기 | 이력해설 | 다운로드 (119 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Drawing; |
5 |
using System.Data; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows.Forms; |
10 |
using System.Threading; |
11 |
using System.IO; |
12 |
using Microsoft.VisualBasic; |
13 |
using Ingr.RAD2D; |
14 |
using Converter.BaseModel; |
15 |
using Converter.SPPID.Properties; |
16 |
using Converter.SPPID.DB; |
17 |
using Converter.SPPID.Util; |
18 |
using Converter.SPPID.Form; |
19 |
using Converter.SPPID.Model; |
20 |
using Plaice; |
21 |
using Llama; |
22 |
using DevExpress.XtraSplashScreen; |
23 |
using Newtonsoft.Json; |
24 |
using System.Runtime.InteropServices; |
25 |
using System.Reflection; |
26 |
using Converter.SPPID.OPC; |
27 |
|
28 |
namespace Converter.SPPID.Wrapper |
29 |
{ |
30 |
public partial class ConverterDocking : UserControl |
31 |
{ |
32 |
Ingr.RAD2D.Application application; |
33 |
internal static bool addEvent = false; |
34 |
public ConverterDocking() |
35 |
{ |
36 |
InitializeComponent(); |
37 |
spinEditSymmetry.Properties.Mask.EditMask = "f0"; |
38 |
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
39 |
WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
40 |
application = wApp.RADApplication; |
41 |
|
42 |
ReleaseCOMObjects(dApplication); |
43 |
dApplication = null; |
44 |
try |
45 |
{ |
46 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
47 |
_ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
48 |
_ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
49 |
_ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
50 |
_ProjectInfo.Port = Settings.Default.ProjectPort; |
51 |
_ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
52 |
_ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
53 |
if (Project_DB.ConnTestAndCreateTable()) |
54 |
{ |
55 |
_ProjectInfo.Enable = true; |
56 |
layoutControlGroupUtils.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
57 |
|
58 |
DataTable dt = Project_DB.SelectSetting(); |
59 |
foreach (DataRow item in dt.Rows) |
60 |
{ |
61 |
string settingType = item["SettingType"].ToString(); |
62 |
if (settingType == "ETCSetting") |
63 |
SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString()); |
64 |
else if (settingType == "GridSetting") |
65 |
SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString()); |
66 |
} |
67 |
} |
68 |
else |
69 |
{ |
70 |
layoutControlGroupUtils.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
71 |
} |
72 |
|
73 |
if (!addEvent) |
74 |
{ |
75 |
application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit; |
76 |
addEvent = true; |
77 |
} |
78 |
} |
79 |
catch (Exception ex) |
80 |
{ |
81 |
StringBuilder sb = new StringBuilder(); |
82 |
sb.AppendLine(ex.Message); |
83 |
sb.AppendLine(ex.StackTrace); |
84 |
MessageBox.Show(sb.ToString()); |
85 |
} |
86 |
|
87 |
#if DEBUG |
88 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
89 |
layoutControlGroup1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
90 |
|
91 |
#else |
92 |
layoutControlGroup1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
93 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
94 |
#endif |
95 |
|
96 |
//#if DEBUG |
97 |
// layoutControlGroupConverter.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
98 |
// layoutControlGroupUtils.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
99 |
// layoutControlGroupShortCut.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
100 |
// this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
101 |
// this.layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
102 |
//#endif |
103 |
} |
104 |
private void ApplicationEvents_ApplicationExit(out bool cancel) |
105 |
{ |
106 |
cancel = false; |
107 |
} |
108 |
/// <summary> |
109 |
/// 선택한 도면들을 읽어서 SPPID로 변환한다. |
110 |
/// </summary> |
111 |
/// <param name="sender"></param> |
112 |
/// <param name="e"></param> |
113 |
private void btnConverter_Click(object sender, EventArgs e) |
114 |
{ |
115 |
ConverterForm converterForm = new ConverterForm(); |
116 |
if (converterForm.ShowDialog() == DialogResult.OK) |
117 |
{ |
118 |
//Ingr.RAD2D.Document doc = application.Documents.Add(); |
119 |
|
120 |
try |
121 |
{ |
122 |
CloseOPCForm.Run(); |
123 |
|
124 |
for (int i = 0; i < converterForm.Documents.Count; i++) |
125 |
{ |
126 |
SPPID_Document document = converterForm.Documents[i]; |
127 |
if (document.SetSPPIDMapping() && document.Enable) |
128 |
{ |
129 |
using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked)) |
130 |
{ |
131 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
132 |
modeling.Run(); |
133 |
|
134 |
List<string> endLine = new List<string>(); |
135 |
Placement placement = new Placement(); |
136 |
LMADataSource dataSource = placement.PIDDataSource; |
137 |
|
138 |
foreach (var lineNumber in document.LINENUMBERS) |
139 |
{ |
140 |
foreach (LineRun run in lineNumber.RUNS) |
141 |
{ |
142 |
foreach (var item in run.RUNITEMS) |
143 |
{ |
144 |
if (item.GetType() == typeof(Line)) |
145 |
{ |
146 |
Line line = item as Line; |
147 |
if (line != null && !endLine.Contains(line.SPPID.ModelItemId)) |
148 |
{ |
149 |
LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
150 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
151 |
{ |
152 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
153 |
{ |
154 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
155 |
if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None" && mapping.SPPIDATTRIBUTENAME == "PlantGroup.Name") |
156 |
{ |
157 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
158 |
if (_LMAAttribute != null) |
159 |
{ |
160 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
161 |
_LMAAttribute.set_Value(attribute.VALUE); |
162 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
163 |
_LMAAttribute.set_Value(attribute.VALUE); |
164 |
} |
165 |
} |
166 |
} |
167 |
_LMModelItem.Commit(); |
168 |
} |
169 |
if (_LMModelItem != null) |
170 |
ReleaseCOMObjects(_LMModelItem); |
171 |
endLine.Add(line.SPPID.ModelItemId); |
172 |
} |
173 |
} |
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
ReleaseCOMObjects(dataSource); |
179 |
ReleaseCOMObjects(placement); |
180 |
} |
181 |
} |
182 |
} |
183 |
} |
184 |
catch (Exception ex) |
185 |
{ |
186 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
187 |
} |
188 |
finally |
189 |
{ |
190 |
CloseOPCForm.Stop(); |
191 |
|
192 |
//doc.SaveOnClose = false; |
193 |
//doc.Close(false); |
194 |
|
195 |
//dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
196 |
//dApplication.Drawings[1].CloseDrawing(false); |
197 |
//ReleaseCOMObjects(dApplication); |
198 |
//dApplication = null; |
199 |
} |
200 |
|
201 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
202 |
} |
203 |
} |
204 |
|
205 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
206 |
{ |
207 |
DataTable tOPCInfo = Project_DB.SelectOPCInfo(); |
208 |
DataTable tOPCRelations = Project_DB.SelectOPCRelations(); |
209 |
DataTable tDrawingInfo = Project_DB.SelectDrawingInfo(); |
210 |
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
211 |
|
212 |
foreach (DataRow row in tOPCInfo.Rows) |
213 |
{ |
214 |
if (!Convert.ToBoolean(row["PAIRED"])) |
215 |
{ |
216 |
string drawingUID = row["ID2_DRAWING_UID"].ToString(); |
217 |
string OPCUID = row["ID2_OPC_UID"].ToString(); |
218 |
DataRow[] rows = tOPCRelations.Select(string.Format("(From_Drawings_UID = '{0}' AND From_OPC_UID = '{1}') OR (To_Drawings_UID = '{0}' AND To_OPC_UID = '{1}')", drawingUID, OPCUID)); |
219 |
|
220 |
if (rows.Length == 2) |
221 |
{ |
222 |
string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString(); |
223 |
string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString(); |
224 |
string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString(); |
225 |
string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString(); |
226 |
string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString(); |
227 |
string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString(); |
228 |
string toOPCUID1 = rows[0]["To_OPC_UID"].ToString(); |
229 |
string toOPCUID2 = rows[1]["To_OPC_UID"].ToString(); |
230 |
|
231 |
DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1)); |
232 |
DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1)); |
233 |
DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1)); |
234 |
DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1)); |
235 |
|
236 |
if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1) |
237 |
{ |
238 |
DataRow fromOPCInfoRow = fromOPCInfoRows[0]; |
239 |
DataRow toOPCInfoRow = toOPCInfoRows[0]; |
240 |
string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
241 |
string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
242 |
string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString(); |
243 |
List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString()); |
244 |
AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes); |
245 |
if (opc.Run()) |
246 |
{ |
247 |
fromOPCInfoRow["PAIRED"] = true; |
248 |
toOPCInfoRow["PAIRED"] = true; |
249 |
|
250 |
Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
251 |
Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
252 |
} |
253 |
} |
254 |
} |
255 |
} |
256 |
} |
257 |
|
258 |
tOPCInfo.Dispose(); |
259 |
tOPCRelations.Dispose(); |
260 |
tDrawingInfo.Dispose(); |
261 |
ReleaseCOMObjects(dApplication); |
262 |
dApplication = null; |
263 |
|
264 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
265 |
} |
266 |
|
267 |
public void ReleaseCOMObjects(params object[] objVars) |
268 |
{ |
269 |
int intNewRefCount = 0; |
270 |
foreach (object obj in objVars) |
271 |
{ |
272 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
273 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
274 |
} |
275 |
} |
276 |
|
277 |
|
278 |
|
279 |
#region SPPID Utils |
280 |
|
281 |
#region Symmetry |
282 |
private void btnSymmetry_Click(object sender, EventArgs e) |
283 |
{ |
284 |
if (application.ActiveSelectSet.Count == 1 && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d)) |
285 |
{ |
286 |
int symCount = (int)spinEditSymmetry.Value; |
287 |
Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
288 |
double x, y; |
289 |
symbol.GetOrigin(out x, out y); |
290 |
string rep = GetRepresentationId(symbol); |
291 |
List<string> verticalRepID = new List<string>(); |
292 |
List<string> horizontalRepID = new List<string>(); |
293 |
|
294 |
if ((symbol.LinearName.Contains("Piping") || |
295 |
symbol.LinearName.Contains("Instrument")) && |
296 |
!string.IsNullOrEmpty(rep)) |
297 |
{ |
298 |
Placement placement = new Placement(); |
299 |
LMADataSource dataSource = placement.PIDDataSource; |
300 |
List<List<string>> datas = SetSymbol(dataSource, rep, x, y, symCount); |
301 |
Dictionary<SymmetryArrow, List<string>> resultDatas = new Dictionary<SymmetryArrow, List<string>>(); |
302 |
if (datas.Count >= 2 && datas.Find(loop => loop.Count != symCount) == null) |
303 |
{ |
304 |
SymmetryArrow arrow = SymmetryArrow.None; |
305 |
foreach (var data in datas) |
306 |
{ |
307 |
LMSymbol firstSymbol = dataSource.GetSymbol(data[0]); |
308 |
double fX = firstSymbol.get_XCoordinate(); |
309 |
double fY = firstSymbol.get_YCoordinate(); |
310 |
|
311 |
SlopeType type = SPPIDUtil.CalcSlope(x, y, fX, fY, 1); |
312 |
if (type == SlopeType.HORIZONTAL) |
313 |
{ |
314 |
if (fX < x) |
315 |
{ |
316 |
arrow |= SymmetryArrow.Left; |
317 |
resultDatas.Add(SymmetryArrow.Left, data); |
318 |
} |
319 |
else |
320 |
{ |
321 |
arrow |= SymmetryArrow.Right; |
322 |
resultDatas.Add(SymmetryArrow.Right, data); |
323 |
} |
324 |
|
325 |
} |
326 |
else if (type == SlopeType.VERTICAL) |
327 |
{ |
328 |
if (fY < y) |
329 |
{ |
330 |
arrow |= SymmetryArrow.Down; |
331 |
resultDatas.Add(SymmetryArrow.Down, data); |
332 |
} |
333 |
else |
334 |
{ |
335 |
arrow |= SymmetryArrow.Up; |
336 |
resultDatas.Add(SymmetryArrow.Up, data); |
337 |
} |
338 |
} |
339 |
|
340 |
ReleaseCOMObjects(firstSymbol); |
341 |
} |
342 |
|
343 |
SymmetryForm form = new SymmetryForm(arrow); |
344 |
if (form.ShowDialog() == DialogResult.OK) |
345 |
{ |
346 |
MoveByResult(dataSource, resultDatas, x, y, form.Result, rep); |
347 |
} |
348 |
} |
349 |
else |
350 |
MessageBox.Show("Check Symmetry Rules", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
351 |
ReleaseCOMObjects(dataSource); |
352 |
ReleaseCOMObjects(placement); |
353 |
} |
354 |
} |
355 |
|
356 |
return; |
357 |
|
358 |
List<Symbol2d> symbols = new List<Symbol2d>(); |
359 |
foreach (var item in application.ActiveSelectSet) |
360 |
{ |
361 |
Type type = item.GetType(); |
362 |
if (type == typeof(Symbol2d)) |
363 |
{ |
364 |
Symbol2d symbol = item as Symbol2d; |
365 |
if (symbol.LinearName.Contains("Piping") || |
366 |
symbol.LinearName.Contains("Instrument")) |
367 |
symbols.Add(symbol); |
368 |
} |
369 |
//if (item.GetType() == typeof(Symbol2d) || item.GetType() == typeof(Point2d)) |
370 |
// items.Add(item); |
371 |
} |
372 |
|
373 |
List<Symbol2d> verticalSymbols = new List<Symbol2d>(); |
374 |
List<Symbol2d> horizontalSymbols = new List<Symbol2d>(); |
375 |
Symbol2d mainSymbol = null; |
376 |
for (int i = 0; i < symbols.Count - 1; i++) |
377 |
{ |
378 |
Symbol2d symbol1 = symbols[i]; |
379 |
for (int j = 1; j < symbols.Count; j++) |
380 |
{ |
381 |
Symbol2d symbol2 = symbols[j]; |
382 |
|
383 |
if (symbol1 != symbol2) |
384 |
{ |
385 |
double x1, y1, x2, y2; |
386 |
symbol1.GetOrigin(out x1, out y1); |
387 |
symbol2.GetOrigin(out x2, out y2); |
388 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 1); |
389 |
if (slopeType == SlopeType.HORIZONTAL) |
390 |
{ |
391 |
if (!horizontalSymbols.Contains(symbol1)) |
392 |
horizontalSymbols.Add(symbol1); |
393 |
if (!horizontalSymbols.Contains(symbol2)) |
394 |
horizontalSymbols.Add(symbol2); |
395 |
|
396 |
if (verticalSymbols.Contains(symbol1)) |
397 |
mainSymbol = symbol1; |
398 |
if (verticalSymbols.Contains(symbol2)) |
399 |
mainSymbol = symbol2; |
400 |
} |
401 |
else if (slopeType == SlopeType.VERTICAL) |
402 |
{ |
403 |
if (!verticalSymbols.Contains(symbol1)) |
404 |
verticalSymbols.Add(symbol1); |
405 |
if (!verticalSymbols.Contains(symbol2)) |
406 |
verticalSymbols.Add(symbol2); |
407 |
|
408 |
if (horizontalSymbols.Contains(symbol1)) |
409 |
mainSymbol = symbol1; |
410 |
if (horizontalSymbols.Contains(symbol2)) |
411 |
mainSymbol = symbol2; |
412 |
} |
413 |
} |
414 |
} |
415 |
} |
416 |
|
417 |
application.ActiveSelectSet.RemoveAll(); |
418 |
foreach (var item in verticalSymbols) |
419 |
application.ActiveSelectSet.Add(item); |
420 |
foreach (var item in horizontalSymbols) |
421 |
application.ActiveSelectSet.Add(item); |
422 |
|
423 |
|
424 |
if (MessageBox.Show("Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) |
425 |
{ |
426 |
application.ActiveSelectSet.RemoveAll(); |
427 |
|
428 |
} |
429 |
} |
430 |
private void MoveByResult(LMADataSource dataSource,Dictionary<SymmetryArrow, List<string>> resultDatas, double x, double y, SymmetryArrow arrow, string centerRepID) |
431 |
{ |
432 |
List<string> datas = resultDatas[arrow]; |
433 |
foreach (var item in resultDatas) |
434 |
{ |
435 |
if (item.Key != arrow) |
436 |
{ |
437 |
for (int i = 0; i < item.Value.Count; i++) |
438 |
{ |
439 |
Symbol2d moveSymbol2d = GetSymbol2DByRepID(dataSource, item.Value[i]); |
440 |
Symbol2d symbol2d = GetSymbol2DByRepID(dataSource, datas[i]); |
441 |
|
442 |
double x1, y1, x2, y2; |
443 |
symbol2d.GetOrigin(out x1, out y1); |
444 |
moveSymbol2d.GetOrigin(out x2, out y2); |
445 |
double distance = SPPIDUtil.CalcPointToPointdDistance(x, y, x1, y1); |
446 |
|
447 |
string symbol1RepID; |
448 |
string symbol2RepID; |
449 |
List<Point2d> point2ds; |
450 |
if (i == 0) |
451 |
{ |
452 |
symbol1RepID = centerRepID; |
453 |
symbol2RepID = item.Value[i]; |
454 |
} |
455 |
else |
456 |
{ |
457 |
symbol1RepID = item.Value[i - 1]; |
458 |
symbol2RepID = item.Value[i]; |
459 |
} |
460 |
point2ds = FindAllPoint2d(dataSource, symbol1RepID, symbol2RepID); |
461 |
double moveX = 0; |
462 |
double moveY = 0; |
463 |
|
464 |
if (item.Key == SymmetryArrow.Left) |
465 |
moveX = x - distance - x2; |
466 |
else if (item.Key == SymmetryArrow.Right) |
467 |
moveX = x + distance - x2; |
468 |
else if (item.Key == SymmetryArrow.Down) |
469 |
moveY = y - distance - y2; |
470 |
else if (item.Key == SymmetryArrow.Up) |
471 |
moveY = y + distance - y2; |
472 |
|
473 |
moveSymbol2d.Move(0, 0, moveX, moveY); |
474 |
MovePoint2d(dataSource, item.Value[i], arrow, moveX, moveY); |
475 |
foreach (var point in point2ds) |
476 |
{ |
477 |
LMSymbol branch = dataSource.GetSymbol(GetRepresentationId(point)); |
478 |
LMSymbol connSymbol = GetFirstSymbolBySlope(dataSource, branch, symbol1RepID, symbol2RepID); |
479 |
point.Move(0, 0, moveX, moveY); |
480 |
if (connSymbol != null) |
481 |
{ |
482 |
Symbol2d connSymbol2d = GetSymbol2DByRepID(dataSource, connSymbol.AsLMRepresentation().Id); |
483 |
connSymbol2d.Move(0, 0, moveX, moveY); |
484 |
ReleaseCOMObjects(connSymbol); |
485 |
} |
486 |
ReleaseCOMObjects(branch); |
487 |
} |
488 |
|
489 |
} |
490 |
} |
491 |
} |
492 |
} |
493 |
private LMSymbol GetFirstSymbolBySlope(LMADataSource dataSource, LMSymbol branch, string symbol1RepID, string symbol2RepID) |
494 |
{ |
495 |
LMSymbol result = null; |
496 |
foreach (LMConnector connector in branch.Connect1Connectors) |
497 |
{ |
498 |
if (connector.ConnectItem1SymbolObject != null && |
499 |
connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
500 |
connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
501 |
{ |
502 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
503 |
if (repID != symbol1RepID && repID != symbol2RepID) |
504 |
result = connector.ConnectItem1SymbolObject; |
505 |
} |
506 |
|
507 |
if (connector.ConnectItem2SymbolObject != null && |
508 |
connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
509 |
connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
510 |
{ |
511 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
512 |
if (repID != symbol1RepID && repID != symbol2RepID) |
513 |
result = connector.ConnectItem2SymbolObject; |
514 |
} |
515 |
} |
516 |
|
517 |
foreach (LMConnector connector in branch.Connect2Connectors) |
518 |
{ |
519 |
if (connector.ConnectItem1SymbolObject != null && |
520 |
connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
521 |
connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
522 |
{ |
523 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
524 |
if (repID != symbol1RepID && repID != symbol2RepID) |
525 |
result = connector.ConnectItem1SymbolObject; |
526 |
} |
527 |
|
528 |
if (connector.ConnectItem2SymbolObject != null && |
529 |
connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
530 |
connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
531 |
{ |
532 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
533 |
if (repID != symbol1RepID && repID != symbol2RepID) |
534 |
result = connector.ConnectItem2SymbolObject; |
535 |
} |
536 |
} |
537 |
|
538 |
|
539 |
return result; |
540 |
} |
541 |
private string GetRepresentationId(Symbol2d symbol) |
542 |
{ |
543 |
foreach (var attributes in symbol.AttributeSets) |
544 |
{ |
545 |
foreach (var attribute in attributes) |
546 |
{ |
547 |
string name = attribute.Name; |
548 |
object value = attribute.GetValue(); |
549 |
if (name == "DrawingID") |
550 |
{ |
551 |
return value.ToString(); |
552 |
} |
553 |
} |
554 |
} |
555 |
return null; |
556 |
} |
557 |
private string GetRepresentationId(Point2d point2d) |
558 |
{ |
559 |
foreach (var attributes in point2d.AttributeSets) |
560 |
{ |
561 |
foreach (var attribute in attributes) |
562 |
{ |
563 |
string name = attribute.Name; |
564 |
object value = attribute.GetValue(); |
565 |
if (name == "DrawingID") |
566 |
{ |
567 |
return value.ToString(); |
568 |
} |
569 |
} |
570 |
} |
571 |
return null; |
572 |
} |
573 |
private List<List<string>> SetSymbol(LMADataSource dataSource, string rep, double x, double y, int count) |
574 |
{ |
575 |
LMSymbol _LMSymbol = dataSource.GetSymbol(rep); |
576 |
List<List<string>> result = new List<List<string>>(); |
577 |
List<string> oldIDs = new List<string>() { rep }; |
578 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
579 |
{ |
580 |
if (connector.get_ItemStatus() != "Active") |
581 |
continue; |
582 |
|
583 |
string repID = connector.AsLMRepresentation().Id; |
584 |
string status = connector.get_ItemStatus(); |
585 |
if (status == "Active" && !oldIDs.Contains(repID)) |
586 |
{ |
587 |
List<string> symbols = new List<string>(); |
588 |
oldIDs.Add(repID); |
589 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
590 |
result.Add(symbols); |
591 |
} |
592 |
} |
593 |
|
594 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
595 |
{ |
596 |
if (connector.get_ItemStatus() != "Active") |
597 |
continue; |
598 |
|
599 |
string repID = connector.AsLMRepresentation().Id; |
600 |
string status = connector.get_ItemStatus(); |
601 |
if (status == "Active" && !oldIDs.Contains(repID)) |
602 |
{ |
603 |
List<string> symbols = new List<string>(); |
604 |
oldIDs.Add(repID); |
605 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
606 |
result.Add(symbols); |
607 |
} |
608 |
} |
609 |
|
610 |
ReleaseCOMObjects(_LMSymbol); |
611 |
return result; |
612 |
} |
613 |
private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMConnector connector, double x, double y, int count) |
614 |
{ |
615 |
if (symbols.Count >= count) |
616 |
return; |
617 |
|
618 |
if (connector.ConnectItem1SymbolObject != null && !oldIDs.Contains(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id)) |
619 |
{ |
620 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
621 |
oldIDs.Add(repID); |
622 |
if (connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
623 |
{ |
624 |
double sX = connector.ConnectItem1SymbolObject.get_XCoordinate(), sY = connector.ConnectItem1SymbolObject.get_YCoordinate(); ; |
625 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1); |
626 |
if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL) |
627 |
symbols.Add(repID); |
628 |
} |
629 |
|
630 |
loop(dataSource, oldIDs, symbols, connector.ConnectItem1SymbolObject, x, y, count); |
631 |
} |
632 |
|
633 |
if (symbols.Count >= count) |
634 |
return; |
635 |
|
636 |
if (connector.ConnectItem2SymbolObject != null && !oldIDs.Contains(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id)) |
637 |
{ |
638 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
639 |
oldIDs.Add(repID); |
640 |
if (connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
641 |
{ |
642 |
double sX = connector.ConnectItem2SymbolObject.get_XCoordinate(), sY = connector.ConnectItem2SymbolObject.get_YCoordinate(); ; |
643 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1); |
644 |
if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL) |
645 |
symbols.Add(repID); |
646 |
} |
647 |
|
648 |
loop(dataSource, oldIDs, symbols, connector.ConnectItem2SymbolObject, x, y, count); |
649 |
} |
650 |
} |
651 |
private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMSymbol _LMSymbol, double x, double y, int count) |
652 |
{ |
653 |
if (symbols.Count >= count) |
654 |
return; |
655 |
|
656 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
657 |
{ |
658 |
if (connector.get_ItemStatus() != "Active") |
659 |
continue; |
660 |
|
661 |
string repID = connector.AsLMRepresentation().Id; |
662 |
string status = connector.get_ItemStatus(); |
663 |
if (status == "Active" && !oldIDs.Contains(repID)) |
664 |
{ |
665 |
oldIDs.Add(repID); |
666 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
667 |
} |
668 |
} |
669 |
|
670 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
671 |
{ |
672 |
if (connector.get_ItemStatus() != "Active") |
673 |
continue; |
674 |
|
675 |
string repID = connector.AsLMRepresentation().Id; |
676 |
string status = connector.get_ItemStatus(); |
677 |
if (status == "Active" && !oldIDs.Contains(repID)) |
678 |
{ |
679 |
oldIDs.Add(repID); |
680 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
681 |
} |
682 |
} |
683 |
} |
684 |
private Symbol2d GetSymbol2DByRepID(LMADataSource dataSource, string repID) |
685 |
{ |
686 |
LMSymbol _LMSymbol = dataSource.GetSymbol(repID); |
687 |
Symbol2d symbol2D = application.ActiveDocument.ActiveSheet.DrawingObjects[_LMSymbol.get_GraphicOID().ToString()]; |
688 |
ReleaseCOMObjects(_LMSymbol); |
689 |
return symbol2D; |
690 |
} |
691 |
private void MovePoint2d(LMADataSource datasource, string repID, SymmetryArrow arrow, double moveX, double moveY) |
692 |
{ |
693 |
LMSymbol _LMSymbol = datasource.GetSymbol(repID); |
694 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
695 |
{ |
696 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength())) |
697 |
{ |
698 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
699 |
{ |
700 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
701 |
point.X += moveX; |
702 |
point.Y += moveY; |
703 |
} |
704 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
705 |
{ |
706 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
707 |
point.X += moveX; |
708 |
point.Y += moveY; |
709 |
} |
710 |
} |
711 |
} |
712 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
713 |
{ |
714 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength())) |
715 |
{ |
716 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
717 |
{ |
718 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
719 |
point.X += moveX; |
720 |
point.Y += moveY; |
721 |
} |
722 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
723 |
{ |
724 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
725 |
point.X += moveX; |
726 |
point.Y += moveY; |
727 |
} |
728 |
} |
729 |
} |
730 |
ReleaseCOMObjects(_LMSymbol); |
731 |
} |
732 |
private List<Point2d> FindAllPoint2d(LMADataSource dataSource, string repID, string nextRepID) |
733 |
{ |
734 |
LMSymbol _LMSymbol = dataSource.GetSymbol(repID); |
735 |
List<string> endIDs = new List<string>() { repID }; |
736 |
List<string> graphicOIDs = new List<string>(); |
737 |
List<Point2d> result = new List<Point2d>(); |
738 |
FindPointsLoop(dataSource, _LMSymbol, endIDs, nextRepID, graphicOIDs); |
739 |
ReleaseCOMObjects(_LMSymbol); |
740 |
foreach (var item in graphicOIDs) |
741 |
{ |
742 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[item] as Point2d; |
743 |
result.Add(point); |
744 |
} |
745 |
|
746 |
return result; |
747 |
} |
748 |
private bool FindPointsLoop(LMADataSource dataSource, LMSymbol _LMSymbol, List<string> endIDs, string targetRepID, List<string> graphicOIDs) |
749 |
{ |
750 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
751 |
{ |
752 |
if (connector.get_ItemStatus() != "Active") |
753 |
continue; |
754 |
|
755 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
756 |
{ |
757 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
758 |
if (!endIDs.Contains(repID)) |
759 |
{ |
760 |
endIDs.Add(repID); |
761 |
if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
762 |
{ |
763 |
if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs)) |
764 |
{ |
765 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
766 |
graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()); |
767 |
return true; |
768 |
} |
769 |
} |
770 |
else if (targetRepID == repID) |
771 |
{ |
772 |
return true; |
773 |
} |
774 |
} |
775 |
} |
776 |
if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
777 |
{ |
778 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
779 |
if (!endIDs.Contains(repID)) |
780 |
{ |
781 |
endIDs.Add(repID); |
782 |
if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
783 |
{ |
784 |
if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs)) |
785 |
{ |
786 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
787 |
graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()); |
788 |
return true; |
789 |
} |
790 |
} |
791 |
else if (targetRepID == repID) |
792 |
{ |
793 |
return true; |
794 |
} |
795 |
} |
796 |
} |
797 |
} |
798 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
799 |
{ |
800 |
if (connector.get_ItemStatus() != "Active") |
801 |
continue; |
802 |
|
803 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
804 |
{ |
805 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
806 |
if (!endIDs.Contains(repID)) |
807 |
{ |
808 |
endIDs.Add(repID); |
809 |
if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
810 |
{ |
811 |
if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs)) |
812 |
{ |
813 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
814 |
graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()); |
815 |
return true; |
816 |
} |
817 |
} |
818 |
else if (targetRepID == repID) |
819 |
{ |
820 |
return true; |
821 |
} |
822 |
} |
823 |
} |
824 |
if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
825 |
{ |
826 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
827 |
if (!endIDs.Contains(repID)) |
828 |
{ |
829 |
endIDs.Add(repID); |
830 |
if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
831 |
{ |
832 |
if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs)) |
833 |
{ |
834 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
835 |
graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()); |
836 |
return true; |
837 |
} |
838 |
} |
839 |
else if (targetRepID == repID) |
840 |
{ |
841 |
return true; |
842 |
} |
843 |
} |
844 |
} |
845 |
} |
846 |
|
847 |
return false; |
848 |
} |
849 |
#endregion |
850 |
|
851 |
#region SpecBreak |
852 |
private void btnSpecBreakRelocation_Click(object sender, EventArgs e) |
853 |
{ |
854 |
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
855 |
WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
856 |
application = wApp.RADApplication; |
857 |
|
858 |
int count = application.ActiveSelectSet.Count; |
859 |
int dependencyCount = 0; |
860 |
foreach (var item in application.ActiveSelectSet) |
861 |
if (item.GetType() == typeof(DependencyObject)) |
862 |
dependencyCount++; |
863 |
|
864 |
if (count > 0 && application.ActiveSelectSet[0].GetType() == typeof(DependencyObject)) |
865 |
{ |
866 |
MessageBox.Show("First selected item is DependencyObject!\r\nPlease move symbol", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
867 |
return; |
868 |
} |
869 |
|
870 |
if ((count == 3 || count == 4) && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d) && |
871 |
(dependencyCount == 2 || dependencyCount == 3)) |
872 |
{ |
873 |
Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
874 |
|
875 |
if (!symbol.DefinitionName.Contains(@"Design\Annotation\Graphics\")) |
876 |
{ |
877 |
MessageBox.Show("Select SpecBreak!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
878 |
return; |
879 |
} |
880 |
|
881 |
DependencyObject dependency1 = application.ActiveSelectSet[1] as DependencyObject; |
882 |
DependencyObject dependency2 = application.ActiveSelectSet[2] as DependencyObject; |
883 |
DependencyObject dependency3 = null; |
884 |
if (count == 4) |
885 |
dependency3 = application.ActiveSelectSet[3] as DependencyObject; |
886 |
|
887 |
application.ActiveSelectSet.RemoveAll(); |
888 |
double angle = symbol.Angle; |
889 |
if (symbol.GetTransform().HasReflection) |
890 |
angle += Math.PI; |
891 |
|
892 |
double degree = double.NaN; |
893 |
if (angle > -0.1 && angle < 0.1) |
894 |
degree = 0; |
895 |
else if (angle > 1.56 && angle < 1.58) |
896 |
degree = 90; |
897 |
else if (angle > 3.13 && angle < 3.15) |
898 |
degree = 180; |
899 |
else if (angle > 4.7 && angle < 4.72) |
900 |
degree = 270; |
901 |
else if (angle > 6.27 && angle < 6.29) |
902 |
degree = 0; |
903 |
else if (angle > -1.58 && angle < -1.56) |
904 |
degree = 270; |
905 |
else if (angle > -3.15 && angle < -3.13) |
906 |
degree = 180; |
907 |
else |
908 |
throw new Exception("Check Angle"); |
909 |
|
910 |
|
911 |
double originX, originY; |
912 |
symbol.GetOrigin(out originX, out originY); |
913 |
|
914 |
double crossX = 0; |
915 |
double crossY = 0; |
916 |
double topX = 0; |
917 |
double topY = 0; |
918 |
foreach (var item in symbol.DrawingObjects) |
919 |
{ |
920 |
Line2d line2d = item as Line2d; |
921 |
if (line2d != null) |
922 |
{ |
923 |
double x1, y1, x2, y2; |
924 |
line2d.GetStartPoint(out x1, out y1); |
925 |
line2d.GetEndPoint(out x2, out y2); |
926 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 0.1); |
927 |
|
928 |
if (slopeType == SlopeType.HORIZONTAL) |
929 |
{ |
930 |
if (crossY == 0) |
931 |
crossY = y1; |
932 |
else |
933 |
crossY = (crossY + y1) / 2; |
934 |
|
935 |
switch (degree) |
936 |
{ |
937 |
case 90: |
938 |
if (topX == 0) |
939 |
topX = Math.Min(x1, x2); |
940 |
else |
941 |
topX = Math.Min(topX, Math.Min(x1, x2)); |
942 |
break; |
943 |
case 270: |
944 |
if (topX == 0) |
945 |
topX = Math.Max(x1, x2); |
946 |
else |
947 |
topX = Math.Max(topX, Math.Max(x1, x2)); |
948 |
break; |
949 |
default: |
950 |
break; |
951 |
} |
952 |
} |
953 |
else if (slopeType == SlopeType.VERTICAL) |
954 |
{ |
955 |
if (crossX == 0) |
956 |
crossX = x1; |
957 |
else |
958 |
crossX = (crossX + x1) / 2; |
959 |
|
960 |
switch (degree) |
961 |
{ |
962 |
case 0: |
963 |
if (topY == 0) |
964 |
topY = Math.Max(y1, y2); |
965 |
else |
966 |
topY = Math.Max(topY, Math.Max(y1, y2)); |
967 |
break; |
968 |
case 180: |
969 |
if (topY == 0) |
970 |
topY = Math.Min(y1, y2); |
971 |
else |
972 |
topY = Math.Min(topY, Math.Min(y1, y2)); |
973 |
break; |
974 |
default: |
975 |
break; |
976 |
} |
977 |
} |
978 |
} |
979 |
} |
980 |
switch (degree) |
981 |
{ |
982 |
case 0: |
983 |
crossX = originX; |
984 |
topX = crossX; |
985 |
break; |
986 |
case 90: |
987 |
crossY = originY; |
988 |
topY = crossY; |
989 |
break; |
990 |
case 180: |
991 |
crossX = originX; |
992 |
topX = crossX; |
993 |
break; |
994 |
case 270: |
995 |
crossY = originY; |
996 |
topY = crossY; |
997 |
break; |
998 |
default: |
999 |
break; |
1000 |
} |
1001 |
|
1002 |
SpecBreakRelocation(degree, originX, originY, crossX, crossY, topX, topY, dependency1, dependency2, dependency3); |
1003 |
SetSpecBreakParameters(symbol, dependency1, dependency2, degree); |
1004 |
} |
1005 |
else |
1006 |
{ |
1007 |
MessageBox.Show("Check Rule!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
1008 |
} |
1009 |
} |
1010 |
private void SetSpecBreakParameters(Symbol2d symbol, DependencyObject dependency1, DependencyObject dependency2, double degree) |
1011 |
{ |
1012 |
bool mirror = symbol.GetTransform().HasReflection; |
1013 |
string repID = GetRepresentationId(symbol); |
1014 |
Placement placement = new Placement(); |
1015 |
LMADataSource dataSource = placement.PIDDataSource; |
1016 |
|
1017 |
LMSymbol _LMSymbol = dataSource.GetSymbol(repID); |
1018 |
if (_LMSymbol != null) |
1019 |
{ |
1020 |
double sX1, sY1, sX2, sY2, sOriginX, sOriginY; |
1021 |
symbol.Range(out sX1, out sY1, out sX2, out sY2); |
1022 |
symbol.GetOrigin(out sOriginX, out sOriginY); |
1023 |
double d1X1, d1Y1, d1X2, d1Y2, d2X1, d2Y1, d2X2, d2Y2; |
1024 |
FindRangeWithOutLineString2d(dependency1, out d1X1, out d1Y1, out d1X2, out d1Y2); |
1025 |
FindRangeWithOutLineString2d(dependency2, out d2X1, out d2Y1, out d2X2, out d2Y2); |
1026 |
|
1027 |
double left = 0, right = 0; |
1028 |
switch (degree) |
1029 |
{ |
1030 |
case 0: |
1031 |
if (!mirror) |
1032 |
{ |
1033 |
left = Math.Abs(d1X1 - sOriginX); |
1034 |
right = Math.Abs(d2X2 - sOriginX); |
1035 |
} |
1036 |
else |
1037 |
{ |
1038 |
right = Math.Abs(d1X1 - sOriginX); |
1039 |
left = Math.Abs(d2X2 - sOriginX); |
1040 |
} |
1041 |
break; |
1042 |
case 90: |
1043 |
if (!mirror) |
1044 |
{ |
1045 |
left = Math.Abs(d1Y1 - sOriginY); |
1046 |
right = Math.Abs(d2Y2 - sOriginY); |
1047 |
} |
1048 |
else |
1049 |
{ |
1050 |
right = Math.Abs(d1Y1 - sOriginY); |
1051 |
left = Math.Abs(d2Y2 - sOriginY); |
1052 |
} |
1053 |
break; |
1054 |
case 180: |
1055 |
if (!mirror) |
1056 |
{ |
1057 |
right = Math.Abs(d1X1 - sOriginX); |
1058 |
left = Math.Abs(d2X2 - sOriginX); |
1059 |
} |
1060 |
else |
1061 |
{ |
1062 |
left = Math.Abs(d1X1 - sOriginX); |
1063 |
right = Math.Abs(d2X2 - sOriginX); |
1064 |
|
1065 |
} |
1066 |
break; |
1067 |
case 270: |
1068 |
if (!mirror) |
1069 |
{ |
1070 |
right = Math.Abs(d1Y1 - sOriginY); |
1071 |
left = Math.Abs(d2Y2 - sOriginY); |
1072 |
} |
1073 |
else |
1074 |
{ |
1075 |
left = Math.Abs(d1Y1 - sOriginY); |
1076 |
right = Math.Abs(d2Y2 - sOriginY); |
1077 |
} |
1078 |
break; |
1079 |
default: |
1080 |
break; |
1081 |
} |
1082 |
|
1083 |
string[] array1 = new string[] { "", "Left", "Right" }; |
1084 |
string[] array2 = new string[] { "", left.ToString(), right.ToString() }; |
1085 |
placement.PIDApplyParameters(_LMSymbol.AsLMRepresentation(), array1, array2); |
1086 |
} |
1087 |
|
1088 |
ReleaseCOMObjects(_LMSymbol); |
1089 |
ReleaseCOMObjects(dataSource); |
1090 |
ReleaseCOMObjects(placement); |
1091 |
} |
1092 |
private void SpecBreakRelocation(double degree, double originX, double originY, double crossX, double crossY, double topX, double topY, DependencyObject dependency1, DependencyObject dependency2, DependencyObject dependency3) |
1093 |
{ |
1094 |
double d1X1, d1Y1, d1X2, d1Y2, d2X1, d2Y1, d2X2, d2Y2, d3X1 = 0, d3Y1 = 0, d3X2 = 0, d3Y2 = 0; |
1095 |
|
1096 |
FindRangeWithOutLineString2d(dependency1, out d1X1, out d1Y1, out d1X2, out d1Y2); |
1097 |
FindRangeWithOutLineString2d(dependency2, out d2X1, out d2Y1, out d2X2, out d2Y2); |
1098 |
if (dependency3 != null) |
1099 |
FindRangeWithOutLineString2dAndTextBox(dependency3, out d3X1, out d3Y1, out d3X2, out d3Y2); |
1100 |
|
1101 |
GridSetting gridSetting = GridSetting.GetInstance(); |
1102 |
double move = gridSetting.Length / 2; |
1103 |
switch (degree) |
1104 |
{ |
1105 |
case 0: |
1106 |
MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY); |
1107 |
MoveDependency(dependency2, d2X1, d2Y2, crossX + move, crossY); |
1108 |
if (dependency3 != null) |
1109 |
MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y1, topX, topY); |
1110 |
break; |
1111 |
case 90: |
1112 |
MoveDependency(dependency1, d1X1, d1Y2, crossX + move, crossY); |
1113 |
MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY); |
1114 |
if (dependency3 != null) |
1115 |
MoveDependency(dependency3, d3X1, (d3Y1 + d3Y2) / 2, originX, originY); |
1116 |
break; |
1117 |
case 180: |
1118 |
MoveDependency(dependency1, d1X2, d1Y1, crossX - move, crossY); |
1119 |
MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY); |
1120 |
if (dependency3 != null) |
1121 |
MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y2, topX, topY); |
1122 |
break; |
1123 |
case 270: |
1124 |
MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY); |
1125 |
MoveDependency(dependency2, d2X2, d2Y1, crossX - move, crossY); |
1126 |
if (dependency3 != null) |
1127 |
MoveDependency(dependency3, d3X2, (d3Y1 + d3Y2) / 2, originX, originY); |
1128 |
break; |
1129 |
default: |
1130 |
break; |
1131 |
} |
1132 |
} |
1133 |
private void MoveDependency(DependencyObject dependency, double xFrom, double yFrom, double xTo, double yTo) |
1134 |
{ |
1135 |
application.ActiveSelectSet.Add(dependency); |
1136 |
|
1137 |
Transform transform = dependency.GetTransform(); |
1138 |
transform.DefineByMove2d(xTo - xFrom, yTo - yFrom); |
1139 |
application.ActiveSelectSet.Transform(transform, false); |
1140 |
|
1141 |
application.ActiveSelectSet.RemoveAll(); |
1142 |
} |
1143 |
private string GetDrawingItemType(DependencyObject dependency) |
1144 |
{ |
1145 |
string result = string.Empty; |
1146 |
|
1147 |
foreach (var attributes in dependency.AttributeSets) |
1148 |
{ |
1149 |
foreach (var attribute in attributes) |
1150 |
{ |
1151 |
if (attribute.Name == "DrawingItemType") |
1152 |
return attribute.GetValue().ToString(); |
1153 |
} |
1154 |
} |
1155 |
|
1156 |
return result; |
1157 |
} |
1158 |
private void FindRangeWithOutLineString2d(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2) |
1159 |
{ |
1160 |
x1 = double.MaxValue; |
1161 |
y1 = double.MaxValue; |
1162 |
x2 = double.MinValue; |
1163 |
y2 = double.MinValue; |
1164 |
foreach (DrawingObjectBase item in dependency.DrawingObjects) |
1165 |
{ |
1166 |
if (item.GetType() != typeof(LineString2d)) |
1167 |
{ |
1168 |
double minX, minY, maxX, maxY; |
1169 |
item.Range(out minX, out minY, out maxX, out maxY); |
1170 |
if (x1 > minX) |
1171 |
x1 = minX; |
1172 |
if (y1 > minY) |
1173 |
y1 = minY; |
1174 |
if (x2 < maxX) |
1175 |
x2 = maxX; |
1176 |
if (y2 < maxY) |
1177 |
y2 = maxY; |
1178 |
} |
1179 |
} |
1180 |
|
1181 |
} |
1182 |
private void FindWidthHeightWidthOutLineString2d(DependencyObject dependency, out double width, out double height) |
1183 |
{ |
1184 |
width = 0; |
1185 |
height = 0; |
1186 |
|
1187 |
double x1 = double.MaxValue; |
1188 |
double y1 = double.MaxValue; |
1189 |
double x2 = double.MinValue; |
1190 |
double y2 = double.MinValue; |
1191 |
foreach (DrawingObjectBase item in dependency.DrawingObjects) |
1192 |
{ |
1193 |
if (item.GetType() != typeof(LineString2d)) |
1194 |
{ |
1195 |
double minX, minY, maxX, maxY; |
1196 |
item.Range(out minX, out minY, out maxX, out maxY); |
1197 |
if (x1 > minX) |
1198 |
x1 = minX; |
1199 |
if (y1 > minY) |
1200 |
y1 = minY; |
1201 |
if (x2 < maxX) |
1202 |
x2 = maxX; |
1203 |
if (y2 < maxY) |
1204 |
y2 = maxY; |
1205 |
} |
1206 |
} |
1207 |
|
1208 |
width = x2 - x1; |
1209 |
height = y2 - y1; |
1210 |
} |
1211 |
private void FindRangeWithOutLineString2dAndTextBox(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2) |
1212 |
{ |
1213 |
x1 = double.MaxValue; |
1214 |
y1 = double.MaxValue; |
1215 |
x2 = double.MinValue; |
1216 |
y2 = double.MinValue; |
1217 |
foreach (DrawingObjectBase item in dependency.DrawingObjects) |
1218 |
{ |
1219 |
if (item.GetType() != typeof(LineString2d) && item.GetType() != typeof(Ingr.RAD2D.TextBox)) |
1220 |
{ |
1221 |
double minX, minY, maxX, maxY; |
1222 |
item.Range(out minX, out minY, out maxX, out maxY); |
1223 |
if (x1 > minX) |
1224 |
x1 = minX; |
1225 |
if (y1 > minY) |
1226 |
y1 = minY; |
1227 |
if (x2 < maxX) |
1228 |
x2 = maxX; |
1229 |
if (y2 < maxY) |
1230 |
y2 = maxY; |
1231 |
} |
1232 |
} |
1233 |
|
1234 |
} |
1235 |
#endregion |
1236 |
|
1237 |
#region Hot Key |
1238 |
private void toggleSwitchSnapGrid_Toggled(object sender, EventArgs e) |
1239 |
{ |
1240 |
if (toggleSwitchSnapGrid.IsOn) |
1241 |
{ |
1242 |
RegisterHotKey(this.Handle, 0, (int)KeyModifier.Shift, Keys.A.GetHashCode()); |
1243 |
} |
1244 |
else |
1245 |
{ |
1246 |
UnregisterHotKey(this.Handle, 0); |
1247 |
} |
1248 |
} |
1249 |
private void toggleSwitchMoveSymbol_Toggled(object sender, EventArgs e) |
1250 |
{ |
1251 |
if (toggleSwitchMoveSymbol.IsOn) |
1252 |
{ |
1253 |
RegisterHotKey(this.Handle, 1, (int)KeyModifier.Shift, Keys.Left.GetHashCode()); |
1254 |
RegisterHotKey(this.Handle, 2, (int)KeyModifier.Shift, Keys.Up.GetHashCode()); |
1255 |
RegisterHotKey(this.Handle, 3, (int)KeyModifier.Shift, Keys.Right.GetHashCode()); |
1256 |
RegisterHotKey(this.Handle, 4, (int)KeyModifier.Shift, Keys.Down.GetHashCode()); |
1257 |
} |
1258 |
else |
1259 |
{ |
1260 |
UnregisterHotKey(this.Handle, 1); |
1261 |
UnregisterHotKey(this.Handle, 2); |
1262 |
UnregisterHotKey(this.Handle, 3); |
1263 |
UnregisterHotKey(this.Handle, 4); |
1264 |
} |
1265 |
} |
1266 |
public void ClearHotKey() |
1267 |
{ |
1268 |
if (toggleSwitchMoveSymbol.IsOn) |
1269 |
{ |
1270 |
UnregisterHotKey(this.Handle, 1); |
1271 |
UnregisterHotKey(this.Handle, 2); |
1272 |
UnregisterHotKey(this.Handle, 3); |
1273 |
UnregisterHotKey(this.Handle, 4); |
1274 |
} |
1275 |
if (toggleSwitchSnapGrid.IsOn) |
1276 |
{ |
1277 |
UnregisterHotKey(this.Handle, 0); |
1278 |
} |
1279 |
} |
1280 |
[System.Runtime.InteropServices.DllImport("user32.dll")] |
1281 |
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); |
1282 |
[System.Runtime.InteropServices.DllImport("user32.dll")] |
1283 |
private static extern bool UnregisterHotKey(IntPtr hWnd, int id); |
1284 |
enum KeyModifier |
1285 |
{ |
1286 |
None = 0, |
1287 |
Alt = 1, |
1288 |
Control = 2, |
1289 |
Shift = 4, |
1290 |
WinKey = 8 |
1291 |
} |
1292 |
protected override void WndProc(ref Message m) |
1293 |
{ |
1294 |
base.WndProc(ref m); |
1295 |
if (m.Msg == 0x0312) |
1296 |
{ |
1297 |
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); |
1298 |
KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF); |
1299 |
int id = m.WParam.ToInt32(); |
1300 |
switch (id) |
1301 |
{ |
1302 |
case 0: |
1303 |
application.RunCommand(CommandConstants.igcmdGridSnap); |
1304 |
break; |
1305 |
case 1: |
1306 |
MoveSymbol(Arrow.Left); |
1307 |
break; |
1308 |
case 2: |
1309 |
MoveSymbol(Arrow.Up); |
1310 |
break; |
1311 |
case 3: |
1312 |
MoveSymbol(Arrow.Right); |
1313 |
break; |
1314 |
case 4: |
1315 |
MoveSymbol(Arrow.Down); |
1316 |
break; |
1317 |
default: |
1318 |
break; |
1319 |
} |
1320 |
|
1321 |
} |
1322 |
|
1323 |
} |
1324 |
#endregion |
1325 |
|
1326 |
#region Move Symbol |
1327 |
enum Arrow |
1328 |
{ |
1329 |
Left, |
1330 |
Up, |
1331 |
Right, |
1332 |
Down |
1333 |
} |
1334 |
private void MoveSymbol(Arrow arrow) |
1335 |
{ |
1336 |
if (application.ActiveSelectSet.Count > 0) |
1337 |
{ |
1338 |
Placement placement = new Placement(); |
1339 |
LMADataSource dataSource = placement.PIDDataSource; |
1340 |
System.Collections.ObjectModel.Collection<DrawingObjectBase> originalDrawingObjectBases = new System.Collections.ObjectModel.Collection<DrawingObjectBase>(); |
1341 |
foreach (var item in application.ActiveSelectSet) |
1342 |
originalDrawingObjectBases.Add(item); |
1343 |
System.Collections.ObjectModel.Collection<DrawingObjectBase> drawingObjectBases = new System.Collections.ObjectModel.Collection<DrawingObjectBase>(); |
1344 |
Transform transform = null; |
1345 |
foreach (DrawingObjectBase drawingObject in application.ActiveSelectSet) |
1346 |
{ |
1347 |
if (drawingObject.GetType() == typeof(Symbol2d)) |
1348 |
{ |
1349 |
Symbol2d symbol2D = drawingObject as Symbol2d; |
1350 |
if (transform == null) |
1351 |
transform = symbol2D.GetTransform(); |
1352 |
drawingObjectBases.Add(symbol2D); |
1353 |
LMSymbol _LMSymbol = dataSource.GetSymbol(GetRepresentationId(symbol2D)); |
1354 |
if (_LMSymbol != null) |
1355 |
{ |
1356 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
1357 |
{ |
1358 |
if (connector.get_ItemStatus() == "Active") |
1359 |
{ |
1360 |
#region Zero Length And Branch |
1361 |
if (Convert.ToBoolean(connector.get_IsZeroLength())) |
1362 |
{ |
1363 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolID != _LMSymbol.Id) |
1364 |
{ |
1365 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1366 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1367 |
drawingObjectBases.Add(point2D); |
1368 |
} |
1369 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolID != _LMSymbol.Id) |
1370 |
{ |
1371 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1372 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1373 |
drawingObjectBases.Add(point2D); |
1374 |
} |
1375 |
} |
1376 |
#endregion |
1377 |
#region Not Zero Length And Branch And Vertical,Horizontal |
1378 |
else |
1379 |
{ |
1380 |
if (connector.ConnectItem1SymbolObject != null && |
1381 |
connector.ConnectItem1SymbolID != _LMSymbol.Id && |
1382 |
connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
1383 |
connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch" && |
1384 |
IsMovePoint2D(connector.ConnectItem1SymbolObject, connector, arrow)) |
1385 |
{ |
1386 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1387 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1388 |
drawingObjectBases.Add(point2D); |
1389 |
} |
1390 |
|
1391 |
else if (connector.ConnectItem2SymbolObject != null && |
1392 |
connector.ConnectItem2SymbolID != _LMSymbol.Id && |
1393 |
connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
1394 |
connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch" && |
1395 |
IsMovePoint2D(connector.ConnectItem2SymbolObject, connector, arrow)) |
1396 |
{ |
1397 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1398 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1399 |
drawingObjectBases.Add(point2D); |
1400 |
} |
1401 |
|
1402 |
} |
1403 |
#endregion |
1404 |
} |
1405 |
} |
1406 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
1407 |
{ |
1408 |
if (connector.get_ItemStatus() == "Active") |
1409 |
{ |
1410 |
#region Zero Length And Branch |
1411 |
if (Convert.ToBoolean(connector.get_IsZeroLength())) |
1412 |
{ |
1413 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolID != _LMSymbol.Id) |
1414 |
{ |
1415 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1416 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1417 |
drawingObjectBases.Add(point2D); |
1418 |
} |
1419 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolID != _LMSymbol.Id) |
1420 |
{ |
1421 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1422 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1423 |
drawingObjectBases.Add(point2D); |
1424 |
} |
1425 |
} |
1426 |
#endregion |
1427 |
#region Not Zero Length And Branch And Vertical,Horizontal |
1428 |
else |
1429 |
{ |
1430 |
if (connector.ConnectItem1SymbolObject != null && |
1431 |
connector.ConnectItem1SymbolID != _LMSymbol.Id && |
1432 |
connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
1433 |
connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch" && |
1434 |
IsMovePoint2D(connector.ConnectItem1SymbolObject, connector, arrow)) |
1435 |
{ |
1436 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1437 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1438 |
drawingObjectBases.Add(point2D); |
1439 |
} |
1440 |
|
1441 |
else if (connector.ConnectItem2SymbolObject != null && |
1442 |
connector.ConnectItem2SymbolID != _LMSymbol.Id && |
1443 |
connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
1444 |
connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch" && |
1445 |
IsMovePoint2D(connector.ConnectItem2SymbolObject, connector, arrow)) |
1446 |
{ |
1447 |
Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
1448 |
if (point2D != null && !drawingObjectBases.Contains(point2D)) |
1449 |
drawingObjectBases.Add(point2D); |
1450 |
} |
1451 |
|
1452 |
} |
1453 |
#endregion |
1454 |
} |
1455 |
} |
1456 |
} |
1457 |
ReleaseCOMObjects(_LMSymbol); |
1458 |
} |
1459 |
else if (drawingObject.GetType() == typeof(Point2d)) |
1460 |
{ |
1461 |
Point2d point2D = drawingObject as Point2d; |
1462 |
if (!drawingObjectBases.Contains(point2D)) |
1463 |
drawingObjectBases.Add(point2D); |
1464 |
} |
1465 |
} |
1466 |
|
1467 |
application.ActiveSelectSet.RemoveAll(); |
1468 |
if (drawingObjectBases.Count > 0 && transform != null) |
1469 |
{ |
1470 |
application.ActiveSelectSet.AddObjects(drawingObjectBases); |
1471 |
SetTransform(transform, arrow); |
1472 |
application.ActiveSelectSet.Transform(transform, false); |
1473 |
|
1474 |
application.ActiveSelectSet.RemoveAll(); |
1475 |
application.ActiveSelectSet.AddObjects(originalDrawingObjectBases); |
1476 |
} |
1477 |
|
1478 |
//foreach (DrawingObjectBaseEx item in drawingObjectBases) |
1479 |
// MoveSymbol(item, arrow); |
1480 |
|
1481 |
ReleaseCOMObjects(dataSource); |
1482 |
ReleaseCOMObjects(placement); |
1483 |
} |
1484 |
} |
1485 |
private bool IsMovePoint2D(LMSymbol branchSymbol, LMConnector targetConnector, Arrow arrow) |
1486 |
{ |
1487 |
bool result = false; |
1488 |
|
1489 |
DependencyObject dependency = application.ActiveDocument.ActiveSheet.DrawingObjects[targetConnector.get_GraphicOID().ToString()] as DependencyObject; |
1490 |
SlopeType mainSlope = GetLineSlopeType(dependency); |
1491 |
|
1492 |
if (mainSlope == SlopeType.HORIZONTAL || mainSlope == SlopeType.VERTICAL) |
1493 |
{ |
1494 |
List<SlopeType> types = new List<SlopeType>(); |
1495 |
|
1496 |
foreach (LMConnector connector in branchSymbol.Connect1Connectors) |
1497 |
{ |
1498 |
if (connector.get_ItemStatus() == "Active" && |
1499 |
connector.Id != targetConnector.Id && |
1500 |
!Convert.ToBoolean(connector.get_IsZeroLength())) |
1501 |
types.Add(GetLineSlopeType(application.ActiveDocument.ActiveSheet.DrawingObjects[connector.get_GraphicOID().ToString()] as DependencyObject)); |
1502 |
} |
1503 |
|
1504 |
foreach (LMConnector connector in branchSymbol.Connect2Connectors) |
1505 |
{ |
1506 |
if (connector.get_ItemStatus() == "Active" && |
1507 |
connector.Id != targetConnector.Id && |
1508 |
!Convert.ToBoolean(connector.get_IsZeroLength())) |
1509 |
types.Add(GetLineSlopeType(application.ActiveDocument.ActiveSheet.DrawingObjects[connector.get_GraphicOID().ToString()] as DependencyObject)); |
1510 |
} |
1511 |
|
1512 |
foreach (var type in types) |
1513 |
{ |
1514 |
if (type == mainSlope) |
1515 |
{ |
1516 |
if (type == SlopeType.HORIZONTAL && (arrow == Arrow.Up || arrow == Arrow.Down)) |
1517 |
result = true; |
1518 |
else if (type == SlopeType.VERTICAL && (arrow == Arrow.Left || arrow == Arrow.Right)) |
1519 |
result = true; |
1520 |
else |
1521 |
{ |
1522 |
result = false; |
1523 |
break; |
1524 |
} |
1525 |
} |
1526 |
else |
1527 |
result = true; |
1528 |
} |
1529 |
|
1530 |
if (result) |
1531 |
{ |
1532 |
if ((arrow == Arrow.Down || arrow == Arrow.Up) && mainSlope == SlopeType.VERTICAL) |
1533 |
result = false; |
1534 |
else if ((arrow == Arrow.Left || arrow == Arrow.Right) && mainSlope == SlopeType.HORIZONTAL) |
1535 |
result = false; |
1536 |
} |
1537 |
} |
1538 |
|
1539 |
return result; |
1540 |
} |
1541 |
private SlopeType GetLineSlopeType(DependencyObject dependency) |
1542 |
{ |
1543 |
if (dependency != null && dependency.DrawingObjects.Count == 1 && dependency.DrawingObjects[0].GetType() == typeof(LineString2d)) |
1544 |
{ |
1545 |
LineString2d line = dependency.DrawingObjects[0] as LineString2d; |
1546 |
double x1 = 0, y1 = 0, x2 = double.MaxValue, y2 = double.MaxValue; |
1547 |
for (int i = 0; i < line.KeyPointCount; i++) |
1548 |
{ |
1549 |
double x, y, z; |
1550 |
KeyPointType keyPointType; |
1551 |
HandleType handleType; |
1552 |
line.GetKeyPoint(i, out x, out y, out z, out keyPointType, out handleType); |
1553 |
if (keyPointType == KeyPointType.igKeyPointStart) |
1554 |
{ |
1555 |
x1 = x; |
1556 |
y1 = y; |
1557 |
} |
1558 |
else if (keyPointType == KeyPointType.igKeyPointEnd) |
1559 |
{ |
1560 |
x2 = x; |
1561 |
y2 = y; |
1562 |
} |
1563 |
} |
1564 |
return SPPIDUtil.CalcSlope(x1, y1, x2, y2, 0.5); |
1565 |
} |
1566 |
|
1567 |
return SlopeType.None; |
1568 |
} |
1569 |
private void MoveSymbol(DrawingObjectBaseEx drawingObjectBase, Arrow arrow) |
1570 |
{ |
1571 |
if (drawingObjectBase == null) |
1572 |
return; |
1573 |
|
1574 |
GridSetting gridSetting = GridSetting.GetInstance(); |
1575 |
switch (arrow) |
1576 |
{ |
1577 |
case Arrow.Left: |
1578 |
drawingObjectBase.Move(0, 0, -gridSetting.Length, 0); |
1579 |
break; |
1580 |
case Arrow.Up: |
1581 |
drawingObjectBase.Move(0, 0, 0, gridSetting.Length); |
1582 |
break; |
1583 |
case Arrow.Right: |
1584 |
drawingObjectBase.Move(0, 0, gridSetting.Length, 0); |
1585 |
break; |
1586 |
case Arrow.Down: |
1587 |
drawingObjectBase.Move(0, 0, 0, -gridSetting.Length); |
1588 |
break; |
1589 |
default: |
1590 |
break; |
1591 |
} |
1592 |
} |
1593 |
private void SetTransform(Transform transform, Arrow arrow) |
1594 |
{ |
1595 |
if (transform == null) |
1596 |
return; |
1597 |
|
1598 |
GridSetting gridSetting = GridSetting.GetInstance(); |
1599 |
switch (arrow) |
1600 |
{ |
1601 |
case Arrow.Left: |
1602 |
transform.DefineByMove2d(-gridSetting.Length, 0); |
1603 |
break; |
1604 |
case Arrow.Up: |
1605 |
transform.DefineByMove2d(0, gridSetting.Length); |
1606 |
break; |
1607 |
case Arrow.Right: |
1608 |
transform.DefineByMove2d(gridSetting.Length, 0); |
1609 |
break; |
1610 |
case Arrow.Down: |
1611 |
transform.DefineByMove2d(0, -gridSetting.Length); |
1612 |
break; |
1613 |
default: |
1614 |
break; |
1615 |
} |
1616 |
} |
1617 |
#endregion |
1618 |
|
1619 |
#endregion |
1620 |
|
1621 |
|
1622 |
#region TEST |
1623 |
private void simpleButton1_Click(object sender, EventArgs e) |
1624 |
{ |
1625 |
//SPPIDUtil.test(); |
1626 |
if (application.ActiveSelectSet.Count == 0) |
1627 |
return; |
1628 |
|
1629 |
foreach (DrawingObjectBase item in application.ActiveSelectSet) |
1630 |
{ |
1631 |
DependencyObject dependency = item as DependencyObject; |
1632 |
if (dependency != null) |
1633 |
{ |
1634 |
foreach (var attributes in dependency.AttributeSets) |
1635 |
{ |
1636 |
foreach (var attribute in attributes) |
1637 |
{ |
1638 |
string name = attribute.Name; |
1639 |
object value = attribute.GetValue(); |
1640 |
if (name == "ModelID") |
1641 |
{ |
1642 |
Placement placement = new Placement(); |
1643 |
LMADataSource dataSource = placement.PIDDataSource; |
1644 |
LMPipeRun pipeRun = dataSource.GetPipeRun(value); |
1645 |
string attrName = "PlantGroup.Name"; |
1646 |
LMAAttribute lMAAttribute = pipeRun.Attributes[attrName]; |
1647 |
if (lMAAttribute != null) |
1648 |
{ |
1649 |
lMAAttribute.set_Value("25"); |
1650 |
pipeRun.Commit(); |
1651 |
} |
1652 |
else |
1653 |
{ |
1654 |
|
1655 |
} |
1656 |
} |
1657 |
} |
1658 |
} |
1659 |
} |
1660 |
} |
1661 |
|
1662 |
|
1663 |
|
1664 |
//string a = "0A509911F33441A2AF088BFBA78B770D"; |
1665 |
//LMLabelPersist label = dataSource.GetLabelPersist(a); |
1666 |
//label.set_XCoordinate(0.4); |
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
//LMOptionSettings |
1672 |
|
1673 |
|
1674 |
//LMAFilter filter = new LMAFilter(); |
1675 |
//LMACriterion criterion = new LMACriterion(); |
1676 |
//filter.ItemType = "Relationship"; |
1677 |
//criterion.SourceAttributeName = "SP_DRAWINGID"; |
1678 |
//criterion.Operator = "="; |
1679 |
//criterion.set_ValueAttribute(drawingID); |
1680 |
//filter.get_Criteria().Add(criterion); |
1681 |
|
1682 |
//LMRelationships relationships = new LMRelationships(); |
1683 |
//relationships.Collect(dataSource, Filter: filter); |
1684 |
|
1685 |
} |
1686 |
private void AutoJoinPipeRun() |
1687 |
{ |
1688 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
1689 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
1690 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
1691 |
|
1692 |
string modelItemId = null; |
1693 |
List<double[]> vertices = new List<double[]>(); |
1694 |
if (radApp.ActiveSelectSet.Count == 0) |
1695 |
{ |
1696 |
return; |
1697 |
} |
1698 |
dynamic OID = radApp.ActiveSelectSet[0].Key(); |
1699 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1700 |
foreach (var attributes in drawingObject.AttributeSets) |
1701 |
{ |
1702 |
foreach (var attribute in attributes) |
1703 |
{ |
1704 |
if (attribute.Name == "ModelID") |
1705 |
modelItemId = attribute.GetValue().ToString(); |
1706 |
} |
1707 |
} |
1708 |
radApp.ActiveSelectSet.RemoveAll(); |
1709 |
|
1710 |
} |
1711 |
#endregion |
1712 |
|
1713 |
|
1714 |
[DllImport("user32.dll")] |
1715 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
1716 |
|
1717 |
[DllImport("user32.dll", SetLastError = true)] |
1718 |
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
1719 |
|
1720 |
private void btnLinkOPCTest_Click(object sender, EventArgs e) |
1721 |
{ |
1722 |
Placement placement = new Placement(); |
1723 |
LMADataSource dataSource = placement.PIDDataSource; |
1724 |
|
1725 |
LMAFilter filter = new LMAFilter(); |
1726 |
filter.ItemType = "REPRESENTATION"; |
1727 |
|
1728 |
LMACriterion criterion = new LMACriterion(); |
1729 |
criterion.SourceAttributeName = "REPRESENTATIONTYPE"; |
1730 |
criterion.Operator = "="; |
1731 |
criterion.set_ValueAttribute("39"); |
1732 |
filter.get_Criteria().Add(criterion); |
1733 |
|
1734 |
LMRepresentations representations = new LMRepresentations(); |
1735 |
representations.Collect(dataSource, Filter: filter); |
1736 |
|
1737 |
foreach (LMRepresentation representation in representations) |
1738 |
{ |
1739 |
if (representation.get_ItemStatus() == "Active" && representation.DrawingID != "0") |
1740 |
{ |
1741 |
LMOPC opc = dataSource.GetOPC(representation.ModelItemID); |
1742 |
LMOPC pairOPC = opc.pairedWithOPCObject; |
1743 |
bool isPaired = false; |
1744 |
foreach (LMRepresentation rep in pairOPC.Representations) |
1745 |
if (rep.DrawingID != "0") |
1746 |
isPaired = true; |
1747 |
|
1748 |
if (!isPaired) |
1749 |
{ |
1750 |
LMSymbol newOPC = placement.PIDPlaceSymbol(representation.get_FileName().ToString(), 0, 0, ExistingItem: pairOPC.AsLMAItem()); |
1751 |
ReleaseCOMObjects(newOPC); |
1752 |
} |
1753 |
|
1754 |
ReleaseCOMObjects(opc); |
1755 |
ReleaseCOMObjects(pairOPC); |
1756 |
|
1757 |
} |
1758 |
} |
1759 |
|
1760 |
ReleaseCOMObjects(representations); |
1761 |
ReleaseCOMObjects(criterion); |
1762 |
ReleaseCOMObjects(filter); |
1763 |
ReleaseCOMObjects(dataSource); |
1764 |
ReleaseCOMObjects(placement); |
1765 |
} |
1766 |
|
1767 |
#region Test For SECL |
1768 |
private void btnAutoBreakTest_Click(object sender, EventArgs e) |
1769 |
{ |
1770 |
|
1771 |
} |
1772 |
|
1773 |
private void FindRun(LMSymbol startSymbol, LMSymbol endSymbol, string model) |
1774 |
{ |
1775 |
Placement placement = new Placement(); |
1776 |
LMADataSource dataSource = placement.PIDDataSource; |
1777 |
List<string> endRepID = new List<string>(); |
1778 |
List<string> findRepID = new List<string>(); |
1779 |
endRepID.Add(startSymbol.AsLMRepresentation().Id); |
1780 |
findRepID.Add(startSymbol.AsLMRepresentation().Id); |
1781 |
bool end = false; |
1782 |
LoopRunTest(startSymbol.AsLMRepresentation(), endRepID, endSymbol.AsLMRepresentation().Id, ref end, findRepID); |
1783 |
|
1784 |
|
1785 |
//findRepID.Reverse(); |
1786 |
for (int i = 0; i < findRepID.Count; i++) |
1787 |
{ |
1788 |
string repID = findRepID[i]; |
1789 |
|
1790 |
LMRepresentation representation = dataSource.GetRepresentation(repID); |
1791 |
if (representation != null) |
1792 |
{ |
1793 |
string fileName = representation.get_FileName().ToString(); |
1794 |
if (fileName.Contains(@"\Piping\Valves")) |
1795 |
{ |
1796 |
LMModelItem modelItem = representation.ModelItemObject; |
1797 |
LMSymbol tarsym = dataSource.GetSymbol(representation.Id); |
1798 |
LMRepresentation prevRep = dataSource.GetRepresentation(findRepID[i - 1]); |
1799 |
LMConnector removeConnector = dataSource.GetConnector(prevRep.Id); |
1800 |
|
1801 |
List<double[]> vertices = GetConnectorVertices(removeConnector); |
1802 |
|
1803 |
ZoomObjectByGraphicOID(vertices[0][0], vertices[0][1]); |
1804 |
Array array = new double[] { 0, vertices[0][0], vertices[0][1] }; |
1805 |
LMLabelPersist _LmLabelPersist = placement.PIDPlaceLabel(model, ref array, LabeledItem: removeConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1806 |
if (_LmLabelPersist == null) |
1807 |
{ |
1808 |
if (removeConnector.get_ItemStatus() == "Active") |
1809 |
{ |
1810 |
LMConnector newConnector = ReModelingLine(removeConnector, removeConnector.ConnectItem1SymbolObject, removeConnector.ConnectItem2SymbolObject, true, false); |
1811 |
FindRun(startSymbol, endSymbol, model); |
1812 |
} |
1813 |
} |
1814 |
|
1815 |
|
1816 |
|
1817 |
//string dd = startSymbol.ModelItemObject.Attributes["SteamOutTemperature"].get_Value(); |
1818 |
//string dd2 = endSymbol.ModelItemObject.Attributes["SteamOutTemperature"].get_Value(); |
1819 |
//double value1 = Convert.ToDouble(dd.Split(new char[] { ' ' })[0]); |
1820 |
//double value2 = Convert.ToDouble(dd2.Split(new char[] { ' ' })[0]); |
1821 |
|
1822 |
//if (value1 > value2) |
1823 |
//{ |
1824 |
// LMRepresentation prevRep = dataSource.GetRepresentation(endRepID[i + 1]); |
1825 |
// placement.PIDRemovePlacement(prevRep); |
1826 |
//} |
1827 |
//else |
1828 |
//{ |
1829 |
// LMRepresentation prevRep = dataSource.GetRepresentation(endRepID[i - 1]); |
1830 |
// placement.PIDRemovePlacement(prevRep); |
1831 |
//} |
1832 |
|
1833 |
//LMRepresentation prevRep = dataSource.GetRepresentation(endRepID[i - 1]); |
1834 |
//placement.PIDRemovePlacement(prevRep); |
1835 |
|
1836 |
|
1837 |
//application.ActiveDocument.Save(); |
1838 |
//ReleaseCOMObjects(modelItem); |
1839 |
break; |
1840 |
} |
1841 |
} |
1842 |
|
1843 |
ReleaseCOMObjects(representation); |
1844 |
} |
1845 |
} |
1846 |
private LMConnector ReModelingLine(LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd) |
1847 |
{ |
1848 |
Placement _placement = new Placement(); |
1849 |
LMADataSource dataSource = _placement.PIDDataSource; |
1850 |
|
1851 |
string symbolPath = string.Empty; |
1852 |
#region get symbol path |
1853 |
LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID); |
1854 |
symbolPath = GetSPPIDFileName(modelItem); |
1855 |
ReleaseCOMObjects(modelItem); |
1856 |
#endregion |
1857 |
bool diagonal = false; |
1858 |
_LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath); |
1859 |
LMConnector newConnector = null; |
1860 |
dynamic OID = prevLMConnector.get_GraphicOID().ToString(); |
1861 |
DependencyObject drawingObject = application.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1862 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1863 |
int verticesCount = lineStringGeometry.VertexCount; |
1864 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
1865 |
|
1866 |
List<double[]> vertices = new List<double[]>(); |
1867 |
for (int i = 1; i <= verticesCount; i++) |
1868 |
{ |
1869 |
double x = 0; |
1870 |
double y = 0; |
1871 |
lineStringGeometry.GetVertex(i, ref x, ref y); |
1872 |
vertices.Add(new double[] { x, y }); |
1873 |
} |
1874 |
|
1875 |
for (int i = 0; i < vertices.Count; i++) |
1876 |
{ |
1877 |
double[] points = vertices[i]; |
1878 |
// 시작 심볼이 있고 첫번째 좌표일 때 |
1879 |
if (startSymbol != null && i == 0) |
1880 |
{ |
1881 |
if (bStart) |
1882 |
{ |
1883 |
SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]); |
1884 |
if (slopeType == SlopeType.HORIZONTAL) |
1885 |
placeRunInputs.AddPoint(points[0], -0.1); |
1886 |
else if (slopeType == SlopeType.VERTICAL) |
1887 |
placeRunInputs.AddPoint(-0.1, points[1]); |
1888 |
else |
1889 |
placeRunInputs.AddPoint(points[0], -0.1); |
1890 |
|
1891 |
placeRunInputs.AddPoint(points[0], points[1]); |
1892 |
} |
1893 |
else |
1894 |
{ |
1895 |
placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1], diagonal); |
1896 |
} |
1897 |
} |
1898 |
// 마지막 심볼이 있고 마지막 좌표일 때 |
1899 |
else if (endSymbol != null && i == vertices.Count - 1) |
1900 |
{ |
1901 |
if (bEnd) |
1902 |
{ |
1903 |
placeRunInputs.AddPoint(points[0], points[1]); |
1904 |
|
1905 |
SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]); |
1906 |
if (slopeType == SlopeType.HORIZONTAL) |
1907 |
placeRunInputs.AddPoint(points[0], -0.1); |
1908 |
else if (slopeType == SlopeType.VERTICAL) |
1909 |
placeRunInputs.AddPoint(-0.1, points[1]); |
1910 |
else |
1911 |
placeRunInputs.AddPoint(points[0], -0.1); |
1912 |
} |
1913 |
else |
1914 |
{ |
1915 |
placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1], diagonal); |
1916 |
} |
1917 |
} |
1918 |
// 첫번째이며 시작 심볼이 아니고 Connecotr일 경우 |
1919 |
else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null) |
1920 |
placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1], diagonal); |
1921 |
// 마지막이며 마지막 심볼이 아니고 Connecotr일 경우 |
1922 |
else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null) |
1923 |
placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1], diagonal); |
1924 |
else |
1925 |
placeRunInputs.AddPoint(points[0], points[1]); |
1926 |
} |
1927 |
|
1928 |
_placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation()); |
1929 |
Thread.Sleep(1000); |
1930 |
newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1931 |
|
1932 |
ReleaseCOMObjects(placeRunInputs); |
1933 |
ReleaseCOMObjects(_LMAItem); |
1934 |
ReleaseCOMObjects(modelItem); |
1935 |
|
1936 |
if (newConnector != null) |
1937 |
{ |
1938 |
newConnector.Commit(); |
1939 |
if (startSymbol != null && bStart) |
1940 |
{ |
1941 |
_LMAItem = _placement.PIDCreateItem(symbolPath); |
1942 |
placeRunInputs = new PlaceRunInputs(); |
1943 |
placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]); |
1944 |
placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]); |
1945 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1946 |
if (_LMConnector != null) |
1947 |
{ |
1948 |
_LMConnector.Commit(); |
1949 |
newConnector = RemoveConnectorForReModelingLine(newConnector); |
1950 |
ReleaseCOMObjects(_LMConnector); |
1951 |
} |
1952 |
ReleaseCOMObjects(placeRunInputs); |
1953 |
ReleaseCOMObjects(_LMAItem); |
1954 |
} |
1955 |
|
1956 |
if (endSymbol != null && bEnd) |
1957 |
{ |
1958 |
if (startSymbol != null) |
1959 |
{ |
1960 |
Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID); |
1961 |
newConnector = dicVertices.First().Key; |
1962 |
} |
1963 |
|
1964 |
_LMAItem = _placement.PIDCreateItem(symbolPath); |
1965 |
placeRunInputs = new PlaceRunInputs(); |
1966 |
placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]); |
1967 |
placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]); |
1968 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1969 |
if (_LMConnector != null) |
1970 |
{ |
1971 |
_LMConnector.Commit(); |
1972 |
newConnector = RemoveConnectorForReModelingLine(newConnector); |
1973 |
ReleaseCOMObjects(_LMConnector); |
1974 |
} |
1975 |
ReleaseCOMObjects(placeRunInputs); |
1976 |
ReleaseCOMObjects(_LMAItem); |
1977 |
} |
1978 |
|
1979 |
|
1980 |
} |
1981 |
ReleaseCOMObjects(modelItem); |
1982 |
return newConnector; |
1983 |
|
1984 |
} |
1985 |
|
1986 |
private LMConnector RemoveConnectorForReModelingLine(LMConnector connector) |
1987 |
{ |
1988 |
Placement _placement = new Placement(); |
1989 |
LMADataSource dataSource = _placement.PIDDataSource; |
1990 |
|
1991 |
Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID); |
1992 |
foreach (var item in dicVertices) |
1993 |
{ |
1994 |
if (item.Value.Count == 2) |
1995 |
{ |
1996 |
bool result = false; |
1997 |
foreach (var point in item.Value) |
1998 |
{ |
1999 |
if (point[0] < 0 || point[1] < 0) |
2000 |
{ |
2001 |
result = true; |
2002 |
_placement.PIDRemovePlacement(item.Key.AsLMRepresentation()); |
2003 |
break; |
2004 |
} |
2005 |
} |
2006 |
|
2007 |
if (result) |
2008 |
break; |
2009 |
} |
2010 |
} |
2011 |
|
2012 |
LMConnector result111 = null; |
2013 |
foreach (var item in dicVertices) |
2014 |
{ |
2015 |
if (item.Key.get_ItemStatus() == "Active") |
2016 |
result111 = item.Key; |
2017 |
else |
2018 |
ReleaseCOMObjects(item.Key); |
2019 |
} |
2020 |
|
2021 |
return result111; |
2022 |
} |
2023 |
|
2024 |
private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId, bool ContainZeroLength = true) |
2025 |
{ |
2026 |
Placement _placement = new Placement(); |
2027 |
LMADataSource dataSource = _placement.PIDDataSource; |
2028 |
|
2029 |
Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
2030 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
2031 |
|
2032 |
if (modelItem != null) |
2033 |
{ |
2034 |
foreach (LMRepresentation rep in modelItem.Representations) |
2035 |
{ |
2036 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
2037 |
{ |
2038 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
2039 |
if (!ContainZeroLength && Convert.ToBoolean(_LMConnector.get_IsZeroLength())) |
2040 |
{ |
2041 |
ReleaseCOMObjects(_LMConnector); |
2042 |
_LMConnector = null; |
2043 |
continue; |
2044 |
} |
2045 |
connectorVertices.Add(_LMConnector, new List<double[]>()); |
2046 |
dynamic OID = rep.get_GraphicOID().ToString(); |
2047 |
DependencyObject drawingObject = application.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
2048 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
2049 |
int verticesCount = lineStringGeometry.VertexCount; |
2050 |
double[] vertices = null; |
2051 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
2052 |
for (int i = 0; i < verticesCount; i++) |
2053 |
{ |
2054 |
double x = 0; |
2055 |
double y = 0; |
2056 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
2057 |
connectorVertices[_LMConnector].Add(new double[] { x, y }); |
2058 |
} |
2059 |
} |
2060 |
} |
2061 |
|
2062 |
ReleaseCOMObjects(modelItem); |
2063 |
} |
2064 |
|
2065 |
return connectorVertices; |
2066 |
} |
2067 |
private string GetSPPIDFileName(LMModelItem modelItem) |
2068 |
{ |
2069 |
string symbolPath = null; |
2070 |
foreach (LMRepresentation rep in modelItem.Representations) |
2071 |
{ |
2072 |
if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
2073 |
{ |
2074 |
symbolPath = rep.get_FileName(); |
2075 |
break; |
2076 |
} |
2077 |
} |
2078 |
return symbolPath; |
2079 |
} |
2080 |
private string GetSPPIDFileName(string modelItemId) |
2081 |
{ |
2082 |
Placement placement = new Placement(); |
2083 |
LMADataSource dataSource = placement.PIDDataSource; |
2084 |
|
2085 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
2086 |
string symbolPath = null; |
2087 |
foreach (LMRepresentation rep in modelItem.Representations) |
2088 |
{ |
2089 |
if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
2090 |
{ |
2091 |
symbolPath = rep.get_FileName(); |
2092 |
break; |
2093 |
} |
2094 |
} |
2095 |
ReleaseCOMObjects(modelItem); |
2096 |
return symbolPath; |
2097 |
} |
2098 |
private List<double[]> GetConnectorVertices(LMConnector connector) |
2099 |
{ |
2100 |
List<double[]> vertices = new List<double[]>(); |
2101 |
if (connector != null) |
2102 |
{ |
2103 |
dynamic OID = connector.get_GraphicOID().ToString(); |
2104 |
DependencyObject drawingObject = application.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
2105 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
2106 |
int verticesCount = lineStringGeometry.VertexCount; |
2107 |
double[] value = null; |
2108 |
lineStringGeometry.GetVertices(ref verticesCount, ref value); |
2109 |
for (int i = 0; i < verticesCount; i++) |
2110 |
{ |
2111 |
double x = 0; |
2112 |
double y = 0; |
2113 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
2114 |
vertices.Add(new double[] { x, y }); |
2115 |
} |
2116 |
} |
2117 |
return vertices; |
2118 |
} |
2119 |
private void LoopRunTest(LMRepresentation rep, List<string> endRepID, string endID,ref bool end, List<string> findRepID) |
2120 |
{ |
2121 |
if (!end) |
2122 |
{ |
2123 |
foreach (LMRelationship item in rep.Relation1Relationships) |
2124 |
{ |
2125 |
if (end) |
2126 |
break; |
2127 |
|
2128 |
if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID) && item.Item1RepresentationObject.get_ItemStatus() == "Active" && |
2129 |
(item.Item1RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item1RepresentationObject.get_RepresentationClass() == "Connector")) |
2130 |
{ |
2131 |
if (endID != item.Item1RepresentationID) |
2132 |
{ |
2133 |
endRepID.Add(item.Item1RepresentationID); |
2134 |
LoopRunTest(item.Item1RepresentationObject, endRepID, endID, ref end, findRepID); |
2135 |
if (end) |
2136 |
findRepID.Add(item.Item1RepresentationID); |
2137 |
} |
2138 |
else |
2139 |
end = true; |
2140 |
} |
2141 |
|
2142 |
if (end) |
2143 |
break; |
2144 |
|
2145 |
if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID) && item.Item2RepresentationObject.get_ItemStatus() == "Active" && |
2146 |
(item.Item2RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item2RepresentationObject.get_RepresentationClass() == "Connector")) |
2147 |
{ |
2148 |
if (endID != item.Item2RepresentationID) |
2149 |
{ |
2150 |
endRepID.Add(item.Item2RepresentationID); |
2151 |
LoopRunTest(item.Item2RepresentationObject, endRepID, endID, ref end, findRepID); |
2152 |
if (end) |
2153 |
findRepID.Add(item.Item2RepresentationID); |
2154 |
} |
2155 |
else |
2156 |
end = true; |
2157 |
} |
2158 |
} |
2159 |
} |
2160 |
|
2161 |
if (!end) |
2162 |
{ |
2163 |
foreach (LMRelationship item in rep.Relation2Relationships) |
2164 |
{ |
2165 |
if (end) |
2166 |
break; |
2167 |
|
2168 |
if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID) && item.Item1RepresentationObject.get_ItemStatus() == "Active" && |
2169 |
(item.Item1RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item1RepresentationObject.get_RepresentationClass() == "Connector")) |
2170 |
{ |
2171 |
if (endID != item.Item1RepresentationID) |
2172 |
{ |
2173 |
endRepID.Add(item.Item1RepresentationID); |
2174 |
LoopRunTest(item.Item1RepresentationObject, endRepID, endID, ref end, findRepID); |
2175 |
if (end) |
2176 |
findRepID.Add(item.Item1RepresentationID); |
2177 |
} |
2178 |
else |
2179 |
end = true; |
2180 |
} |
2181 |
|
2182 |
if (end) |
2183 |
break; |
2184 |
|
2185 |
if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID) && item.Item2RepresentationObject.get_ItemStatus() == "Active" && |
2186 |
(item.Item2RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item2RepresentationObject.get_RepresentationClass() == "Connector")) |
2187 |
{ |
2188 |
if (endID != item.Item2RepresentationID) |
2189 |
{ |
2190 |
endRepID.Add(item.Item2RepresentationID); |
2191 |
LoopRunTest(item.Item2RepresentationObject, endRepID, endID, ref end, findRepID); |
2192 |
if (end) |
2193 |
findRepID.Add(item.Item2RepresentationID); |
2194 |
} |
2195 |
else |
2196 |
end = true; |
2197 |
} |
2198 |
} |
2199 |
} |
2200 |
} |
2201 |
|
2202 |
private void btnOPC_Click(object sender, EventArgs e) |
2203 |
{ |
2204 |
Placement _placement; |
2205 |
LMADataSource dataSource; |
2206 |
_placement = new Placement(); |
2207 |
dataSource = _placement.PIDDataSource; |
2208 |
|
2209 |
OPCFlowDirection(); |
2210 |
|
2211 |
void OPCFlowDirection() |
2212 |
{ |
2213 |
//current LMDrawing 가져오기 |
2214 |
LMAFilter filter = new LMAFilter(); |
2215 |
LMACriterion criterion = new LMACriterion(); |
2216 |
filter.ItemType = "Drawing"; |
2217 |
criterion.SourceAttributeName = "Name"; |
2218 |
criterion.Operator = "="; |
2219 |
criterion.set_ValueAttribute(application.ActiveDocument.Name.Replace(".pid", "")); |
2220 |
filter.get_Criteria().Add(criterion); |
2221 |
|
2222 |
LMDrawings drawings = new LMDrawings(); |
2223 |
drawings.Collect(dataSource, Filter: filter); |
2224 |
|
2225 |
// Input Drawing Attribute |
2226 |
LMDrawing drawing = ((dynamic)drawings).Nth(1); |
2227 |
|
2228 |
LMAFilter filter2 = new LMAFilter(); |
2229 |
filter2.ItemType = "REPRESENTATION"; |
2230 |
|
2231 |
LMACriterion criterion2 = new LMACriterion(); |
2232 |
criterion2.SourceAttributeName = "REPRESENTATIONTYPE"; |
2233 |
criterion2.Operator = "="; |
2234 |
criterion2.set_ValueAttribute("39"); |
2235 |
filter2.get_Criteria().Add(criterion2); |
2236 |
|
2237 |
LMRepresentations representations = new LMRepresentations(); |
2238 |
representations.Collect(dataSource, Filter: filter2); |
2239 |
|
2240 |
foreach (LMRepresentation representation in representations) |
2241 |
{ |
2242 |
if (representation.DrawingID == drawing.Id) |
2243 |
{ |
2244 |
RunOPC(representation); |
2245 |
} |
2246 |
} |
2247 |
|
2248 |
ReleaseCOMObjects(filter); |
2249 |
ReleaseCOMObjects(filter2); |
2250 |
ReleaseCOMObjects(criterion); |
2251 |
ReleaseCOMObjects(criterion2); |
2252 |
ReleaseCOMObjects(drawing); |
2253 |
ReleaseCOMObjects(drawings); |
2254 |
ReleaseCOMObjects(representations); |
2255 |
} |
2256 |
|
2257 |
void RunOPC(LMRepresentation representation) |
2258 |
{ |
2259 |
LMSymbol symbol = dataSource.GetSymbol(representation.Id); |
2260 |
List<string> endRepId = new List<string>(); |
2261 |
endRepId.Add(symbol.AsLMRepresentation().Id); |
2262 |
LoopSymbol(symbol, endRepId); |
2263 |
|
2264 |
ReleaseCOMObjects(symbol); |
2265 |
|
2266 |
void LoopSymbol(LMSymbol loopSymbol, List<string> endRepID) |
2267 |
{ |
2268 |
foreach (LMRelationship item in loopSymbol.Relation1Relationships) |
2269 |
{ |
2270 |
if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID)) |
2271 |
{ |
2272 |
endRepID.Add(item.Item1RepresentationID); |
2273 |
if (item.Item1RepresentationObject.get_RepresentationClass() == "Connector") |
2274 |
{ |
2275 |
LMModelItem modelItem = item.Item1RepresentationObject.ModelItemObject; |
2276 |
SetAttribute(modelItem); |
2277 |
LoopConnector(dataSource.GetConnector(item.Item1RepresentationID), endRepID); |
2278 |
} |
2279 |
else if (item.Item1RepresentationObject.get_RepresentationClass() == "Symbol") |
2280 |
{ |
2281 |
LoopSymbol(dataSource.GetSymbol(item.Item1RepresentationID), endRepID); |
2282 |
} |
2283 |
} |
2284 |
|
2285 |
if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID)) |
2286 |
{ |
2287 |
endRepID.Add(item.Item2RepresentationID); |
2288 |
if (item.Item2RepresentationObject.get_RepresentationClass() == "Connector") |
2289 |
{ |
2290 |
LMModelItem modelItem = item.Item2RepresentationObject.ModelItemObject; |
2291 |
SetAttribute(modelItem); |
2292 |
LoopConnector(dataSource.GetConnector(item.Item2RepresentationID), endRepID); |
2293 |
} |
2294 |
else if (item.Item2RepresentationObject.get_RepresentationClass() == "Symbol") |
2295 |
{ |
2296 |
LoopSymbol(dataSource.GetSymbol(item.Item2RepresentationID), endRepID); |
2297 |
} |
2298 |
} |
2299 |
} |
2300 |
|
2301 |
foreach (LMRelationship item in loopSymbol.Relation2Relationships) |
2302 |
{ |
2303 |
if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID)) |
2304 |
{ |
2305 |
endRepID.Add(item.Item1RepresentationID); |
2306 |
if (item.Item1RepresentationObject.get_RepresentationClass() == "Connector") |
2307 |
{ |
2308 |
LMModelItem modelItem = item.Item1RepresentationObject.ModelItemObject; |
2309 |
SetAttribute(modelItem); |
2310 |
LoopConnector(dataSource.GetConnector(item.Item1RepresentationID), endRepID); |
2311 |
} |
2312 |
else if (item.Item1RepresentationObject.get_RepresentationClass() == "Symbol") |
2313 |
{ |
2314 |
LoopSymbol(dataSource.GetSymbol(item.Item1RepresentationID), endRepID); |
2315 |
} |
2316 |
} |
2317 |
|
2318 |
if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID)) |
2319 |
{ |
2320 |
endRepID.Add(item.Item2RepresentationID); |
2321 |
if (item.Item2RepresentationObject.get_RepresentationClass() == "Connector") |
2322 |
{ |
2323 |
LMModelItem modelItem = item.Item2RepresentationObject.ModelItemObject; |
2324 |
SetAttribute(modelItem); |
2325 |
LoopConnector(dataSource.GetConnector(item.Item2RepresentationID), endRepID); |
2326 |
} |
2327 |
else if (item.Item2RepresentationObject.get_RepresentationClass() == "Symbol") |
2328 |
{ |
2329 |
LoopSymbol(dataSource.GetSymbol(item.Item2RepresentationID), endRepID); |
2330 |
} |
2331 |
} |
2332 |
} |
2333 |
|
2334 |
foreach (LMConnector item in loopSymbol.Connect1Connectors)//나가는것 |
2335 |
{ |
2336 |
if (item.get_ItemStatus() != "Active" || endRepID.Contains(item.AsLMRepresentation().Id)) |
2337 |
continue; |
2338 |
|
2339 |
endRepID.Add(item.AsLMRepresentation().Id); |
2340 |
if (item.get_ItemStatus() == "Active") |
2341 |
{ |
2342 |
LMModelItem modelItem = item.ModelItemObject; |
2343 |
SetAttribute(modelItem); |
2344 |
LoopConnector(item, endRepID); |
2345 |
} |
2346 |
} |
2347 |
|
2348 |
foreach (LMConnector item in loopSymbol.Connect2Connectors)//들어오는것 |
2349 |
{ |
2350 |
if (item.get_ItemStatus() != "Active" || endRepID.Contains(item.AsLMRepresentation().Id)) |
2351 |
continue; |
2352 |
|
2353 |
endRepID.Add(item.AsLMRepresentation().Id); |
2354 |
if (item.get_ItemStatus() == "Active") |
2355 |
{ |
2356 |
LMModelItem modelItem = item.ModelItemObject; |
2357 |
SetAttribute(modelItem); |
2358 |
LoopConnector(item, endRepID); |
2359 |
} |
2360 |
} |
2361 |
} |
2362 |
|
2363 |
void LoopConnector(LMConnector connector, List<string> endRepID) |
2364 |
{ |
2365 |
if (connector.ConnectItem1SymbolObject != null && !endRepID.Contains(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id)) |
2366 |
{ |
2367 |
endRepID.Add(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id); |
2368 |
//LoopSymbol(connector.ConnectItem1SymbolObject, endRepID); |
2369 |
} |
2370 |
|
2371 |
if (connector.ConnectItem2SymbolObject != null && !endRepID.Contains(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id)) |
2372 |
{ |
2373 |
endRepID.Add(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id); |
2374 |
//LoopSymbol(connector.ConnectItem2SymbolObject, endRepID); |
2375 |
} |
2376 |
} |
2377 |
} |
2378 |
|
2379 |
void SetAttribute(LMModelItem modelItem) |
2380 |
{ |
2381 |
LMAAttribute attribute = modelItem.Attributes["FlowDirection"]; |
2382 |
if (attribute != null) |
2383 |
attribute.set_Value("End 1 is upstream (Inlet)"); |
2384 |
modelItem.Commit(); |
2385 |
} |
2386 |
|
2387 |
ReleaseCOMObjects(_placement); |
2388 |
ReleaseCOMObjects(dataSource); |
2389 |
|
2390 |
MessageBox.Show("End OPC Flow Direction"); |
2391 |
} |
2392 |
|
2393 |
private void btnCreateStreamBreak_Click(object sender, EventArgs e) |
2394 |
{ |
2395 |
Placement _placement; |
2396 |
LMADataSource dataSource; |
2397 |
|
2398 |
StreamNoBreak(); |
2399 |
|
2400 |
void StreamNoBreak() |
2401 |
{ |
2402 |
|
2403 |
_placement = new Placement(); |
2404 |
dataSource = _placement.PIDDataSource; |
2405 |
|
2406 |
OPCFlowDirection(); |
2407 |
|
2408 |
void OPCFlowDirection() |
2409 |
{ |
2410 |
//current LMDrawing 가져오기 |
2411 |
LMAFilter filter = new LMAFilter(); |
2412 |
LMACriterion criterion = new LMACriterion(); |
2413 |
filter.ItemType = "Drawing"; |
2414 |
criterion.SourceAttributeName = "Name"; |
2415 |
criterion.Operator = "="; |
2416 |
criterion.set_ValueAttribute(application.ActiveDocument.Name.Replace(".pid", "")); |
2417 |
filter.get_Criteria().Add(criterion); |
2418 |
|
2419 |
LMDrawings drawings = new LMDrawings(); |
2420 |
drawings.Collect(dataSource, Filter: filter); |
2421 |
|
2422 |
// Input Drawing Attribute |
2423 |
LMDrawing drawing = ((dynamic)drawings).Nth(1); |
2424 |
|
2425 |
LMAFilter filter2 = new LMAFilter(); |
2426 |
filter2.ItemType = "REPRESENTATION"; |
2427 |
|
2428 |
LMACriterion criterion2 = new LMACriterion(); |
2429 |
criterion2.SourceAttributeName = "REPRESENTATIONTYPE"; |
2430 |
criterion2.Operator = "="; |
2431 |
criterion2.set_ValueAttribute("46"); |
2432 |
filter2.get_Criteria().Add(criterion2); |
2433 |
|
2434 |
LMRepresentations representations = new LMRepresentations(); |
2435 |
representations.Collect(dataSource, Filter: filter2); |
2436 |
|
2437 |
foreach (LMRepresentation representation in representations) |
2438 |
{ |
2439 |
if (representation.DrawingID == drawing.Id) |
2440 |
{ |
2441 |
LMSymbol symbol = dataSource.GetSymbol(representation.Id); |
2442 |
CreateSpec(symbol); |
2443 |
} |
2444 |
} |
2445 |
|
2446 |
ReleaseCOMObjects(filter); |
2447 |
ReleaseCOMObjects(filter2); |
2448 |
ReleaseCOMObjects(criterion); |
2449 |
ReleaseCOMObjects(criterion2); |
2450 |
ReleaseCOMObjects(drawing); |
2451 |
ReleaseCOMObjects(drawings); |
2452 |
ReleaseCOMObjects(representations); |
2453 |
} |
2454 |
} |
2455 |
|
2456 |
void CreateSpec(LMSymbol symbol) |
2457 |
{ |
2458 |
ZoomObjectByGraphicOID(symbol.get_XCoordinate(), symbol.get_YCoordinate()); |
2459 |
|
2460 |
foreach (LMConnector item in symbol.Connect1Connectors) |
2461 |
{ |
2462 |
if (item.get_ItemStatus() == "Active") |
2463 |
{ |
2464 |
Array array = new double[] { 0, symbol.get_XCoordinate(), symbol.get_YCoordinate() }; |
2465 |
LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(@"\Piping\Segment Breaks\Above\stream Number Break.sym", ref array, LabeledItem: item.AsLMRepresentation(), IsLeaderVisible: true); |
2466 |
} |
2467 |
} |
2468 |
|
2469 |
foreach (LMConnector item in symbol.Connect2Connectors) |
2470 |
{ |
2471 |
if (item.get_ItemStatus() == "Active") |
2472 |
{ |
2473 |
Array array = new double[] { 0, symbol.get_XCoordinate(), symbol.get_YCoordinate() }; |
2474 |
LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(@"\Piping\Segment Breaks\Above\stream Number Break.sym", ref array, LabeledItem: item.AsLMRepresentation(), IsLeaderVisible: true); |
2475 |
} |
2476 |
} |
2477 |
|
2478 |
Thread.Sleep(500); |
2479 |
} |
2480 |
|
2481 |
MessageBox.Show("End Modeling"); |
2482 |
} |
2483 |
|
2484 |
private void btnPipeRunBreak_Click(object sender, EventArgs e) |
2485 |
{ |
2486 |
Placement placement = new Placement(); |
2487 |
LMADataSource dataSource = placement.PIDDataSource; |
2488 |
|
2489 |
string sFrom = textEdit1.EditValue.ToString(); |
2490 |
string sTo = textEdit2.EditValue.ToString(); |
2491 |
|
2492 |
LMModelItem item1 = dataSource.GetModelItem(sFrom); |
2493 |
LMModelItem item2 = dataSource.GetModelItem(sTo); |
2494 |
if (item1 != null && item1.Representations.Count == 1 && |
2495 |
item2 != null && item2.Representations.Count == 1) |
2496 |
{ |
2497 |
LMSymbol startSymbol = dataSource.GetSymbol(item1.Representations.Nth[1].Id); |
2498 |
LMSymbol endSymbol = dataSource.GetSymbol(item2.Representations.Nth[1].Id); |
2499 |
|
2500 |
if (startSymbol != null && endSymbol != null) |
2501 |
{ |
2502 |
FindRun(startSymbol, endSymbol, @"\Piping\Segment Breaks\End of Group.sym"); |
2503 |
} |
2504 |
else |
2505 |
{ |
2506 |
MessageBox.Show("From To 심볼 확인"); |
2507 |
} |
2508 |
} |
2509 |
else |
2510 |
{ |
2511 |
MessageBox.Show("From To 심볼 확인"); |
2512 |
} |
2513 |
} |
2514 |
|
2515 |
private void btnSegmentBreak_Click(object sender, EventArgs e) |
2516 |
{ |
2517 |
Placement placement = new Placement(); |
2518 |
LMADataSource dataSource = placement.PIDDataSource; |
2519 |
|
2520 |
string sFrom = textEdit1.EditValue.ToString(); |
2521 |
string sTo = textEdit2.EditValue.ToString(); |
2522 |
|
2523 |
LMModelItem item1 = dataSource.GetModelItem(sFrom); |
2524 |
LMModelItem item2 = dataSource.GetModelItem(sTo); |
2525 |
if (item1 != null && item1.Representations.Count == 1 && |
2526 |
item2 != null && item2.Representations.Count == 1) |
2527 |
{ |
2528 |
LMSymbol startSymbol = dataSource.GetSymbol(item1.Representations.Nth[1].Id); |
2529 |
LMSymbol endSymbol = dataSource.GetSymbol(item2.Representations.Nth[1].Id); |
2530 |
|
2531 |
if (startSymbol != null && endSymbol != null) |
2532 |
{ |
2533 |
FindRun(startSymbol, endSymbol, @"\Piping\Segment Breaks\Max Design Press - Temp.sym"); |
2534 |
} |
2535 |
else |
2536 |
{ |
2537 |
MessageBox.Show("From To 심볼 확인"); |
2538 |
} |
2539 |
} |
2540 |
else |
2541 |
{ |
2542 |
MessageBox.Show("From To 심볼 확인"); |
2543 |
} |
2544 |
} |
2545 |
|
2546 |
private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150) |
2547 |
{ |
2548 |
if (application.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null) |
2549 |
{ |
2550 |
double minX = 0; |
2551 |
double minY = 0; |
2552 |
double maxX = 0; |
2553 |
double maxY = 0; |
2554 |
application.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY); |
2555 |
application.ActiveWindow.ZoomArea2(minX - 0.01, minY - 0.01, maxX + 0.01, maxY + 0.01, null); |
2556 |
|
2557 |
Thread.Sleep(milliseconds); |
2558 |
} |
2559 |
} |
2560 |
|
2561 |
private void ZoomObjectByGraphicOID(double x, double y, int milliseconds = 150) |
2562 |
{ |
2563 |
application.ActiveWindow.ZoomArea2(x - 0.01, y - 0.01, x + 0.01, y + 0.01, null); |
2564 |
Thread.Sleep(milliseconds); |
2565 |
} |
2566 |
#endregion |
2567 |
|
2568 |
|
2569 |
} |
2570 |
} |