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