hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 20f9fa83
이력 | 보기 | 이력해설 | 다운로드 (32.4 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using Newtonsoft.Json; |
7 |
using System.IO; |
8 |
using Converter.SPPID.DB; |
9 |
using Converter.BaseModel; |
10 |
using System.Windows.Forms; |
11 |
using Converter.SPPID.Model; |
12 |
using System.Drawing; |
13 |
using Llama; |
14 |
using System.Data; |
15 |
using Plaice; |
16 |
using Microsoft.VisualBasic; |
17 |
using DevExpress.XtraBars.ViewInfo; |
18 |
using Converter.SPPID.SPPIDModel; |
19 |
|
20 |
namespace Converter.SPPID.Util |
21 |
{ |
22 |
public enum BulkAttributeItemType |
23 |
{ |
24 |
PipeRun, |
25 |
Symbol, |
26 |
} |
27 |
public enum SlopeType |
28 |
{ |
29 |
None, |
30 |
Slope, |
31 |
HORIZONTAL, |
32 |
VERTICAL |
33 |
} |
34 |
public class SPPIDUtil |
35 |
{ |
36 |
public static bool ConvertToSPPIDInfo(string jsonString) |
37 |
{ |
38 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
39 |
try |
40 |
{ |
41 |
SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString); |
42 |
|
43 |
_SPPIDInfo.DBType = jsonSPPIDInfo.DBType; |
44 |
_SPPIDInfo.Service = jsonSPPIDInfo.Service; |
45 |
_SPPIDInfo.Site = jsonSPPIDInfo.Site; |
46 |
_SPPIDInfo.ServerIP = jsonSPPIDInfo.ServerIP; |
47 |
_SPPIDInfo.Port = jsonSPPIDInfo.Port; |
48 |
_SPPIDInfo.DBUser = jsonSPPIDInfo.DBUser; |
49 |
_SPPIDInfo.DBPassword = jsonSPPIDInfo.DBPassword; |
50 |
_SPPIDInfo.PlantPath = jsonSPPIDInfo.PlantPath; |
51 |
_SPPIDInfo.PlantDic = jsonSPPIDInfo.PlantDic; |
52 |
_SPPIDInfo.PlantPID = jsonSPPIDInfo.PlantPID; |
53 |
_SPPIDInfo.PlantPIDDic = jsonSPPIDInfo.PlantPIDDic; |
54 |
_SPPIDInfo.Plant = jsonSPPIDInfo.Plant; |
55 |
_SPPIDInfo.Enable = jsonSPPIDInfo.Enable; |
56 |
_SPPIDInfo.SelectedPlant = jsonSPPIDInfo.SelectedPlant; |
57 |
_SPPIDInfo.PlantList = jsonSPPIDInfo.PlantList; |
58 |
_SPPIDInfo.SQLSERVER_DBNAME = jsonSPPIDInfo.SQLSERVER_DBNAME; |
59 |
_SPPIDInfo.PlantDic_DataBase = jsonSPPIDInfo.PlantDic_DataBase; |
60 |
_SPPIDInfo.Plant_DataBase = jsonSPPIDInfo.Plant_DataBase; |
61 |
_SPPIDInfo.PlantPID_DataBase = jsonSPPIDInfo.PlantPID_DataBase; |
62 |
_SPPIDInfo.PlantPIDDic_DataBase = jsonSPPIDInfo.PlantPIDDic_DataBase; |
63 |
|
64 |
} |
65 |
catch (Exception ex) |
66 |
{ |
67 |
_SPPIDInfo.Enable = false; |
68 |
return false; |
69 |
} |
70 |
return true; |
71 |
} |
72 |
|
73 |
public static bool ConvertToETCSetting(string jsonString) |
74 |
{ |
75 |
ETCSetting _ETCSetting = ETCSetting.GetInstance(); |
76 |
try |
77 |
{ |
78 |
ETCSetting jsonETCSetting = JsonConvert.DeserializeObject<ETCSetting>(jsonString); |
79 |
|
80 |
_ETCSetting.NoteSymbolPath = jsonETCSetting.NoteSymbolPath; |
81 |
_ETCSetting.TextSymbolPath = jsonETCSetting.TextSymbolPath; |
82 |
_ETCSetting.DrainValveSize = jsonETCSetting.DrainValveSize; |
83 |
_ETCSetting.VendorPackageSymbolPath = jsonETCSetting.VendorPackageSymbolPath; |
84 |
_ETCSetting.TextLocation = jsonETCSetting.TextLocation; |
85 |
_ETCSetting.NoteLocation = jsonETCSetting.NoteLocation; |
86 |
_ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation; |
87 |
_ETCSetting.FlowMarkSymbolPath = jsonETCSetting.FlowMarkSymbolPath; |
88 |
_ETCSetting.BorderFilePath = jsonETCSetting.BorderFilePath; |
89 |
_ETCSetting.UnitSetting = jsonETCSetting.UnitSetting; |
90 |
_ETCSetting.BulkAttributes = jsonETCSetting.BulkAttributes; |
91 |
} |
92 |
catch (Exception ex) |
93 |
{ |
94 |
return false; |
95 |
} |
96 |
return true; |
97 |
} |
98 |
|
99 |
public static bool ConvertToGridSetting(string jsonString) |
100 |
{ |
101 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
102 |
try |
103 |
{ |
104 |
GridSetting jsonGridSetting = JsonConvert.DeserializeObject<GridSetting>(jsonString); |
105 |
|
106 |
_GridSetting.UseSnapGrid = jsonGridSetting.UseSnapGrid; |
107 |
_GridSetting.Density = jsonGridSetting.Density; |
108 |
_GridSetting.Unit = jsonGridSetting.Unit; |
109 |
_GridSetting.DrainValveCellCount = jsonGridSetting.DrainValveCellCount; |
110 |
} |
111 |
catch (Exception ex) |
112 |
{ |
113 |
return false; |
114 |
} |
115 |
return true; |
116 |
} |
117 |
|
118 |
public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
119 |
{ |
120 |
try |
121 |
{ |
122 |
string[] pointArr = sPoint.Split(new char[] { ',' }); |
123 |
if (pointArr.Length == 2) |
124 |
{ |
125 |
dX = Convert.ToDouble(pointArr[0]); |
126 |
dY = Convert.ToDouble(pointArr[1]); |
127 |
} |
128 |
} |
129 |
catch (Exception) |
130 |
{ |
131 |
dX = 0; |
132 |
dY = 0; |
133 |
return false; |
134 |
} |
135 |
|
136 |
return true; |
137 |
} |
138 |
|
139 |
public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
140 |
{ |
141 |
decimal calcX = 0; |
142 |
decimal calcY = 0; |
143 |
decimal tempX = Convert.ToDecimal(dX); |
144 |
decimal tempY = Convert.ToDecimal(dY); |
145 |
decimal tempWidth = Convert.ToDecimal(SPPID_Width); |
146 |
decimal tempHeight = Convert.ToDecimal(SPPID_Height); |
147 |
decimal tempDwgX = Convert.ToDecimal(dDwgX); |
148 |
decimal tempDwgY = Convert.ToDecimal(dDwgY); |
149 |
|
150 |
calcX = (tempX * tempWidth) / tempDwgX; |
151 |
calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
152 |
dX = Convert.ToDouble(calcX); |
153 |
dY = Convert.ToDouble(calcY); |
154 |
} |
155 |
|
156 |
public static void ConvertGridPoint(ref double x, ref double y) |
157 |
{ |
158 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
159 |
if (_GridSetting.UseSnapGrid) |
160 |
{ |
161 |
if (_GridSetting.Unit == GridUnit.Inch) |
162 |
{ |
163 |
double length = _GridSetting.Density * 0.0254; |
164 |
double tempX = x; |
165 |
double tempY = y; |
166 |
x = Math.Round(tempX / length) * length; |
167 |
y = Math.Round(tempY / length) * length; |
168 |
} |
169 |
} |
170 |
} |
171 |
|
172 |
public static void ConvertGridPointOnlyOnePoint(ref double value) |
173 |
{ |
174 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
175 |
if (_GridSetting.UseSnapGrid) |
176 |
{ |
177 |
if (_GridSetting.Unit == GridUnit.Inch) |
178 |
{ |
179 |
double temp = value; |
180 |
value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length; |
181 |
} |
182 |
} |
183 |
} |
184 |
public static double ConvertGridPointOnlyOnePoint(double value) |
185 |
{ |
186 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
187 |
if (_GridSetting.UseSnapGrid) |
188 |
{ |
189 |
if (_GridSetting.Unit == GridUnit.Inch) |
190 |
{ |
191 |
double temp = value; |
192 |
value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length; |
193 |
} |
194 |
} |
195 |
|
196 |
return value; |
197 |
} |
198 |
|
199 |
public static bool EqualSpacing(double value1, double value2) |
200 |
{ |
201 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
202 |
double multiplier = 100000000000000; |
203 |
value1 = Math.Truncate(value1 * multiplier) / multiplier; |
204 |
value2 = Math.Truncate(value2 * multiplier) / multiplier; |
205 |
|
206 |
return value1 == value2; |
207 |
} |
208 |
|
209 |
public static SlopeType CalcSlope(double x1, double y1, double x2, double y2, double degree = 15) |
210 |
{ |
211 |
if (x1 - x2 == 0) |
212 |
{ |
213 |
return SlopeType.VERTICAL; |
214 |
} |
215 |
else |
216 |
{ |
217 |
double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
218 |
if (angle <= degree) |
219 |
return SlopeType.HORIZONTAL; |
220 |
else if (angle >= 90 - degree) |
221 |
return SlopeType.VERTICAL; |
222 |
else |
223 |
return SlopeType.Slope; |
224 |
} |
225 |
} |
226 |
public static double CalcAngle(double x1, double y1, double x2, double y2) |
227 |
{ |
228 |
double result = 90; |
229 |
if (x1 - x2 != 0) |
230 |
{ |
231 |
result = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
232 |
} |
233 |
return result; |
234 |
} |
235 |
public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y) |
236 |
{ |
237 |
|
238 |
double distance = 0; |
239 |
if (lineX1 == lineX2) |
240 |
distance = Math.Abs(x - lineX1); |
241 |
else |
242 |
{ |
243 |
double a; |
244 |
double b; |
245 |
double c; |
246 |
|
247 |
a = (lineY2 - lineY1) / (lineX2 - lineX1); |
248 |
b = -1; |
249 |
c = -a * lineX1 + lineY1; |
250 |
|
251 |
distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5); |
252 |
} |
253 |
return distance; |
254 |
} |
255 |
|
256 |
public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) |
257 |
{ |
258 |
double a1; |
259 |
double a2; |
260 |
double b1; |
261 |
double b2; |
262 |
|
263 |
if (x1 == x2) |
264 |
a1 = 0; |
265 |
else |
266 |
a1 = (y2 - y1) / (x2 - x1); |
267 |
if (x3 == x4) |
268 |
a2 = 0; |
269 |
else |
270 |
a2 = (y4 - y3) / (x4 - x3); |
271 |
|
272 |
b1 = -a1 * x1 + y1; |
273 |
b2 = -a2 * x3 + y3; |
274 |
|
275 |
if (x1 == x2 && x3 == x4) |
276 |
{ |
277 |
return null; |
278 |
} |
279 |
else if (x1 == x2) |
280 |
{ |
281 |
return new double[] { x1, a2*x1 + b2 }; |
282 |
} |
283 |
else if (x3 == x4) |
284 |
{ |
285 |
return new double[] { x3, a1 * x3 + b1 }; |
286 |
} |
287 |
else |
288 |
{ |
289 |
return new double[] { -(b1 - b2) / (a1 - a2), a1 * -(b1 - b2) / (a1 - a2) + b1 }; |
290 |
} |
291 |
} |
292 |
|
293 |
public static double CalcGradient(double x1, double y1, double x2, double y2) |
294 |
{ |
295 |
double result = double.NaN; |
296 |
|
297 |
if (x1 != x2) |
298 |
result = (y2 - y1) / (x2 - x1); |
299 |
|
300 |
return result; |
301 |
} |
302 |
|
303 |
public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2) |
304 |
{ |
305 |
return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5); |
306 |
} |
307 |
|
308 |
public static object FindObjectByUID(Document document, string UID) |
309 |
{ |
310 |
if (!string.IsNullOrEmpty(UID) && UID != "None") |
311 |
{ |
312 |
foreach (Symbol item in document.SYMBOLS) |
313 |
{ |
314 |
if (item.UID == UID) |
315 |
return item; |
316 |
} |
317 |
|
318 |
foreach (Line item in document.LINES) |
319 |
{ |
320 |
if (item.UID == UID) |
321 |
return item; |
322 |
} |
323 |
|
324 |
foreach (Text item in document.TEXTINFOS) |
325 |
{ |
326 |
if (item.UID == UID) |
327 |
return item; |
328 |
} |
329 |
|
330 |
foreach (Note item in document.NOTES) |
331 |
{ |
332 |
if (item.UID == UID) |
333 |
return item; |
334 |
} |
335 |
|
336 |
foreach (LineNumber item in document.LINENUMBERS) |
337 |
{ |
338 |
if (item.UID == UID) |
339 |
return item; |
340 |
} |
341 |
|
342 |
foreach (Equipment item in document.Equipments) |
343 |
{ |
344 |
if (item.UID == UID) |
345 |
return item; |
346 |
} |
347 |
|
348 |
foreach (SpecBreak item in document.SpecBreaks) |
349 |
{ |
350 |
if (item.UID == UID) |
351 |
return item; |
352 |
} |
353 |
|
354 |
foreach (EndBreak item in document.EndBreaks) |
355 |
{ |
356 |
if (item.UID == UID) |
357 |
return item; |
358 |
} |
359 |
|
360 |
foreach (VendorPackage item in document.VendorPackages) |
361 |
{ |
362 |
if (item.UID == UID) |
363 |
return item; |
364 |
} |
365 |
} |
366 |
|
367 |
return null; |
368 |
} |
369 |
|
370 |
public static List<Line> FindLinesByModelId(Document document, string ModelItemId) |
371 |
{ |
372 |
List<Line> lines = new List<Line>(); |
373 |
foreach (Line item in document.LINES) |
374 |
{ |
375 |
if (item.SPPID.ModelItemId == ModelItemId) |
376 |
lines.Add(item); |
377 |
} |
378 |
|
379 |
return lines; |
380 |
} |
381 |
|
382 |
public static void FindConnectedSymbolGroup(Document document, Symbol symbol, List<Symbol> group) |
383 |
{ |
384 |
if (!group.Contains(symbol)) |
385 |
group.Add(symbol); |
386 |
|
387 |
foreach (var connector in symbol.CONNECTORS) |
388 |
{ |
389 |
object connectedItem = FindObjectByUID(document, connector.CONNECTEDITEM); |
390 |
if (connectedItem != null && connectedItem.GetType() == typeof(Symbol)) |
391 |
{ |
392 |
Symbol connSymbol = connectedItem as Symbol; |
393 |
if (!group.Contains(connSymbol)) |
394 |
{ |
395 |
group.Add(connSymbol); |
396 |
FindConnectedSymbolGroup(document, connSymbol, group); |
397 |
} |
398 |
} |
399 |
} |
400 |
} |
401 |
|
402 |
public static Symbol FindCenterAtThreeSymbols(Document document, List<Symbol> group) |
403 |
{ |
404 |
Symbol result = null; |
405 |
|
406 |
// Group의 가운데 찾기 |
407 |
if (group.Count == 3) |
408 |
{ |
409 |
foreach (var symbol in group) |
410 |
{ |
411 |
int count = 0; |
412 |
foreach (var connector in symbol.CONNECTORS) |
413 |
{ |
414 |
object item = FindObjectByUID(document, connector.CONNECTEDITEM); |
415 |
if (item != null && item.GetType() == typeof(Symbol) && group.Contains(item as Symbol)) |
416 |
count++; |
417 |
} |
418 |
|
419 |
if (count == 2) |
420 |
{ |
421 |
result = symbol; |
422 |
break; |
423 |
} |
424 |
} |
425 |
} |
426 |
|
427 |
return result; |
428 |
} |
429 |
|
430 |
private static void GetConnectedSymbol(Document document, Symbol symbol, List<Symbol> symbolGroup) |
431 |
{ |
432 |
foreach (Connector connector in symbol.CONNECTORS) |
433 |
{ |
434 |
object item = FindObjectByUID(document, connector.CONNECTEDITEM); |
435 |
if (item != null && item.GetType() == typeof(Symbol)) |
436 |
{ |
437 |
Symbol connSymbol = item as Symbol; |
438 |
if (connSymbol != null && !symbolGroup.Contains(connSymbol)) |
439 |
{ |
440 |
symbolGroup.Add(connSymbol); |
441 |
GetConnectedSymbol(document, connSymbol, symbolGroup); |
442 |
} |
443 |
} |
444 |
} |
445 |
} |
446 |
|
447 |
public static int SortSymbolPriority(Symbol a, Symbol b) |
448 |
{ |
449 |
int resultValue = a.SPPID.ORIGINAL_Y.CompareTo(b.SPPID.ORIGINAL_Y); |
450 |
if (resultValue == 0) |
451 |
resultValue = a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X); |
452 |
return resultValue; |
453 |
} |
454 |
|
455 |
public static Connector FindSymbolConnectorByUID(Document document, string uid, Symbol targetSymbol) |
456 |
{ |
457 |
foreach (var connector in targetSymbol.CONNECTORS) |
458 |
{ |
459 |
if (connector.CONNECTEDITEM == uid) |
460 |
{ |
461 |
return connector; |
462 |
} |
463 |
} |
464 |
|
465 |
return null; |
466 |
} |
467 |
|
468 |
public static Symbol FindSymbolByRepresentationID(Document document, string repID) |
469 |
{ |
470 |
Symbol findSymbol = null; |
471 |
foreach (var symbol in document.SYMBOLS) |
472 |
{ |
473 |
if (symbol.SPPID.RepresentationId == repID) |
474 |
{ |
475 |
findSymbol = symbol; |
476 |
} |
477 |
else |
478 |
{ |
479 |
ChildSymbol childSymbol = FindChildSymbolByRepresentationID(document, symbol, repID); |
480 |
if (childSymbol != null) |
481 |
findSymbol = symbol; |
482 |
} |
483 |
|
484 |
if (findSymbol != null) |
485 |
break; |
486 |
} |
487 |
|
488 |
return findSymbol; |
489 |
} |
490 |
|
491 |
public static ChildSymbol FindChildSymbolByRepresentationID(Document document, Symbol symbol, string repID) |
492 |
{ |
493 |
ChildSymbol childSymbol = null; |
494 |
|
495 |
foreach (ChildSymbol loopChild in symbol.ChildSymbols) |
496 |
{ |
497 |
if (loopChild.SPPID.RepresentationId == repID) |
498 |
{ |
499 |
childSymbol = loopChild; |
500 |
break; |
501 |
} |
502 |
else |
503 |
{ |
504 |
childSymbol = FindChildSymbolByRepresentationIDLoop(document, repID, loopChild); |
505 |
if (childSymbol != null) |
506 |
break; |
507 |
} |
508 |
} |
509 |
|
510 |
return childSymbol; |
511 |
} |
512 |
|
513 |
private static ChildSymbol FindChildSymbolByRepresentationIDLoop(Document document, string repID, ChildSymbol childSymbol) |
514 |
{ |
515 |
ChildSymbol findChild = null; |
516 |
|
517 |
foreach (var item in childSymbol.ChildSymbols) |
518 |
{ |
519 |
if (item.SPPID.RepresentationId == repID) |
520 |
{ |
521 |
findChild = item; |
522 |
break; |
523 |
} |
524 |
else |
525 |
{ |
526 |
findChild = FindChildSymbolByRepresentationIDLoop(document, repID, item); |
527 |
if (findChild != null) |
528 |
break; |
529 |
} |
530 |
} |
531 |
|
532 |
return findChild; |
533 |
} |
534 |
|
535 |
public static bool IsBranchLine(Line line1, Line line2) |
536 |
{ |
537 |
bool result = true; |
538 |
|
539 |
Connector conn1 = line1.CONNECTORS.Find(x => x.CONNECTEDITEM == line2.UID); |
540 |
Connector conn2 = line2.CONNECTORS.Find(x => x.CONNECTEDITEM == line1.UID); |
541 |
|
542 |
if (conn1 != null && conn2 != null) |
543 |
result = false; |
544 |
|
545 |
return result; |
546 |
} |
547 |
|
548 |
public static bool IsBranchLine(Line line) |
549 |
{ |
550 |
Connector connector = line.CONNECTORS.Find(x => |
551 |
x.ConnectedObject != null && |
552 |
x.ConnectedObject.GetType() == typeof(Line) && |
553 |
IsBranchLine(line, x.ConnectedObject as Line)); |
554 |
return connector != null ? true : false; |
555 |
} |
556 |
|
557 |
public static bool IsBranchedLine(Document document,Line line) |
558 |
{ |
559 |
return document.LINES.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == line.UID && IsBranchLine(x, y.ConnectedObject as Line)) != null) != null ? true : false; |
560 |
} |
561 |
|
562 |
public static void CalcOverlap(double[] range1, double[] range2, ref double x, ref double y, ref bool overlapX, ref bool overlapY) |
563 |
{ |
564 |
if (range1[0] <= range2[2] && range1[2] >= range2[0]) |
565 |
{ |
566 |
overlapX = true; |
567 |
x = Math.Min(Math.Abs(range1[0] - range2[2]), Math.Abs(range1[2] - range2[0])); |
568 |
} |
569 |
|
570 |
if (range1[1] <= range2[3] && range1[3] >= range2[1]) |
571 |
{ |
572 |
overlapY = true; |
573 |
y = Math.Min(Math.Abs(range1[1] - range2[3]), Math.Abs(range1[3] - range2[1])); |
574 |
} |
575 |
} |
576 |
|
577 |
public static bool IsOverlap(double[] range1, double[] range2) |
578 |
{ |
579 |
if (range1[0] <= range2[2] && range1[2] >= range2[0] && range1[1] <= range2[3] && range1[3] >= range2[1]) |
580 |
return true; |
581 |
else |
582 |
return false; |
583 |
} |
584 |
|
585 |
public static void CalcNewCoordinateForSymbol(Symbol symbol, Symbol prevSymbol, double distanceX, double distanceY) |
586 |
{ |
587 |
SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y); |
588 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
589 |
if (slopeType == SlopeType.HORIZONTAL) |
590 |
{ |
591 |
double length = (Math.Ceiling(distanceX / _GridSetting.Length) + 1) * _GridSetting.Length; |
592 |
if (prevSymbol.SPPID.ORIGINAL_X < symbol.SPPID.ORIGINAL_X) |
593 |
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + length; |
594 |
else |
595 |
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - length; |
596 |
} |
597 |
else if (slopeType == SlopeType.VERTICAL) |
598 |
{ |
599 |
double length = (Math.Ceiling(distanceY / _GridSetting.Length) + 1) * _GridSetting.Length; |
600 |
if (prevSymbol.SPPID.ORIGINAL_Y < symbol.SPPID.ORIGINAL_Y) |
601 |
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + length; |
602 |
else |
603 |
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - length; |
604 |
} |
605 |
} |
606 |
|
607 |
public static Line GetConnectedLine(Symbol symbol1, Symbol symbol2) |
608 |
{ |
609 |
Line line = null; |
610 |
Connector connector1 = symbol1.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && |
611 |
((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol2) != null); |
612 |
Connector connector2 = symbol2.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && |
613 |
((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol1) != null); |
614 |
if (connector1 != null && connector2 != null) |
615 |
line = connector1.ConnectedObject as Line; |
616 |
|
617 |
return line; |
618 |
} |
619 |
|
620 |
public static int GetBranchLineCount(Document document, Line line) |
621 |
{ |
622 |
return document.LINES.FindAll(x => IsBranchLine(line, x) && x.CONNECTORS.Find(y => y.ConnectedObject == line) != null).Count; |
623 |
} |
624 |
|
625 |
public static bool GetLineConnectorPoint(Line line, Connector connector, ref double x, ref double y) |
626 |
{ |
627 |
bool bStart = false; |
628 |
int index = line.CONNECTORS.IndexOf(connector); |
629 |
if (index == 0) |
630 |
{ |
631 |
x = line.SPPID.START_X; |
632 |
y = line.SPPID.START_Y; |
633 |
bStart = true; |
634 |
} |
635 |
else |
636 |
{ |
637 |
x = line.SPPID.END_X; |
638 |
y = line.SPPID.END_Y; |
639 |
} |
640 |
return bStart; |
641 |
} |
642 |
|
643 |
public static bool IsSegment(Document document, Line line1, Line line2) |
644 |
{ |
645 |
bool result = false; |
646 |
|
647 |
SpecBreak specBreak = document.SpecBreaks.Find(x => |
648 |
(x.DownStreamUID == line1.UID && x.UpStreamUID == line2.UID) || |
649 |
(x.DownStreamUID == line2.UID && x.UpStreamUID == line1.UID)); |
650 |
|
651 |
EndBreak endBreak = document.EndBreaks.Find(x => |
652 |
(x.OWNER == line1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line2.UID) || |
653 |
(x.OWNER == line2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line1.UID)); |
654 |
|
655 |
if (specBreak != null || endBreak != null) |
656 |
result = true; |
657 |
|
658 |
return result; |
659 |
} |
660 |
|
661 |
public static bool IsSegment(Document document, Symbol symbol1, Symbol symbol2) |
662 |
{ |
663 |
bool result = false; |
664 |
SpecBreak startSpecBreak = document.SpecBreaks.Find(x => |
665 |
(x.DownStreamUID == symbol1.UID && x.UpStreamUID == symbol2.UID) || |
666 |
(x.DownStreamUID == symbol2.UID && x.UpStreamUID == symbol1.UID)); |
667 |
|
668 |
EndBreak startEndBreak = document.EndBreaks.Find(x => |
669 |
(x.OWNER == symbol1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID) || |
670 |
(x.OWNER == symbol2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID)); |
671 |
|
672 |
if (startSpecBreak != null || startEndBreak != null) |
673 |
result = true; |
674 |
|
675 |
return result; |
676 |
} |
677 |
public static void test() |
678 |
{ |
679 |
Placement placement = new Placement(); |
680 |
LMADataSource dataSource = new LMADataSource(); |
681 |
LMSymbol symbol = dataSource.GetSymbol("BBAB475FA9AF4C01AACF4C51F56241F8"); |
682 |
|
683 |
string[] array1 = new string[] { "", "Top" }; |
684 |
string[] array2 = new string[] { "", "0.005" }; |
685 |
placement.PIDApplyParameters(symbol.AsLMRepresentation(), array1, array2); |
686 |
|
687 |
ReleaseCOMObjects(dataSource); |
688 |
} |
689 |
public static DataTable GetUnitInfo() |
690 |
{ |
691 |
LMADataSource dataSource = new LMADataSource(); |
692 |
LMPlantGroups units = new LMPlantGroups(); |
693 |
units.Collect(dataSource); |
694 |
DataTable dt = new DataTable(); |
695 |
dt.Columns.Add("LEVEL", typeof(string)); |
696 |
dt.Columns.Add("SP_ID", typeof(string)); |
697 |
dt.Columns.Add("PARENTID", typeof(string)); |
698 |
dt.Columns.Add("NAME", typeof(string)); |
699 |
|
700 |
foreach (LMPlantGroup unit in units) |
701 |
{ |
702 |
object tt = unit.get_Dir_Path(); |
703 |
if (tt.Equals(DBNull.Value)) |
704 |
continue; |
705 |
string dir = unit.get_Dir_Path(); |
706 |
string[] array = dir.Split('\\'); |
707 |
List<string> parents = new List<string>(); |
708 |
string prevId = "-1"; |
709 |
for (int i = 1; i < array.Length; i++) |
710 |
{ |
711 |
string name = array[i]; |
712 |
string uid = Guid.NewGuid().ToString(); |
713 |
DataRow[] rows = dt.Select(string.Format("LEVEL = '{0}' AND NAME = '{1}' AND PARENTID = '{2}'", i, name, prevId)); |
714 |
if (rows.Length == 0) |
715 |
dt.Rows.Add(i, uid, prevId, name); |
716 |
else |
717 |
uid = rows[0]["SP_ID"].ToString(); |
718 |
prevId = uid; |
719 |
} |
720 |
} |
721 |
|
722 |
dt.Columns.Remove("LEVEL"); |
723 |
|
724 |
ReleaseCOMObjects(units); |
725 |
ReleaseCOMObjects(dataSource); |
726 |
|
727 |
return dt; |
728 |
} |
729 |
public static string T_OPTIONSETTING_Value(string name) |
730 |
{ |
731 |
string result = string.Empty; |
732 |
LMADataSource dataSource = new LMADataSource(); |
733 |
LMOptionSettings settings = new LMOptionSettings(); |
734 |
|
735 |
LMAFilter filter = new LMAFilter(); |
736 |
LMACriterion criterion = new LMACriterion(); |
737 |
filter.ItemType = "OptionSetting"; |
738 |
criterion.SourceAttributeName = "NAME"; |
739 |
criterion.Operator = "="; |
740 |
criterion.set_ValueAttribute(name); |
741 |
filter.get_Criteria().Add(criterion); |
742 |
settings.Collect(dataSource, Filter: filter); |
743 |
|
744 |
foreach (LMOptionSetting item in settings) |
745 |
{ |
746 |
result = item.get_Value(); |
747 |
break; |
748 |
} |
749 |
|
750 |
ReleaseCOMObjects(criterion); |
751 |
ReleaseCOMObjects(filter); |
752 |
ReleaseCOMObjects(settings); |
753 |
ReleaseCOMObjects(dataSource); |
754 |
return result; |
755 |
} |
756 |
|
757 |
public static string T_PLANTSETTING_Value(string name) |
758 |
{ |
759 |
string result = string.Empty; |
760 |
LMADataSource dataSource = new LMADataSource(); |
761 |
LMPlantSettings settings = new LMPlantSettings(); |
762 |
|
763 |
LMAFilter filter = new LMAFilter(); |
764 |
LMACriterion criterion = new LMACriterion(); |
765 |
filter.ItemType = "PlantSetting"; |
766 |
criterion.SourceAttributeName = "NAME"; |
767 |
criterion.Operator = "="; |
768 |
criterion.set_ValueAttribute(name); |
769 |
filter.get_Criteria().Add(criterion); |
770 |
settings.Collect(dataSource, Filter: filter); |
771 |
|
772 |
foreach (LMPlantSetting item in settings) |
773 |
{ |
774 |
result = item.get_Value(); |
775 |
break; |
776 |
} |
777 |
|
778 |
ReleaseCOMObjects(criterion); |
779 |
ReleaseCOMObjects(filter); |
780 |
ReleaseCOMObjects(settings); |
781 |
ReleaseCOMObjects(dataSource); |
782 |
return result; |
783 |
} |
784 |
|
785 |
public static void ReleaseCOMObjects(params object[] objVars) |
786 |
{ |
787 |
int intNewRefCount = 0; |
788 |
foreach (object obj in objVars) |
789 |
{ |
790 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
791 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
792 |
} |
793 |
} |
794 |
|
795 |
public static void BulkAttribute(LMADataSource dataSource, List<BulkAttribute> attributes, BulkAttributeItemType type) |
796 |
{ |
797 |
switch (type) |
798 |
{ |
799 |
case BulkAttributeItemType.PipeRun: |
800 |
BulkAttribute_PipeRun(); |
801 |
break; |
802 |
case BulkAttributeItemType.Symbol: |
803 |
BulkAttribute_Symbol(); |
804 |
break; |
805 |
default: |
806 |
break; |
807 |
} |
808 |
void BulkAttribute_PipeRun() |
809 |
{ |
810 |
string drawingId = dataSource.PIDMgr.Drawing.ID; |
811 |
|
812 |
LMAFilter filter = new LMAFilter(); |
813 |
|
814 |
LMACriterion criterion = new LMACriterion(); |
815 |
criterion.SourceAttributeName = "REPRESENTATION.SP_DRAWINGID"; |
816 |
criterion.Operator = "="; |
817 |
criterion.set_ValueAttribute(drawingId); |
818 |
filter.get_Criteria().Add(criterion); |
819 |
filter.ItemType = "PIPERUN"; |
820 |
|
821 |
LMACriterion criterion2 = new LMACriterion(); |
822 |
criterion2.SourceAttributeName = "REPRESENTATION.INSTOCKPILE"; |
823 |
criterion2.Operator = "="; |
824 |
criterion2.set_ValueAttribute("1"); |
825 |
criterion2.Conjunctive = true; |
826 |
filter.get_Criteria().Add(criterion2); |
827 |
|
828 |
LMACriterion criterion3 = new LMACriterion(); |
829 |
criterion3.SourceAttributeName = "REPRESENTATION.ITEMSTATUS"; |
830 |
criterion3.Operator = "="; |
831 |
criterion3.set_ValueAttribute("1"); |
832 |
criterion3.Conjunctive = true; |
833 |
filter.get_Criteria().Add(criterion3); |
834 |
|
835 |
LMPipeRuns items = new LMPipeRuns(); |
836 |
items.Collect(dataSource, Filter: filter); |
837 |
|
838 |
foreach (LMPipeRun item in items) |
839 |
{ |
840 |
foreach (var attribute in attributes) |
841 |
{ |
842 |
if (item.Attributes[attribute.SPPIDAttributeName] != null) |
843 |
item.Attributes[attribute.SPPIDAttributeName].set_Value(attribute.Value); |
844 |
} |
845 |
item.Commit(); |
846 |
} |
847 |
|
848 |
ReleaseCOMObjects(items); |
849 |
ReleaseCOMObjects(filter); |
850 |
ReleaseCOMObjects(criterion); |
851 |
ReleaseCOMObjects(criterion2); |
852 |
ReleaseCOMObjects(criterion3); |
853 |
} |
854 |
void BulkAttribute_Symbol() |
855 |
{ |
856 |
string drawingId = dataSource.PIDMgr.Drawing.ID; |
857 |
|
858 |
LMAFilter filter = new LMAFilter(); |
859 |
|
860 |
LMACriterion criterion = new LMACriterion(); |
861 |
criterion.SourceAttributeName = "SP_DRAWINGID"; |
862 |
criterion.Operator = "="; |
863 |
criterion.set_ValueAttribute(drawingId); |
864 |
filter.get_Criteria().Add(criterion); |
865 |
filter.ItemType = "SYMBOL"; |
866 |
|
867 |
LMACriterion criterion2 = new LMACriterion(); |
868 |
criterion2.SourceAttributeName = "INSTOCKPILE"; |
869 |
criterion2.Operator = "="; |
870 |
criterion2.set_ValueAttribute("1"); |
871 |
criterion2.Conjunctive = true; |
872 |
filter.get_Criteria().Add(criterion2); |
873 |
|
874 |
LMACriterion criterion3 = new LMACriterion(); |
875 |
criterion3.SourceAttributeName = "ITEMSTATUS"; |
876 |
criterion3.Operator = "="; |
877 |
criterion3.set_ValueAttribute("1"); |
878 |
criterion3.Conjunctive = true; |
879 |
filter.get_Criteria().Add(criterion3); |
880 |
|
881 |
LMSymbols items = new LMSymbols(); |
882 |
items.Collect(dataSource, Filter: filter); |
883 |
|
884 |
foreach (LMSymbol item in items) |
885 |
{ |
886 |
foreach (var attribute in attributes) |
887 |
{ |
888 |
if (item.Attributes[attribute.SPPIDAttributeName] != null) |
889 |
item.Attributes[attribute.SPPIDAttributeName].set_Value(attribute.Value); |
890 |
} |
891 |
item.Commit(); |
892 |
} |
893 |
|
894 |
ReleaseCOMObjects(items); |
895 |
ReleaseCOMObjects(filter); |
896 |
ReleaseCOMObjects(criterion); |
897 |
ReleaseCOMObjects(criterion2); |
898 |
ReleaseCOMObjects(criterion3); |
899 |
} |
900 |
} |
901 |
|
902 |
} |
903 |
} |