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