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