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