1 |
23eb98bf
|
gaqhf
|
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 |
b8e2644e
|
gaqhf
|
using Converter.SPPID.DB;
|
9 |
23eb98bf
|
gaqhf
|
using Converter.BaseModel;
|
10 |
|
|
using System.Windows.Forms;
|
11 |
bca81f4c
|
gaqhf
|
using Converter.SPPID.Model;
|
12 |
5dfb8a24
|
gaqhf
|
using System.Drawing;
|
13 |
4d4dce52
|
esham21
|
using Llama;
|
14 |
ea54adc8
|
gaqhf
|
using System.Data;
|
15 |
4d4dce52
|
esham21
|
using Plaice;
|
16 |
ea54adc8
|
gaqhf
|
using Microsoft.VisualBasic;
|
17 |
86c0a45e
|
gaqhf
|
using DevExpress.XtraBars.ViewInfo;
|
18 |
|
|
using Converter.SPPID.SPPIDModel;
|
19 |
23eb98bf
|
gaqhf
|
|
20 |
b8e2644e
|
gaqhf
|
namespace Converter.SPPID.Util
|
21 |
23eb98bf
|
gaqhf
|
{
|
22 |
86c0a45e
|
gaqhf
|
public enum BulkAttributeItemType
|
23 |
|
|
{
|
24 |
|
|
PipeRun,
|
25 |
|
|
Symbol,
|
26 |
|
|
}
|
27 |
5dfb8a24
|
gaqhf
|
public enum SlopeType
|
28 |
|
|
{
|
29 |
d1eac84d
|
gaqhf
|
None,
|
30 |
5dfb8a24
|
gaqhf
|
Slope,
|
31 |
|
|
HORIZONTAL,
|
32 |
|
|
VERTICAL
|
33 |
|
|
}
|
34 |
23eb98bf
|
gaqhf
|
public class SPPIDUtil
|
35 |
|
|
{
|
36 |
6b60e542
|
Denny
|
public static LMPipeRun PipeRun;
|
37 |
|
|
public static List<BaseModel.SPPIDCodeList> CodeListSet;
|
38 |
|
|
|
39 |
fab4f207
|
gaqhf
|
public static bool ConvertToSPPIDInfo(string jsonString)
|
40 |
23eb98bf
|
gaqhf
|
{
|
41 |
2e1e3c12
|
gaqhf
|
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
|
42 |
23eb98bf
|
gaqhf
|
try
|
43 |
|
|
{
|
44 |
fab4f207
|
gaqhf
|
SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString);
|
45 |
23eb98bf
|
gaqhf
|
|
46 |
|
|
_SPPIDInfo.DBType = jsonSPPIDInfo.DBType;
|
47 |
|
|
_SPPIDInfo.Service = jsonSPPIDInfo.Service;
|
48 |
|
|
_SPPIDInfo.Site = jsonSPPIDInfo.Site;
|
49 |
|
|
_SPPIDInfo.ServerIP = jsonSPPIDInfo.ServerIP;
|
50 |
|
|
_SPPIDInfo.Port = jsonSPPIDInfo.Port;
|
51 |
|
|
_SPPIDInfo.DBUser = jsonSPPIDInfo.DBUser;
|
52 |
|
|
_SPPIDInfo.DBPassword = jsonSPPIDInfo.DBPassword;
|
53 |
|
|
_SPPIDInfo.PlantPath = jsonSPPIDInfo.PlantPath;
|
54 |
|
|
_SPPIDInfo.PlantDic = jsonSPPIDInfo.PlantDic;
|
55 |
|
|
_SPPIDInfo.PlantPID = jsonSPPIDInfo.PlantPID;
|
56 |
|
|
_SPPIDInfo.PlantPIDDic = jsonSPPIDInfo.PlantPIDDic;
|
57 |
|
|
_SPPIDInfo.Plant = jsonSPPIDInfo.Plant;
|
58 |
|
|
_SPPIDInfo.Enable = jsonSPPIDInfo.Enable;
|
59 |
|
|
_SPPIDInfo.SelectedPlant = jsonSPPIDInfo.SelectedPlant;
|
60 |
|
|
_SPPIDInfo.PlantList = jsonSPPIDInfo.PlantList;
|
61 |
2e92b956
|
gaqhf
|
_SPPIDInfo.SQLSERVER_DBNAME = jsonSPPIDInfo.SQLSERVER_DBNAME;
|
62 |
04133d37
|
gaqhf
|
_SPPIDInfo.PlantDic_DataBase = jsonSPPIDInfo.PlantDic_DataBase;
|
63 |
|
|
_SPPIDInfo.Plant_DataBase = jsonSPPIDInfo.Plant_DataBase;
|
64 |
|
|
_SPPIDInfo.PlantPID_DataBase = jsonSPPIDInfo.PlantPID_DataBase;
|
65 |
|
|
_SPPIDInfo.PlantPIDDic_DataBase = jsonSPPIDInfo.PlantPIDDic_DataBase;
|
66 |
23eb98bf
|
gaqhf
|
|
67 |
|
|
}
|
68 |
|
|
catch (Exception ex)
|
69 |
|
|
{
|
70 |
fab4f207
|
gaqhf
|
_SPPIDInfo.Enable = false;
|
71 |
23eb98bf
|
gaqhf
|
return false;
|
72 |
|
|
}
|
73 |
|
|
return true;
|
74 |
|
|
}
|
75 |
5dfb8a24
|
gaqhf
|
|
76 |
e00e891d
|
gaqhf
|
public static bool ConvertToETCSetting(string jsonString)
|
77 |
|
|
{
|
78 |
|
|
ETCSetting _ETCSetting = ETCSetting.GetInstance();
|
79 |
|
|
try
|
80 |
|
|
{
|
81 |
|
|
ETCSetting jsonETCSetting = JsonConvert.DeserializeObject<ETCSetting>(jsonString);
|
82 |
|
|
|
83 |
|
|
_ETCSetting.NoteSymbolPath = jsonETCSetting.NoteSymbolPath;
|
84 |
|
|
_ETCSetting.TextSymbolPath = jsonETCSetting.TextSymbolPath;
|
85 |
|
|
_ETCSetting.DrainValveSize = jsonETCSetting.DrainValveSize;
|
86 |
fbea6028
|
gaqhf
|
_ETCSetting.VendorPackageSymbolPath = jsonETCSetting.VendorPackageSymbolPath;
|
87 |
1a3a74a8
|
gaqhf
|
_ETCSetting.TextLocation = jsonETCSetting.TextLocation;
|
88 |
|
|
_ETCSetting.NoteLocation = jsonETCSetting.NoteLocation;
|
89 |
|
|
_ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation;
|
90 |
b2d1c1aa
|
gaqhf
|
_ETCSetting.FlowMarkSymbolPath = jsonETCSetting.FlowMarkSymbolPath;
|
91 |
b7b123ba
|
gaqhf
|
_ETCSetting.BorderFilePath = jsonETCSetting.BorderFilePath;
|
92 |
c9264d17
|
gaqhf
|
_ETCSetting.UnitSetting = jsonETCSetting.UnitSetting;
|
93 |
86c0a45e
|
gaqhf
|
_ETCSetting.BulkAttributes = jsonETCSetting.BulkAttributes;
|
94 |
e00e891d
|
gaqhf
|
}
|
95 |
|
|
catch (Exception ex)
|
96 |
|
|
{
|
97 |
|
|
return false;
|
98 |
|
|
}
|
99 |
|
|
return true;
|
100 |
|
|
}
|
101 |
bca81f4c
|
gaqhf
|
|
102 |
7cbb1038
|
gaqhf
|
public static bool ConvertToGridSetting(string jsonString)
|
103 |
|
|
{
|
104 |
|
|
GridSetting _GridSetting = GridSetting.GetInstance();
|
105 |
|
|
try
|
106 |
|
|
{
|
107 |
|
|
GridSetting jsonGridSetting = JsonConvert.DeserializeObject<GridSetting>(jsonString);
|
108 |
|
|
|
109 |
|
|
_GridSetting.UseSnapGrid = jsonGridSetting.UseSnapGrid;
|
110 |
|
|
_GridSetting.Density = jsonGridSetting.Density;
|
111 |
|
|
_GridSetting.Unit = jsonGridSetting.Unit;
|
112 |
f676f99a
|
gaqhf
|
_GridSetting.DrainValveCellCount = jsonGridSetting.DrainValveCellCount;
|
113 |
7cbb1038
|
gaqhf
|
}
|
114 |
|
|
catch (Exception ex)
|
115 |
|
|
{
|
116 |
|
|
return false;
|
117 |
|
|
}
|
118 |
|
|
return true;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
39a2a688
|
gaqhf
|
public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY)
|
122 |
|
|
{
|
123 |
|
|
try
|
124 |
|
|
{
|
125 |
|
|
string[] pointArr = sPoint.Split(new char[] { ',' });
|
126 |
|
|
if (pointArr.Length == 2)
|
127 |
|
|
{
|
128 |
|
|
dX = Convert.ToDouble(pointArr[0]);
|
129 |
|
|
dY = Convert.ToDouble(pointArr[1]);
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
catch (Exception)
|
133 |
|
|
{
|
134 |
|
|
dX = 0;
|
135 |
|
|
dY = 0;
|
136 |
|
|
return false;
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
return true;
|
140 |
|
|
}
|
141 |
bca81f4c
|
gaqhf
|
|
142 |
39a2a688
|
gaqhf
|
public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height)
|
143 |
|
|
{
|
144 |
1b261371
|
gaqhf
|
decimal calcX = 0;
|
145 |
|
|
decimal calcY = 0;
|
146 |
|
|
decimal tempX = Convert.ToDecimal(dX);
|
147 |
|
|
decimal tempY = Convert.ToDecimal(dY);
|
148 |
|
|
decimal tempWidth = Convert.ToDecimal(SPPID_Width);
|
149 |
|
|
decimal tempHeight = Convert.ToDecimal(SPPID_Height);
|
150 |
|
|
decimal tempDwgX = Convert.ToDecimal(dDwgX);
|
151 |
|
|
decimal tempDwgY = Convert.ToDecimal(dDwgY);
|
152 |
|
|
|
153 |
|
|
calcX = (tempX * tempWidth) / tempDwgX;
|
154 |
|
|
calcY = tempHeight - ((tempY * tempHeight) / tempDwgY);
|
155 |
c3d2e266
|
gaqhf
|
dX = Convert.ToDouble(calcX);
|
156 |
|
|
dY = Convert.ToDouble(calcY);
|
157 |
39a2a688
|
gaqhf
|
}
|
158 |
bca81f4c
|
gaqhf
|
|
159 |
06b40010
|
gaqhf
|
public static void ConvertGridPoint(ref double x, ref double y)
|
160 |
|
|
{
|
161 |
|
|
GridSetting _GridSetting = GridSetting.GetInstance();
|
162 |
|
|
if (_GridSetting.UseSnapGrid)
|
163 |
|
|
{
|
164 |
|
|
if (_GridSetting.Unit == GridUnit.Inch)
|
165 |
|
|
{
|
166 |
|
|
double length = _GridSetting.Density * 0.0254;
|
167 |
|
|
double tempX = x;
|
168 |
|
|
double tempY = y;
|
169 |
|
|
x = Math.Round(tempX / length) * length;
|
170 |
|
|
y = Math.Round(tempY / length) * length;
|
171 |
b66a2996
|
gaqhf
|
}
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
4d2571ab
|
gaqhf
|
|
175 |
b66a2996
|
gaqhf
|
public static void ConvertGridPointOnlyOnePoint(ref double value)
|
176 |
|
|
{
|
177 |
|
|
GridSetting _GridSetting = GridSetting.GetInstance();
|
178 |
|
|
if (_GridSetting.UseSnapGrid)
|
179 |
|
|
{
|
180 |
|
|
if (_GridSetting.Unit == GridUnit.Inch)
|
181 |
|
|
{
|
182 |
|
|
double temp = value;
|
183 |
5fed7052
|
esham21
|
value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length;
|
184 |
06b40010
|
gaqhf
|
}
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
a0e3dca4
|
gaqhf
|
public static double ConvertGridPointOnlyOnePoint(double value)
|
188 |
|
|
{
|
189 |
|
|
GridSetting _GridSetting = GridSetting.GetInstance();
|
190 |
|
|
if (_GridSetting.UseSnapGrid)
|
191 |
|
|
{
|
192 |
|
|
if (_GridSetting.Unit == GridUnit.Inch)
|
193 |
|
|
{
|
194 |
|
|
double temp = value;
|
195 |
|
|
value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length;
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
return value;
|
200 |
|
|
}
|
201 |
06b40010
|
gaqhf
|
|
202 |
20f9fa83
|
Denny
|
public static bool EqualSpacing(double value1, double value2)
|
203 |
|
|
{
|
204 |
|
|
GridSetting _GridSetting = GridSetting.GetInstance();
|
205 |
|
|
double multiplier = 100000000000000;
|
206 |
|
|
value1 = Math.Truncate(value1 * multiplier) / multiplier;
|
207 |
|
|
value2 = Math.Truncate(value2 * multiplier) / multiplier;
|
208 |
|
|
|
209 |
|
|
return value1 == value2;
|
210 |
|
|
}
|
211 |
|
|
|
212 |
c3e8fa8e
|
gaqhf
|
public static SlopeType CalcSlope(double x1, double y1, double x2, double y2, double degree = 15)
|
213 |
5dfb8a24
|
gaqhf
|
{
|
214 |
|
|
if (x1 - x2 == 0)
|
215 |
|
|
{
|
216 |
|
|
return SlopeType.VERTICAL;
|
217 |
|
|
}
|
218 |
|
|
else
|
219 |
|
|
{
|
220 |
|
|
double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
|
221 |
c3e8fa8e
|
gaqhf
|
if (angle <= degree)
|
222 |
5dfb8a24
|
gaqhf
|
return SlopeType.HORIZONTAL;
|
223 |
c3e8fa8e
|
gaqhf
|
else if (angle >= 90 - degree)
|
224 |
5dfb8a24
|
gaqhf
|
return SlopeType.VERTICAL;
|
225 |
|
|
else
|
226 |
|
|
return SlopeType.Slope;
|
227 |
|
|
}
|
228 |
|
|
}
|
229 |
32205389
|
gaqhf
|
public static double CalcAngle(double x1, double y1, double x2, double y2)
|
230 |
|
|
{
|
231 |
60f4405d
|
gaqhf
|
double result = 90;
|
232 |
32205389
|
gaqhf
|
if (x1 - x2 != 0)
|
233 |
|
|
{
|
234 |
|
|
result = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
|
235 |
|
|
}
|
236 |
|
|
return result;
|
237 |
|
|
}
|
238 |
5e6ecf05
|
gaqhf
|
public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y)
|
239 |
|
|
{
|
240 |
|
|
|
241 |
|
|
double distance = 0;
|
242 |
|
|
if (lineX1 == lineX2)
|
243 |
|
|
distance = Math.Abs(x - lineX1);
|
244 |
|
|
else
|
245 |
|
|
{
|
246 |
|
|
double a;
|
247 |
|
|
double b;
|
248 |
|
|
double c;
|
249 |
|
|
|
250 |
|
|
a = (lineY2 - lineY1) / (lineX2 - lineX1);
|
251 |
|
|
b = -1;
|
252 |
|
|
c = -a * lineX1 + lineY1;
|
253 |
|
|
|
254 |
|
|
distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5);
|
255 |
|
|
}
|
256 |
|
|
return distance;
|
257 |
|
|
}
|
258 |
|
|
|
259 |
56bc67e1
|
gaqhf
|
public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
|
260 |
|
|
{
|
261 |
|
|
double a1;
|
262 |
|
|
double a2;
|
263 |
|
|
double b1;
|
264 |
|
|
double b2;
|
265 |
|
|
|
266 |
|
|
if (x1 == x2)
|
267 |
|
|
a1 = 0;
|
268 |
|
|
else
|
269 |
|
|
a1 = (y2 - y1) / (x2 - x1);
|
270 |
|
|
if (x3 == x4)
|
271 |
|
|
a2 = 0;
|
272 |
|
|
else
|
273 |
|
|
a2 = (y4 - y3) / (x4 - x3);
|
274 |
|
|
|
275 |
|
|
b1 = -a1 * x1 + y1;
|
276 |
|
|
b2 = -a2 * x3 + y3;
|
277 |
|
|
|
278 |
32205389
|
gaqhf
|
if (x1 == x2 && x3 == x4)
|
279 |
56bc67e1
|
gaqhf
|
{
|
280 |
|
|
return null;
|
281 |
|
|
}
|
282 |
|
|
else if (x1 == x2)
|
283 |
|
|
{
|
284 |
|
|
return new double[] { x1, a2*x1 + b2 };
|
285 |
|
|
}
|
286 |
|
|
else if (x3 == x4)
|
287 |
|
|
{
|
288 |
|
|
return new double[] { x3, a1 * x3 + b1 };
|
289 |
|
|
}
|
290 |
|
|
else
|
291 |
|
|
{
|
292 |
32205389
|
gaqhf
|
return new double[] { -(b1 - b2) / (a1 - a2), a1 * -(b1 - b2) / (a1 - a2) + b1 };
|
293 |
|
|
}
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
public static double CalcGradient(double x1, double y1, double x2, double y2)
|
297 |
|
|
{
|
298 |
|
|
double result = double.NaN;
|
299 |
|
|
|
300 |
|
|
if (x1 != x2)
|
301 |
|
|
result = (y2 - y1) / (x2 - x1);
|
302 |
|
|
|
303 |
|
|
return result;
|
304 |
56bc67e1
|
gaqhf
|
}
|
305 |
d1eac84d
|
gaqhf
|
|
306 |
30a9ffce
|
gaqhf
|
public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
|
307 |
|
|
{
|
308 |
|
|
return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
|
309 |
|
|
}
|
310 |
|
|
|
311 |
bca81f4c
|
gaqhf
|
public static object FindObjectByUID(Document document, string UID)
|
312 |
|
|
{
|
313 |
d63050d6
|
gaqhf
|
if (!string.IsNullOrEmpty(UID) && UID != "None")
|
314 |
bca81f4c
|
gaqhf
|
{
|
315 |
d63050d6
|
gaqhf
|
foreach (Symbol item in document.SYMBOLS)
|
316 |
|
|
{
|
317 |
|
|
if (item.UID == UID)
|
318 |
|
|
return item;
|
319 |
|
|
}
|
320 |
bca81f4c
|
gaqhf
|
|
321 |
d63050d6
|
gaqhf
|
foreach (Line item in document.LINES)
|
322 |
|
|
{
|
323 |
|
|
if (item.UID == UID)
|
324 |
|
|
return item;
|
325 |
|
|
}
|
326 |
bca81f4c
|
gaqhf
|
|
327 |
d63050d6
|
gaqhf
|
foreach (Text item in document.TEXTINFOS)
|
328 |
|
|
{
|
329 |
|
|
if (item.UID == UID)
|
330 |
|
|
return item;
|
331 |
|
|
}
|
332 |
bca81f4c
|
gaqhf
|
|
333 |
d63050d6
|
gaqhf
|
foreach (Note item in document.NOTES)
|
334 |
|
|
{
|
335 |
|
|
if (item.UID == UID)
|
336 |
|
|
return item;
|
337 |
|
|
}
|
338 |
bca81f4c
|
gaqhf
|
|
339 |
d63050d6
|
gaqhf
|
foreach (LineNumber item in document.LINENUMBERS)
|
340 |
|
|
{
|
341 |
|
|
if (item.UID == UID)
|
342 |
|
|
return item;
|
343 |
|
|
}
|
344 |
bca81f4c
|
gaqhf
|
|
345 |
d63050d6
|
gaqhf
|
foreach (Equipment item in document.Equipments)
|
346 |
|
|
{
|
347 |
|
|
if (item.UID == UID)
|
348 |
|
|
return item;
|
349 |
|
|
}
|
350 |
30ba9ae0
|
gaqhf
|
|
351 |
|
|
foreach (SpecBreak item in document.SpecBreaks)
|
352 |
|
|
{
|
353 |
|
|
if (item.UID == UID)
|
354 |
|
|
return item;
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
foreach (EndBreak item in document.EndBreaks)
|
358 |
|
|
{
|
359 |
|
|
if (item.UID == UID)
|
360 |
|
|
return item;
|
361 |
|
|
}
|
362 |
fb2d9638
|
gaqhf
|
|
363 |
|
|
foreach (VendorPackage item in document.VendorPackages)
|
364 |
|
|
{
|
365 |
|
|
if (item.UID == UID)
|
366 |
|
|
return item;
|
367 |
|
|
}
|
368 |
809a7640
|
gaqhf
|
}
|
369 |
|
|
|
370 |
bca81f4c
|
gaqhf
|
return null;
|
371 |
|
|
}
|
372 |
d1eac84d
|
gaqhf
|
|
373 |
335b7a24
|
gaqhf
|
public static List<Line> FindLinesByModelId(Document document, string ModelItemId)
|
374 |
|
|
{
|
375 |
|
|
List<Line> lines = new List<Line>();
|
376 |
|
|
foreach (Line item in document.LINES)
|
377 |
|
|
{
|
378 |
|
|
if (item.SPPID.ModelItemId == ModelItemId)
|
379 |
|
|
lines.Add(item);
|
380 |
|
|
}
|
381 |
|
|
|
382 |
|
|
return lines;
|
383 |
|
|
}
|
384 |
d1eac84d
|
gaqhf
|
|
385 |
4d2571ab
|
gaqhf
|
public static void FindConnectedSymbolGroup(Document document, Symbol symbol, List<Symbol> group)
|
386 |
b9cc9254
|
gaqhf
|
{
|
387 |
f1a7faf9
|
gaqhf
|
if (!group.Contains(symbol))
|
388 |
|
|
group.Add(symbol);
|
389 |
|
|
|
390 |
4d2571ab
|
gaqhf
|
foreach (var connector in symbol.CONNECTORS)
|
391 |
b9cc9254
|
gaqhf
|
{
|
392 |
4d2571ab
|
gaqhf
|
object connectedItem = FindObjectByUID(document, connector.CONNECTEDITEM);
|
393 |
|
|
if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
|
394 |
b9cc9254
|
gaqhf
|
{
|
395 |
4d2571ab
|
gaqhf
|
Symbol connSymbol = connectedItem as Symbol;
|
396 |
|
|
if (!group.Contains(connSymbol))
|
397 |
b9cc9254
|
gaqhf
|
{
|
398 |
4d2571ab
|
gaqhf
|
group.Add(connSymbol);
|
399 |
|
|
FindConnectedSymbolGroup(document, connSymbol, group);
|
400 |
b9cc9254
|
gaqhf
|
}
|
401 |
|
|
}
|
402 |
|
|
}
|
403 |
|
|
}
|
404 |
|
|
|
405 |
4d2571ab
|
gaqhf
|
public static Symbol FindCenterAtThreeSymbols(Document document, List<Symbol> group)
|
406 |
d1eac84d
|
gaqhf
|
{
|
407 |
4d2571ab
|
gaqhf
|
Symbol result = null;
|
408 |
|
|
|
409 |
|
|
// Group의 가운데 찾기
|
410 |
|
|
if (group.Count == 3)
|
411 |
d1eac84d
|
gaqhf
|
{
|
412 |
4d2571ab
|
gaqhf
|
foreach (var symbol in group)
|
413 |
|
|
{
|
414 |
|
|
int count = 0;
|
415 |
|
|
foreach (var connector in symbol.CONNECTORS)
|
416 |
|
|
{
|
417 |
|
|
object item = FindObjectByUID(document, connector.CONNECTEDITEM);
|
418 |
|
|
if (item != null && item.GetType() == typeof(Symbol) && group.Contains(item as Symbol))
|
419 |
|
|
count++;
|
420 |
|
|
}
|
421 |
d1eac84d
|
gaqhf
|
|
422 |
4d2571ab
|
gaqhf
|
if (count == 2)
|
423 |
|
|
{
|
424 |
|
|
result = symbol;
|
425 |
|
|
break;
|
426 |
|
|
}
|
427 |
|
|
}
|
428 |
d1eac84d
|
gaqhf
|
}
|
429 |
|
|
|
430 |
4d2571ab
|
gaqhf
|
return result;
|
431 |
d1eac84d
|
gaqhf
|
}
|
432 |
|
|
|
433 |
|
|
private static void GetConnectedSymbol(Document document, Symbol symbol, List<Symbol> symbolGroup)
|
434 |
|
|
{
|
435 |
|
|
foreach (Connector connector in symbol.CONNECTORS)
|
436 |
|
|
{
|
437 |
|
|
object item = FindObjectByUID(document, connector.CONNECTEDITEM);
|
438 |
|
|
if (item != null && item.GetType() == typeof(Symbol))
|
439 |
|
|
{
|
440 |
|
|
Symbol connSymbol = item as Symbol;
|
441 |
|
|
if (connSymbol != null && !symbolGroup.Contains(connSymbol))
|
442 |
|
|
{
|
443 |
|
|
symbolGroup.Add(connSymbol);
|
444 |
|
|
GetConnectedSymbol(document, connSymbol, symbolGroup);
|
445 |
|
|
}
|
446 |
|
|
}
|
447 |
|
|
}
|
448 |
|
|
}
|
449 |
2fdb56bf
|
gaqhf
|
|
450 |
20f9fa83
|
Denny
|
public static int SortSymbolPriority(Symbol a, Symbol b)
|
451 |
|
|
{
|
452 |
|
|
int resultValue = a.SPPID.ORIGINAL_Y.CompareTo(b.SPPID.ORIGINAL_Y);
|
453 |
|
|
if (resultValue == 0)
|
454 |
|
|
resultValue = a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
|
455 |
|
|
return resultValue;
|
456 |
|
|
}
|
457 |
|
|
|
458 |
2fdb56bf
|
gaqhf
|
public static Connector FindSymbolConnectorByUID(Document document, string uid, Symbol targetSymbol)
|
459 |
|
|
{
|
460 |
|
|
foreach (var connector in targetSymbol.CONNECTORS)
|
461 |
|
|
{
|
462 |
|
|
if (connector.CONNECTEDITEM == uid)
|
463 |
|
|
{
|
464 |
|
|
return connector;
|
465 |
|
|
}
|
466 |
|
|
}
|
467 |
|
|
|
468 |
|
|
return null;
|
469 |
|
|
}
|
470 |
71ba1ca3
|
gaqhf
|
|
471 |
|
|
public static Symbol FindSymbolByRepresentationID(Document document, string repID)
|
472 |
|
|
{
|
473 |
|
|
Symbol findSymbol = null;
|
474 |
|
|
foreach (var symbol in document.SYMBOLS)
|
475 |
|
|
{
|
476 |
|
|
if (symbol.SPPID.RepresentationId == repID)
|
477 |
|
|
{
|
478 |
|
|
findSymbol = symbol;
|
479 |
|
|
}
|
480 |
|
|
else
|
481 |
|
|
{
|
482 |
|
|
ChildSymbol childSymbol = FindChildSymbolByRepresentationID(document, symbol, repID);
|
483 |
|
|
if (childSymbol != null)
|
484 |
|
|
findSymbol = symbol;
|
485 |
|
|
}
|
486 |
|
|
|
487 |
|
|
if (findSymbol != null)
|
488 |
|
|
break;
|
489 |
|
|
}
|
490 |
|
|
|
491 |
|
|
return findSymbol;
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
public static ChildSymbol FindChildSymbolByRepresentationID(Document document, Symbol symbol, string repID)
|
495 |
|
|
{
|
496 |
|
|
ChildSymbol childSymbol = null;
|
497 |
|
|
|
498 |
|
|
foreach (ChildSymbol loopChild in symbol.ChildSymbols)
|
499 |
|
|
{
|
500 |
|
|
if (loopChild.SPPID.RepresentationId == repID)
|
501 |
|
|
{
|
502 |
|
|
childSymbol = loopChild;
|
503 |
|
|
break;
|
504 |
|
|
}
|
505 |
|
|
else
|
506 |
|
|
{
|
507 |
|
|
childSymbol = FindChildSymbolByRepresentationIDLoop(document, repID, loopChild);
|
508 |
|
|
if (childSymbol != null)
|
509 |
|
|
break;
|
510 |
|
|
}
|
511 |
|
|
}
|
512 |
|
|
|
513 |
|
|
return childSymbol;
|
514 |
|
|
}
|
515 |
|
|
|
516 |
|
|
private static ChildSymbol FindChildSymbolByRepresentationIDLoop(Document document, string repID, ChildSymbol childSymbol)
|
517 |
|
|
{
|
518 |
|
|
ChildSymbol findChild = null;
|
519 |
|
|
|
520 |
|
|
foreach (var item in childSymbol.ChildSymbols)
|
521 |
|
|
{
|
522 |
|
|
if (item.SPPID.RepresentationId == repID)
|
523 |
|
|
{
|
524 |
|
|
findChild = item;
|
525 |
|
|
break;
|
526 |
|
|
}
|
527 |
|
|
else
|
528 |
|
|
{
|
529 |
|
|
findChild = FindChildSymbolByRepresentationIDLoop(document, repID, item);
|
530 |
|
|
if (findChild != null)
|
531 |
|
|
break;
|
532 |
|
|
}
|
533 |
|
|
}
|
534 |
|
|
|
535 |
|
|
return findChild;
|
536 |
|
|
}
|
537 |
d9794a6c
|
gaqhf
|
|
538 |
|
|
public static bool IsBranchLine(Line line1, Line line2)
|
539 |
|
|
{
|
540 |
|
|
bool result = true;
|
541 |
|
|
|
542 |
|
|
Connector conn1 = line1.CONNECTORS.Find(x => x.CONNECTEDITEM == line2.UID);
|
543 |
|
|
Connector conn2 = line2.CONNECTORS.Find(x => x.CONNECTEDITEM == line1.UID);
|
544 |
|
|
|
545 |
|
|
if (conn1 != null && conn2 != null)
|
546 |
|
|
result = false;
|
547 |
|
|
|
548 |
|
|
return result;
|
549 |
|
|
}
|
550 |
|
|
|
551 |
a0e3dca4
|
gaqhf
|
public static bool IsBranchLine(Line line)
|
552 |
|
|
{
|
553 |
9e781a4e
|
Denny
|
Connector connector = line.CONNECTORS.Find(x => x.ConnectedObject != null &&
|
554 |
|
|
x.ConnectedObject.GetType() == typeof(Line) &&
|
555 |
|
|
IsBranchLine(line, x.ConnectedObject as Line));
|
556 |
a0e3dca4
|
gaqhf
|
return connector != null ? true : false;
|
557 |
|
|
}
|
558 |
cf210438
|
gaqhf
|
|
559 |
9e781a4e
|
Denny
|
public static bool IsBranchStartLine(Line line)
|
560 |
|
|
{
|
561 |
|
|
bool result = false;
|
562 |
|
|
if (line.CONNECTORS[0].ConnectedObject != null && line.CONNECTORS[0].ConnectedObject.GetType() == typeof(Line))
|
563 |
|
|
{
|
564 |
|
|
Line connLine = line.CONNECTORS[0].ConnectedObject as Line;
|
565 |
|
|
if (!(connLine.CONNECTORS[1].ConnectedObject != null && connLine.CONNECTORS[1].ConnectedObject == line))
|
566 |
|
|
{
|
567 |
|
|
result = true;
|
568 |
|
|
}
|
569 |
|
|
}
|
570 |
|
|
return result;
|
571 |
|
|
}
|
572 |
|
|
|
573 |
cf210438
|
gaqhf
|
public static bool IsBranchedLine(Document document,Line line)
|
574 |
|
|
{
|
575 |
|
|
return document.LINES.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == line.UID && IsBranchLine(x, y.ConnectedObject as Line)) != null) != null ? true : false;
|
576 |
|
|
}
|
577 |
9e781a4e
|
Denny
|
public static Line FindOtherLine(Line line, Symbol symbol,int index, string prevSymbolUID = "")
|
578 |
|
|
{
|
579 |
|
|
Line result = null;
|
580 |
|
|
|
581 |
|
|
try
|
582 |
|
|
{
|
583 |
|
|
Connector connector = symbol.CONNECTORS.Find(x =>
|
584 |
|
|
x.ConnectedObject != null &&
|
585 |
|
|
x.ConnectedObject != line &&
|
586 |
|
|
x.ConnectedObject.GetType() == typeof(Line) &&
|
587 |
|
|
((line.SlopeType == ((Line)x.ConnectedObject).SlopeType &&
|
588 |
|
|
(line.SlopeType == SlopeType.VERTICAL && SPPIDUtil.IsNearValue(line.SPPID.START_X, ((Line)x.ConnectedObject).SPPID.START_X) ||
|
589 |
|
|
line.SlopeType == SlopeType.HORIZONTAL && SPPIDUtil.IsNearValue(line.SPPID.START_Y, ((Line)x.ConnectedObject).SPPID.START_Y))) ||
|
590 |
|
|
(line.SlopeType != ((Line)x.ConnectedObject).SlopeType &&
|
591 |
|
|
(symbol.CONNECTORS.Count == 2 || symbol.CONNECTORS.IndexOf(x) <= 1) &&
|
592 |
|
|
(SPPIDUtil.IsNearValue(symbol.SPPID.SPPID_X, ((Line)x.ConnectedObject).SPPID.START_X) ||
|
593 |
|
|
SPPIDUtil.IsNearValue(symbol.SPPID.SPPID_X, ((Line)x.ConnectedObject).SPPID.END_X) ||
|
594 |
|
|
SPPIDUtil.IsNearValue(symbol.SPPID.SPPID_Y, ((Line)x.ConnectedObject).SPPID.START_Y) ||
|
595 |
|
|
SPPIDUtil.IsNearValue(symbol.SPPID.SPPID_Y, ((Line)x.ConnectedObject).SPPID.END_Y))))
|
596 |
|
|
);
|
597 |
|
|
|
598 |
|
|
if (connector != null)
|
599 |
|
|
{
|
600 |
|
|
result = connector.ConnectedObject as Line;
|
601 |
|
|
Connector resConn = result.CONNECTORS.Find(f => f.ConnectedObject != null && f.ConnectedObject == symbol);
|
602 |
|
|
if (result.CONNECTORS.IndexOf(resConn) == index)
|
603 |
|
|
{
|
604 |
|
|
result = null ;
|
605 |
|
|
}
|
606 |
|
|
}
|
607 |
|
|
else
|
608 |
|
|
{
|
609 |
|
|
Connector connector1 = symbol.CONNECTORS.Find(x =>
|
610 |
|
|
x.ConnectedObject != null &&
|
611 |
|
|
x.ConnectedObject != line &&
|
612 |
|
|
x.ConnectedObject.GetType() == typeof(Symbol) &&
|
613 |
|
|
(string.IsNullOrEmpty(prevSymbolUID) || ((Symbol)x.ConnectedObject).UID != prevSymbolUID)
|
614 |
|
|
);
|
615 |
|
|
if (connector1 != null)
|
616 |
|
|
{
|
617 |
|
|
result = FindOtherLine(line, connector1.ConnectedObject as Symbol, index, symbol.UID);
|
618 |
|
|
}
|
619 |
|
|
}
|
620 |
|
|
}
|
621 |
|
|
catch (System.Exception ex)
|
622 |
|
|
{
|
623 |
|
|
Log.Write(string.Format("[{0}] {1}\r\n{2}", DateTime.Now, ex.Message, ex.StackTrace));
|
624 |
|
|
throw new System.Exception("Error", ex);
|
625 |
|
|
}
|
626 |
|
|
|
627 |
|
|
return result;
|
628 |
|
|
}
|
629 |
cf210438
|
gaqhf
|
|
630 |
6d12a734
|
gaqhf
|
public static void CalcOverlap(double[] range1, double[] range2, ref double x, ref double y, ref bool overlapX, ref bool overlapY)
|
631 |
d9794a6c
|
gaqhf
|
{
|
632 |
|
|
if (range1[0] <= range2[2] && range1[2] >= range2[0])
|
633 |
|
|
{
|
634 |
6d12a734
|
gaqhf
|
overlapX = true;
|
635 |
d9794a6c
|
gaqhf
|
x = Math.Min(Math.Abs(range1[0] - range2[2]), Math.Abs(range1[2] - range2[0]));
|
636 |
|
|
}
|
637 |
|
|
|
638 |
|
|
if (range1[1] <= range2[3] && range1[3] >= range2[1])
|
639 |
|
|
{
|
640 |
6d12a734
|
gaqhf
|
overlapY = true;
|
641 |
d9794a6c
|
gaqhf
|
y = Math.Min(Math.Abs(range1[1] - range2[3]), Math.Abs(range1[3] - range2[1]));
|
642 |
|
|
}
|
643 |
|
|
}
|
644 |
|
|
|
645 |
1299077b
|
gaqhf
|
public static bool IsOverlap(double[] range1, double[] range2)
|
646 |
|
|
{
|
647 |
|
|
if (range1[0] <= range2[2] && range1[2] >= range2[0] && range1[1] <= range2[3] && range1[3] >= range2[1])
|
648 |
|
|
return true;
|
649 |
|
|
else
|
650 |
|
|
return false;
|
651 |
|
|
}
|
652 |
|
|
|
653 |
d9794a6c
|
gaqhf
|
public static void CalcNewCoordinateForSymbol(Symbol symbol, Symbol prevSymbol, double distanceX, double distanceY)
|
654 |
|
|
{
|
655 |
|
|
SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
|
656 |
|
|
GridSetting _GridSetting = GridSetting.GetInstance();
|
657 |
|
|
if (slopeType == SlopeType.HORIZONTAL)
|
658 |
|
|
{
|
659 |
|
|
double length = (Math.Ceiling(distanceX / _GridSetting.Length) + 1) * _GridSetting.Length;
|
660 |
|
|
if (prevSymbol.SPPID.ORIGINAL_X < symbol.SPPID.ORIGINAL_X)
|
661 |
|
|
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + length;
|
662 |
|
|
else
|
663 |
|
|
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - length;
|
664 |
|
|
}
|
665 |
|
|
else if (slopeType == SlopeType.VERTICAL)
|
666 |
|
|
{
|
667 |
|
|
double length = (Math.Ceiling(distanceY / _GridSetting.Length) + 1) * _GridSetting.Length;
|
668 |
|
|
if (prevSymbol.SPPID.ORIGINAL_Y < symbol.SPPID.ORIGINAL_Y)
|
669 |
|
|
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + length;
|
670 |
|
|
else
|
671 |
|
|
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - length;
|
672 |
|
|
}
|
673 |
|
|
}
|
674 |
a0e3dca4
|
gaqhf
|
|
675 |
b2064e69
|
gaqhf
|
public static Line GetConnectedLine(Symbol symbol1, Symbol symbol2)
|
676 |
|
|
{
|
677 |
|
|
Line line = null;
|
678 |
|
|
Connector connector1 = symbol1.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) &&
|
679 |
|
|
((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol2) != null);
|
680 |
|
|
Connector connector2 = symbol2.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) &&
|
681 |
|
|
((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol1) != null);
|
682 |
|
|
if (connector1 != null && connector2 != null)
|
683 |
|
|
line = connector1.ConnectedObject as Line;
|
684 |
|
|
|
685 |
|
|
return line;
|
686 |
|
|
}
|
687 |
|
|
|
688 |
|
|
public static int GetBranchLineCount(Document document, Line line)
|
689 |
|
|
{
|
690 |
|
|
return document.LINES.FindAll(x => IsBranchLine(line, x) && x.CONNECTORS.Find(y => y.ConnectedObject == line) != null).Count;
|
691 |
|
|
}
|
692 |
|
|
|
693 |
a0e3dca4
|
gaqhf
|
public static bool GetLineConnectorPoint(Line line, Connector connector, ref double x, ref double y)
|
694 |
|
|
{
|
695 |
|
|
bool bStart = false;
|
696 |
|
|
int index = line.CONNECTORS.IndexOf(connector);
|
697 |
|
|
if (index == 0)
|
698 |
|
|
{
|
699 |
|
|
x = line.SPPID.START_X;
|
700 |
|
|
y = line.SPPID.START_Y;
|
701 |
|
|
bStart = true;
|
702 |
|
|
}
|
703 |
|
|
else
|
704 |
|
|
{
|
705 |
|
|
x = line.SPPID.END_X;
|
706 |
|
|
y = line.SPPID.END_Y;
|
707 |
|
|
}
|
708 |
|
|
return bStart;
|
709 |
|
|
}
|
710 |
dfac4553
|
gaqhf
|
|
711 |
d9fc7084
|
gaqhf
|
public static bool IsSegment(Document document, Line line1, Line line2)
|
712 |
dfac4553
|
gaqhf
|
{
|
713 |
|
|
bool result = false;
|
714 |
|
|
|
715 |
|
|
SpecBreak specBreak = document.SpecBreaks.Find(x =>
|
716 |
d9fc7084
|
gaqhf
|
(x.DownStreamUID == line1.UID && x.UpStreamUID == line2.UID) ||
|
717 |
|
|
(x.DownStreamUID == line2.UID && x.UpStreamUID == line1.UID));
|
718 |
dfac4553
|
gaqhf
|
|
719 |
|
|
EndBreak endBreak = document.EndBreaks.Find(x =>
|
720 |
d9fc7084
|
gaqhf
|
(x.OWNER == line1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line2.UID) ||
|
721 |
|
|
(x.OWNER == line2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line1.UID));
|
722 |
dfac4553
|
gaqhf
|
|
723 |
|
|
if (specBreak != null || endBreak != null)
|
724 |
|
|
result = true;
|
725 |
|
|
|
726 |
|
|
return result;
|
727 |
|
|
}
|
728 |
d23fe61b
|
gaqhf
|
|
729 |
d9fc7084
|
gaqhf
|
public static bool IsSegment(Document document, Symbol symbol1, Symbol symbol2)
|
730 |
32205389
|
gaqhf
|
{
|
731 |
|
|
bool result = false;
|
732 |
|
|
SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
|
733 |
d9fc7084
|
gaqhf
|
(x.DownStreamUID == symbol1.UID && x.UpStreamUID == symbol2.UID) ||
|
734 |
|
|
(x.DownStreamUID == symbol2.UID && x.UpStreamUID == symbol1.UID));
|
735 |
32205389
|
gaqhf
|
|
736 |
|
|
EndBreak startEndBreak = document.EndBreaks.Find(x =>
|
737 |
d9fc7084
|
gaqhf
|
(x.OWNER == symbol1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID) ||
|
738 |
|
|
(x.OWNER == symbol2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID));
|
739 |
32205389
|
gaqhf
|
|
740 |
|
|
if (startSpecBreak != null || startEndBreak != null)
|
741 |
|
|
result = true;
|
742 |
|
|
|
743 |
|
|
return result;
|
744 |
|
|
}
|
745 |
bd474049
|
Denny
|
public static void test(string representationId)
|
746 |
ea54adc8
|
gaqhf
|
{
|
747 |
|
|
Placement placement = new Placement();
|
748 |
|
|
LMADataSource dataSource = new LMADataSource();
|
749 |
bd474049
|
Denny
|
LMSymbol symbol = dataSource.GetSymbol(representationId);
|
750 |
518c7651
|
gaqhf
|
|
751 |
|
|
string[] array1 = new string[] { "", "Top" };
|
752 |
|
|
string[] array2 = new string[] { "", "0.005" };
|
753 |
|
|
placement.PIDApplyParameters(symbol.AsLMRepresentation(), array1, array2);
|
754 |
ea54adc8
|
gaqhf
|
|
755 |
|
|
ReleaseCOMObjects(dataSource);
|
756 |
|
|
}
|
757 |
|
|
public static DataTable GetUnitInfo()
|
758 |
|
|
{
|
759 |
|
|
LMADataSource dataSource = new LMADataSource();
|
760 |
9c451472
|
gaqhf
|
LMPlantGroups units = new LMPlantGroups();
|
761 |
ea54adc8
|
gaqhf
|
units.Collect(dataSource);
|
762 |
|
|
DataTable dt = new DataTable();
|
763 |
|
|
dt.Columns.Add("LEVEL", typeof(string));
|
764 |
|
|
dt.Columns.Add("SP_ID", typeof(string));
|
765 |
|
|
dt.Columns.Add("PARENTID", typeof(string));
|
766 |
|
|
dt.Columns.Add("NAME", typeof(string));
|
767 |
9c451472
|
gaqhf
|
|
768 |
|
|
foreach (LMPlantGroup unit in units)
|
769 |
ea54adc8
|
gaqhf
|
{
|
770 |
4d4dce52
|
esham21
|
object tt = unit.get_Dir_Path();
|
771 |
9c451472
|
gaqhf
|
if (tt.Equals(DBNull.Value))
|
772 |
|
|
continue;
|
773 |
4d4dce52
|
esham21
|
string dir = unit.get_Dir_Path();
|
774 |
ea54adc8
|
gaqhf
|
string[] array = dir.Split('\\');
|
775 |
|
|
List<string> parents = new List<string>();
|
776 |
|
|
string prevId = "-1";
|
777 |
|
|
for (int i = 1; i < array.Length; i++)
|
778 |
|
|
{
|
779 |
|
|
string name = array[i];
|
780 |
|
|
string uid = Guid.NewGuid().ToString();
|
781 |
|
|
DataRow[] rows = dt.Select(string.Format("LEVEL = '{0}' AND NAME = '{1}' AND PARENTID = '{2}'", i, name, prevId));
|
782 |
|
|
if (rows.Length == 0)
|
783 |
|
|
dt.Rows.Add(i, uid, prevId, name);
|
784 |
|
|
else
|
785 |
|
|
uid = rows[0]["SP_ID"].ToString();
|
786 |
|
|
prevId = uid;
|
787 |
|
|
}
|
788 |
|
|
}
|
789 |
|
|
|
790 |
|
|
dt.Columns.Remove("LEVEL");
|
791 |
|
|
|
792 |
|
|
ReleaseCOMObjects(units);
|
793 |
|
|
ReleaseCOMObjects(dataSource);
|
794 |
|
|
|
795 |
|
|
return dt;
|
796 |
|
|
}
|
797 |
|
|
public static string T_OPTIONSETTING_Value(string name)
|
798 |
|
|
{
|
799 |
|
|
string result = string.Empty;
|
800 |
|
|
LMADataSource dataSource = new LMADataSource();
|
801 |
|
|
LMOptionSettings settings = new LMOptionSettings();
|
802 |
|
|
|
803 |
|
|
LMAFilter filter = new LMAFilter();
|
804 |
|
|
LMACriterion criterion = new LMACriterion();
|
805 |
|
|
filter.ItemType = "OptionSetting";
|
806 |
|
|
criterion.SourceAttributeName = "NAME";
|
807 |
|
|
criterion.Operator = "=";
|
808 |
4d4dce52
|
esham21
|
criterion.set_ValueAttribute(name);
|
809 |
|
|
filter.get_Criteria().Add(criterion);
|
810 |
ea54adc8
|
gaqhf
|
settings.Collect(dataSource, Filter: filter);
|
811 |
|
|
|
812 |
|
|
foreach (LMOptionSetting item in settings)
|
813 |
|
|
{
|
814 |
4d4dce52
|
esham21
|
result = item.get_Value();
|
815 |
ea54adc8
|
gaqhf
|
break;
|
816 |
|
|
}
|
817 |
|
|
|
818 |
|
|
ReleaseCOMObjects(criterion);
|
819 |
|
|
ReleaseCOMObjects(filter);
|
820 |
|
|
ReleaseCOMObjects(settings);
|
821 |
|
|
ReleaseCOMObjects(dataSource);
|
822 |
|
|
return result;
|
823 |
|
|
}
|
824 |
|
|
|
825 |
a80baec5
|
gaqhf
|
public static string T_PLANTSETTING_Value(string name)
|
826 |
|
|
{
|
827 |
|
|
string result = string.Empty;
|
828 |
|
|
LMADataSource dataSource = new LMADataSource();
|
829 |
|
|
LMPlantSettings settings = new LMPlantSettings();
|
830 |
|
|
|
831 |
|
|
LMAFilter filter = new LMAFilter();
|
832 |
|
|
LMACriterion criterion = new LMACriterion();
|
833 |
|
|
filter.ItemType = "PlantSetting";
|
834 |
|
|
criterion.SourceAttributeName = "NAME";
|
835 |
|
|
criterion.Operator = "=";
|
836 |
4d4dce52
|
esham21
|
criterion.set_ValueAttribute(name);
|
837 |
|
|
filter.get_Criteria().Add(criterion);
|
838 |
a80baec5
|
gaqhf
|
settings.Collect(dataSource, Filter: filter);
|
839 |
|
|
|
840 |
|
|
foreach (LMPlantSetting item in settings)
|
841 |
|
|
{
|
842 |
4d4dce52
|
esham21
|
result = item.get_Value();
|
843 |
a80baec5
|
gaqhf
|
break;
|
844 |
|
|
}
|
845 |
|
|
|
846 |
|
|
ReleaseCOMObjects(criterion);
|
847 |
|
|
ReleaseCOMObjects(filter);
|
848 |
|
|
ReleaseCOMObjects(settings);
|
849 |
|
|
ReleaseCOMObjects(dataSource);
|
850 |
|
|
return result;
|
851 |
|
|
}
|
852 |
|
|
|
853 |
ea54adc8
|
gaqhf
|
public static void ReleaseCOMObjects(params object[] objVars)
|
854 |
|
|
{
|
855 |
|
|
int intNewRefCount = 0;
|
856 |
|
|
foreach (object obj in objVars)
|
857 |
|
|
{
|
858 |
|
|
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
|
859 |
|
|
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
|
860 |
|
|
}
|
861 |
|
|
}
|
862 |
86c0a45e
|
gaqhf
|
|
863 |
|
|
public static void BulkAttribute(LMADataSource dataSource, List<BulkAttribute> attributes, BulkAttributeItemType type)
|
864 |
|
|
{
|
865 |
|
|
switch (type)
|
866 |
|
|
{
|
867 |
|
|
case BulkAttributeItemType.PipeRun:
|
868 |
|
|
BulkAttribute_PipeRun();
|
869 |
|
|
break;
|
870 |
|
|
case BulkAttributeItemType.Symbol:
|
871 |
|
|
BulkAttribute_Symbol();
|
872 |
|
|
break;
|
873 |
|
|
default:
|
874 |
|
|
break;
|
875 |
|
|
}
|
876 |
|
|
void BulkAttribute_PipeRun()
|
877 |
|
|
{
|
878 |
|
|
string drawingId = dataSource.PIDMgr.Drawing.ID;
|
879 |
|
|
|
880 |
|
|
LMAFilter filter = new LMAFilter();
|
881 |
|
|
|
882 |
|
|
LMACriterion criterion = new LMACriterion();
|
883 |
|
|
criterion.SourceAttributeName = "REPRESENTATION.SP_DRAWINGID";
|
884 |
|
|
criterion.Operator = "=";
|
885 |
4d4dce52
|
esham21
|
criterion.set_ValueAttribute(drawingId);
|
886 |
|
|
filter.get_Criteria().Add(criterion);
|
887 |
86c0a45e
|
gaqhf
|
filter.ItemType = "PIPERUN";
|
888 |
|
|
|
889 |
|
|
LMACriterion criterion2 = new LMACriterion();
|
890 |
|
|
criterion2.SourceAttributeName = "REPRESENTATION.INSTOCKPILE";
|
891 |
|
|
criterion2.Operator = "=";
|
892 |
4d4dce52
|
esham21
|
criterion2.set_ValueAttribute("1");
|
893 |
86c0a45e
|
gaqhf
|
criterion2.Conjunctive = true;
|
894 |
4d4dce52
|
esham21
|
filter.get_Criteria().Add(criterion2);
|
895 |
86c0a45e
|
gaqhf
|
|
896 |
|
|
LMACriterion criterion3 = new LMACriterion();
|
897 |
|
|
criterion3.SourceAttributeName = "REPRESENTATION.ITEMSTATUS";
|
898 |
|
|
criterion3.Operator = "=";
|
899 |
4d4dce52
|
esham21
|
criterion3.set_ValueAttribute("1");
|
900 |
86c0a45e
|
gaqhf
|
criterion3.Conjunctive = true;
|
901 |
4d4dce52
|
esham21
|
filter.get_Criteria().Add(criterion3);
|
902 |
86c0a45e
|
gaqhf
|
|
903 |
|
|
LMPipeRuns items = new LMPipeRuns();
|
904 |
|
|
items.Collect(dataSource, Filter: filter);
|
905 |
|
|
|
906 |
|
|
foreach (LMPipeRun item in items)
|
907 |
|
|
{
|
908 |
|
|
foreach (var attribute in attributes)
|
909 |
|
|
{
|
910 |
|
|
if (item.Attributes[attribute.SPPIDAttributeName] != null)
|
911 |
4d4dce52
|
esham21
|
item.Attributes[attribute.SPPIDAttributeName].set_Value(attribute.Value);
|
912 |
86c0a45e
|
gaqhf
|
}
|
913 |
|
|
item.Commit();
|
914 |
|
|
}
|
915 |
|
|
|
916 |
|
|
ReleaseCOMObjects(items);
|
917 |
|
|
ReleaseCOMObjects(filter);
|
918 |
|
|
ReleaseCOMObjects(criterion);
|
919 |
|
|
ReleaseCOMObjects(criterion2);
|
920 |
|
|
ReleaseCOMObjects(criterion3);
|
921 |
|
|
}
|
922 |
|
|
void BulkAttribute_Symbol()
|
923 |
|
|
{
|
924 |
|
|
string drawingId = dataSource.PIDMgr.Drawing.ID;
|
925 |
|
|
|
926 |
|
|
LMAFilter filter = new LMAFilter();
|
927 |
|
|
|
928 |
|
|
LMACriterion criterion = new LMACriterion();
|
929 |
|
|
criterion.SourceAttributeName = "SP_DRAWINGID";
|
930 |
|
|
criterion.Operator = "=";
|
931 |
4d4dce52
|
esham21
|
criterion.set_ValueAttribute(drawingId);
|
932 |
|
|
filter.get_Criteria().Add(criterion);
|
933 |
86c0a45e
|
gaqhf
|
filter.ItemType = "SYMBOL";
|
934 |
|
|
|
935 |
|
|
LMACriterion criterion2 = new LMACriterion();
|
936 |
|
|
criterion2.SourceAttributeName = "INSTOCKPILE";
|
937 |
|
|
criterion2.Operator = "=";
|
938 |
4d4dce52
|
esham21
|
criterion2.set_ValueAttribute("1");
|
939 |
86c0a45e
|
gaqhf
|
criterion2.Conjunctive = true;
|
940 |
4d4dce52
|
esham21
|
filter.get_Criteria().Add(criterion2);
|
941 |
86c0a45e
|
gaqhf
|
|
942 |
|
|
LMACriterion criterion3 = new LMACriterion();
|
943 |
|
|
criterion3.SourceAttributeName = "ITEMSTATUS";
|
944 |
|
|
criterion3.Operator = "=";
|
945 |
4d4dce52
|
esham21
|
criterion3.set_ValueAttribute("1");
|
946 |
86c0a45e
|
gaqhf
|
criterion3.Conjunctive = true;
|
947 |
4d4dce52
|
esham21
|
filter.get_Criteria().Add(criterion3);
|
948 |
86c0a45e
|
gaqhf
|
|
949 |
|
|
LMSymbols items = new LMSymbols();
|
950 |
|
|
items.Collect(dataSource, Filter: filter);
|
951 |
|
|
|
952 |
|
|
foreach (LMSymbol item in items)
|
953 |
|
|
{
|
954 |
|
|
foreach (var attribute in attributes)
|
955 |
|
|
{
|
956 |
|
|
if (item.Attributes[attribute.SPPIDAttributeName] != null)
|
957 |
4d4dce52
|
esham21
|
item.Attributes[attribute.SPPIDAttributeName].set_Value(attribute.Value);
|
958 |
86c0a45e
|
gaqhf
|
}
|
959 |
|
|
item.Commit();
|
960 |
|
|
}
|
961 |
|
|
|
962 |
|
|
ReleaseCOMObjects(items);
|
963 |
|
|
ReleaseCOMObjects(filter);
|
964 |
|
|
ReleaseCOMObjects(criterion);
|
965 |
|
|
ReleaseCOMObjects(criterion2);
|
966 |
|
|
ReleaseCOMObjects(criterion3);
|
967 |
|
|
}
|
968 |
|
|
}
|
969 |
6b60e542
|
Denny
|
public static void UpdatePipeRunProperty(LMADataSource dataSource, Model.SPPID_PipeRunPropSetting setting)
|
970 |
|
|
{
|
971 |
|
|
string drawingId = dataSource.PIDMgr.Drawing.ID;
|
972 |
|
|
string type = setting.DataType.Substring(0, 1);
|
973 |
|
|
LMAFilter filter = new LMAFilter();
|
974 |
|
|
filter.ItemType = "PIPERUN";
|
975 |
|
|
|
976 |
|
|
LMACriterion criterionID = new LMACriterion();
|
977 |
|
|
criterionID.SourceAttributeName = "REPRESENTATION.SP_DRAWINGID";
|
978 |
|
|
criterionID.Operator = "=";
|
979 |
|
|
criterionID.set_ValueAttribute(drawingId);
|
980 |
|
|
filter.get_Criteria().Add(criterionID);
|
981 |
|
|
|
982 |
|
|
SetCriterionPipeRun(setting.Cond1_Name, setting.Cond1_Value, setting.Cond1_DataType);
|
983 |
|
|
if (!string.IsNullOrWhiteSpace(setting.Cond2_Name))
|
984 |
|
|
SetCriterionPipeRun(setting.Cond2_Name, setting.Cond2_Value, setting.Cond2_DataType);
|
985 |
|
|
|
986 |
|
|
LMPipeRuns items = new LMPipeRuns();
|
987 |
|
|
items.Collect(dataSource, Filter: filter);
|
988 |
|
|
|
989 |
|
|
foreach (LMPipeRun item in items)
|
990 |
|
|
{
|
991 |
|
|
if (item.Attributes[setting.Name] != null)
|
992 |
|
|
{
|
993 |
|
|
object oValue = null;
|
994 |
|
|
if (type == "S" || type == "C")
|
995 |
|
|
oValue = setting.Value;
|
996 |
|
|
else
|
997 |
|
|
oValue = Convert.ToDouble(setting.Value);
|
998 |
|
|
|
999 |
|
|
item.Attributes[setting.Name].set_Value(oValue);
|
1000 |
|
|
}
|
1001 |
|
|
try
|
1002 |
|
|
{
|
1003 |
|
|
item.Commit();
|
1004 |
|
|
}
|
1005 |
|
|
catch (Exception ex)
|
1006 |
|
|
{
|
1007 |
|
|
}
|
1008 |
|
|
}
|
1009 |
|
|
|
1010 |
|
|
ReleaseCOMObjects(items);
|
1011 |
|
|
ReleaseCOMObjects(filter);
|
1012 |
|
|
|
1013 |
|
|
void SetCriterionPipeRun(string condName, string condValue, string condDataType)
|
1014 |
|
|
{
|
1015 |
|
|
if (condValue.Contains("~"))
|
1016 |
|
|
{
|
1017 |
|
|
string[] value_Arr = condValue.Split('~');
|
1018 |
|
|
|
1019 |
|
|
object fromValue = GetPipeRunSiValue(dataSource, condName, value_Arr[0]);
|
1020 |
|
|
if (fromValue.GetType() == typeof(double))
|
1021 |
|
|
{
|
1022 |
|
|
double dfrom = Convert.ToDouble(fromValue);
|
1023 |
|
|
dfrom -= 0.000000000001;
|
1024 |
|
|
fromValue = dfrom;
|
1025 |
|
|
}
|
1026 |
|
|
object toValue = null;
|
1027 |
|
|
if (value_Arr.Length > 1)
|
1028 |
|
|
{
|
1029 |
|
|
toValue = GetPipeRunSiValue(dataSource, condName, value_Arr[1]);
|
1030 |
|
|
if (toValue.GetType() == typeof(double))
|
1031 |
|
|
{
|
1032 |
|
|
double dTo = Convert.ToDouble(toValue);
|
1033 |
|
|
dTo += 0.000000000001;
|
1034 |
|
|
toValue = dTo;
|
1035 |
|
|
}
|
1036 |
|
|
}
|
1037 |
|
|
|
1038 |
|
|
LMACriterion criterionFrom = new LMACriterion();
|
1039 |
|
|
criterionFrom.SourceAttributeName = condName;
|
1040 |
|
|
criterionFrom.Operator = ">";
|
1041 |
|
|
criterionFrom.set_ValueAttribute(fromValue);
|
1042 |
|
|
criterionFrom.Conjunctive = true;
|
1043 |
|
|
filter.get_Criteria().Add(criterionFrom);
|
1044 |
|
|
ReleaseCOMObjects(criterionFrom);
|
1045 |
|
|
|
1046 |
|
|
if (toValue != null)
|
1047 |
|
|
{
|
1048 |
|
|
LMACriterion criterionTo = new LMACriterion();
|
1049 |
|
|
criterionTo.SourceAttributeName = condName;
|
1050 |
|
|
criterionTo.Operator = "<";
|
1051 |
|
|
criterionTo.set_ValueAttribute(toValue);
|
1052 |
|
|
criterionTo.Conjunctive = true;
|
1053 |
|
|
filter.get_Criteria().Add(criterionTo);
|
1054 |
|
|
|
1055 |
|
|
ReleaseCOMObjects(criterionTo);
|
1056 |
|
|
}
|
1057 |
|
|
}
|
1058 |
|
|
else
|
1059 |
|
|
{
|
1060 |
|
|
LMACriterion criterion = new LMACriterion();
|
1061 |
|
|
criterion.SourceAttributeName = condName;
|
1062 |
|
|
criterion.Operator = "=";
|
1063 |
|
|
double dValue = 0;
|
1064 |
|
|
object oValue = condValue;
|
1065 |
|
|
if (condDataType.StartsWith("C"))
|
1066 |
|
|
{
|
1067 |
|
|
oValue = GetCodeIndex(condDataType, condValue.Trim());
|
1068 |
|
|
}
|
1069 |
|
|
else if (double.TryParse(condValue.Trim(), out dValue))
|
1070 |
|
|
{
|
1071 |
|
|
oValue = dValue;
|
1072 |
|
|
}
|
1073 |
|
|
else
|
1074 |
|
|
{
|
1075 |
|
|
oValue = GetPipeRunSiValue(dataSource, condName, condValue);
|
1076 |
|
|
}
|
1077 |
|
|
criterion.set_ValueAttribute(oValue);
|
1078 |
|
|
criterion.Conjunctive = true;
|
1079 |
|
|
filter.get_Criteria().Add(criterion);
|
1080 |
|
|
ReleaseCOMObjects(criterion);
|
1081 |
|
|
}
|
1082 |
|
|
ReleaseCOMObjects(criterionID);
|
1083 |
|
|
}
|
1084 |
|
|
}
|
1085 |
|
|
|
1086 |
|
|
private static object GetPipeRunSiValue(LMADataSource dataSource, string attributeName, string displayValue)
|
1087 |
|
|
{
|
1088 |
|
|
object valueObject = null;
|
1089 |
|
|
|
1090 |
|
|
if (PipeRun == null)
|
1091 |
|
|
{
|
1092 |
|
|
string drawingId = dataSource.PIDMgr.Drawing.ID;
|
1093 |
|
|
LMAFilter filter = new LMAFilter();
|
1094 |
|
|
LMACriterion criterion = new LMACriterion();
|
1095 |
|
|
criterion.SourceAttributeName = "REPRESENTATION.SP_DRAWINGID";
|
1096 |
|
|
criterion.Operator = "=";
|
1097 |
|
|
criterion.set_ValueAttribute(drawingId);
|
1098 |
|
|
filter.get_Criteria().Add(criterion);
|
1099 |
|
|
filter.ItemType = "PIPERUN";
|
1100 |
|
|
|
1101 |
|
|
LMPipeRuns items = new LMPipeRuns();
|
1102 |
|
|
items.Collect(dataSource, Filter: filter);
|
1103 |
|
|
|
1104 |
|
|
foreach (LMPipeRun run in items)
|
1105 |
|
|
{
|
1106 |
|
|
PipeRun = run;
|
1107 |
|
|
break;
|
1108 |
|
|
}
|
1109 |
|
|
ReleaseCOMObjects(criterion);
|
1110 |
|
|
ReleaseCOMObjects(criterion);
|
1111 |
|
|
ReleaseCOMObjects(items);
|
1112 |
|
|
}
|
1113 |
|
|
|
1114 |
|
|
if (PipeRun != null)
|
1115 |
|
|
{
|
1116 |
|
|
if (PipeRun.Attributes[attributeName] != null)
|
1117 |
|
|
{
|
1118 |
|
|
object prevValue = PipeRun.Attributes[attributeName].get_Value();
|
1119 |
|
|
PipeRun.Attributes[attributeName].set_Value(displayValue);
|
1120 |
|
|
valueObject = PipeRun.Attributes[attributeName].SIValue;
|
1121 |
|
|
PipeRun.Attributes[attributeName].set_Value(prevValue);
|
1122 |
|
|
}
|
1123 |
|
|
}
|
1124 |
|
|
|
1125 |
|
|
if (valueObject == null)
|
1126 |
|
|
{
|
1127 |
|
|
valueObject = displayValue;
|
1128 |
|
|
}
|
1129 |
|
|
return valueObject;
|
1130 |
|
|
}
|
1131 |
|
|
|
1132 |
|
|
private static void InitCodeList()
|
1133 |
|
|
{
|
1134 |
|
|
if (CodeListSet == null || CodeListSet.Count == 0)
|
1135 |
|
|
{
|
1136 |
|
|
CodeListSet = new List<SPPIDCodeList>();
|
1137 |
|
|
DataTable dt = SPPID_DB.GetSPPIDCodeList();
|
1138 |
|
|
try
|
1139 |
|
|
{
|
1140 |
|
|
Plaice.Placement placement = new Plaice.Placement();
|
1141 |
|
|
LMADataSource dataSource = placement.PIDDataSource;
|
1142 |
|
|
foreach (LMAEnumAttList item in dataSource.CodeLists)
|
1143 |
|
|
{
|
1144 |
|
|
DataRow[] rows = dt.Select(string.Format("ATTRIBUTE_DATATYPE = '{0}'", item.Name));
|
1145 |
|
|
foreach (DataRow row in rows)
|
1146 |
|
|
{
|
1147 |
|
|
string name = row["ATTRIBUTE_NAME"].ToString();
|
1148 |
|
|
if (CodeListSet.FirstOrDefault(x => x.Name.Equals(name)) == null)
|
1149 |
|
|
{
|
1150 |
|
|
SPPIDCodeList code = new SPPIDCodeList();
|
1151 |
|
|
code.Name = name;
|
1152 |
|
|
code.CodeName = item.Name;
|
1153 |
|
|
int nullIndex = item.EnumeratedAttributes.GetItemIndex("");
|
1154 |
|
|
if (nullIndex >= 0)
|
1155 |
|
|
{
|
1156 |
|
|
code.Values.Add(nullIndex, "");
|
1157 |
|
|
}
|
1158 |
|
|
foreach (LMAEnumeratedAttribute attr in item.EnumeratedAttributes)
|
1159 |
|
|
{
|
1160 |
|
|
if (attr.Name == "") continue;
|
1161 |
|
|
code.Values.Add(attr.Index, attr.Name);
|
1162 |
|
|
}
|
1163 |
|
|
|
1164 |
|
|
CodeListSet.Add(code);
|
1165 |
|
|
}
|
1166 |
|
|
}
|
1167 |
|
|
SPPIDUtil.ReleaseCOMObjects(item);
|
1168 |
|
|
}
|
1169 |
|
|
SPPIDUtil.ReleaseCOMObjects(dataSource);
|
1170 |
|
|
SPPIDUtil.ReleaseCOMObjects(placement);
|
1171 |
|
|
}
|
1172 |
|
|
catch (Exception ex)
|
1173 |
|
|
{
|
1174 |
|
|
MessageBox.Show(ex.Message);
|
1175 |
|
|
}
|
1176 |
|
|
}
|
1177 |
|
|
}
|
1178 |
|
|
public static SPPIDCodeList GetCodeList(string codeName)
|
1179 |
|
|
{
|
1180 |
|
|
InitCodeList();
|
1181 |
|
|
SPPIDCodeList findCodeList = CodeListSet.FirstOrDefault(f => f.CodeName == codeName);
|
1182 |
|
|
if (findCodeList == null)
|
1183 |
|
|
{
|
1184 |
|
|
findCodeList = CodeListSet.FirstOrDefault(f => f.Name == codeName);
|
1185 |
|
|
}
|
1186 |
|
|
|
1187 |
|
|
return findCodeList;
|
1188 |
|
|
}
|
1189 |
|
|
public static int GetCodeIndex(string codeName, string codeText)
|
1190 |
|
|
{
|
1191 |
|
|
int codeIndex = -1;
|
1192 |
|
|
InitCodeList();
|
1193 |
|
|
SPPIDCodeList findCodeList = CodeListSet.FirstOrDefault(f => f.CodeName == codeName);
|
1194 |
|
|
if (findCodeList != null && findCodeList.Values.ContainsValue(codeText))
|
1195 |
|
|
{
|
1196 |
|
|
codeIndex = findCodeList.Values.Where(w => w.Value == codeText).Select(s => s.Key).FirstOrDefault();
|
1197 |
|
|
}
|
1198 |
|
|
return codeIndex;
|
1199 |
|
|
}
|
1200 |
9e781a4e
|
Denny
|
public static bool IsNearValue(double value1, double value2)
|
1201 |
|
|
{
|
1202 |
|
|
double tolerance = 0.000019685;
|
1203 |
|
|
bool isNear = Math.Abs(value1 - value2) <= tolerance;
|
1204 |
|
|
return isNear;
|
1205 |
|
|
}
|
1206 |
23eb98bf
|
gaqhf
|
}
|
1207 |
|
|
} |