hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 06b40010
이력 | 보기 | 이력해설 | 다운로드 (9.99 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 |
|
14 |
namespace Converter.SPPID.Util |
15 |
{ |
16 |
public enum SlopeType |
17 |
{ |
18 |
Slope, |
19 |
HORIZONTAL, |
20 |
VERTICAL |
21 |
} |
22 |
public class SPPIDUtil |
23 |
{ |
24 |
public static bool ConvertToSPPIDInfo(string jsonString) |
25 |
{ |
26 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
27 |
try |
28 |
{ |
29 |
SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString); |
30 |
|
31 |
_SPPIDInfo.DBType = jsonSPPIDInfo.DBType; |
32 |
_SPPIDInfo.Service = jsonSPPIDInfo.Service; |
33 |
_SPPIDInfo.Site = jsonSPPIDInfo.Site; |
34 |
_SPPIDInfo.ServerIP = jsonSPPIDInfo.ServerIP; |
35 |
_SPPIDInfo.Port = jsonSPPIDInfo.Port; |
36 |
_SPPIDInfo.DBUser = jsonSPPIDInfo.DBUser; |
37 |
_SPPIDInfo.DBPassword = jsonSPPIDInfo.DBPassword; |
38 |
_SPPIDInfo.PlantPath = jsonSPPIDInfo.PlantPath; |
39 |
_SPPIDInfo.PlantDic = jsonSPPIDInfo.PlantDic; |
40 |
_SPPIDInfo.PlantPID = jsonSPPIDInfo.PlantPID; |
41 |
_SPPIDInfo.PlantPIDDic = jsonSPPIDInfo.PlantPIDDic; |
42 |
_SPPIDInfo.Plant = jsonSPPIDInfo.Plant; |
43 |
_SPPIDInfo.Enable = jsonSPPIDInfo.Enable; |
44 |
_SPPIDInfo.SelectedPlant = jsonSPPIDInfo.SelectedPlant; |
45 |
_SPPIDInfo.PlantList = jsonSPPIDInfo.PlantList; |
46 |
|
47 |
} |
48 |
catch (Exception ex) |
49 |
{ |
50 |
_SPPIDInfo.Enable = false; |
51 |
return false; |
52 |
} |
53 |
return true; |
54 |
} |
55 |
|
56 |
public static bool ConvertToETCSetting(string jsonString) |
57 |
{ |
58 |
ETCSetting _ETCSetting = ETCSetting.GetInstance(); |
59 |
try |
60 |
{ |
61 |
ETCSetting jsonETCSetting = JsonConvert.DeserializeObject<ETCSetting>(jsonString); |
62 |
|
63 |
_ETCSetting.NoteSymbolPath = jsonETCSetting.NoteSymbolPath; |
64 |
_ETCSetting.TextSymbolPath = jsonETCSetting.TextSymbolPath; |
65 |
_ETCSetting.DrainValveSize = jsonETCSetting.DrainValveSize; |
66 |
_ETCSetting.TextLocation = jsonETCSetting.TextLocation; |
67 |
_ETCSetting.NoteLocation = jsonETCSetting.NoteLocation; |
68 |
_ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation; |
69 |
|
70 |
} |
71 |
catch (Exception ex) |
72 |
{ |
73 |
return false; |
74 |
} |
75 |
return true; |
76 |
} |
77 |
|
78 |
public static bool ConvertToGridSetting(string jsonString) |
79 |
{ |
80 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
81 |
try |
82 |
{ |
83 |
GridSetting jsonGridSetting = JsonConvert.DeserializeObject<GridSetting>(jsonString); |
84 |
|
85 |
_GridSetting.UseSnapGrid = jsonGridSetting.UseSnapGrid; |
86 |
_GridSetting.Density = jsonGridSetting.Density; |
87 |
_GridSetting.Unit = jsonGridSetting.Unit; |
88 |
} |
89 |
catch (Exception ex) |
90 |
{ |
91 |
return false; |
92 |
} |
93 |
return true; |
94 |
} |
95 |
|
96 |
public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
97 |
{ |
98 |
try |
99 |
{ |
100 |
string[] pointArr = sPoint.Split(new char[] { ',' }); |
101 |
if (pointArr.Length == 2) |
102 |
{ |
103 |
dX = Convert.ToDouble(pointArr[0]); |
104 |
dY = Convert.ToDouble(pointArr[1]); |
105 |
} |
106 |
} |
107 |
catch (Exception) |
108 |
{ |
109 |
dX = 0; |
110 |
dY = 0; |
111 |
return false; |
112 |
} |
113 |
|
114 |
return true; |
115 |
} |
116 |
|
117 |
public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
118 |
{ |
119 |
decimal calcX = 0; |
120 |
decimal calcY = 0; |
121 |
decimal tempX = Convert.ToDecimal(dX); |
122 |
decimal tempY = Convert.ToDecimal(dY); |
123 |
decimal tempWidth = Convert.ToDecimal(SPPID_Width); |
124 |
decimal tempHeight = Convert.ToDecimal(SPPID_Height); |
125 |
decimal tempDwgX = Convert.ToDecimal(dDwgX); |
126 |
decimal tempDwgY = Convert.ToDecimal(dDwgY); |
127 |
|
128 |
//calcX = (tempX * tempWidth) / tempDwgX; |
129 |
//calcX = Math.Truncate(calcX * 1000) / 1000; |
130 |
//calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
131 |
//calcY = Math.Truncate(calcY * 1000) / 1000; |
132 |
//dX = Math.Round(Convert.ToDouble(calcX), 10); |
133 |
//dY = Math.Round(Convert.ToDouble(calcY), 10); |
134 |
|
135 |
calcX = (tempX * tempWidth) / tempDwgX; |
136 |
calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
137 |
dX = Convert.ToDouble(calcX); |
138 |
dY = Convert.ToDouble(calcY); |
139 |
} |
140 |
|
141 |
public static void ConvertGridPoint(ref double x, ref double y) |
142 |
{ |
143 |
GridSetting _GridSetting = GridSetting.GetInstance(); |
144 |
if (_GridSetting.UseSnapGrid) |
145 |
{ |
146 |
if (_GridSetting.Unit == GridUnit.Inch) |
147 |
{ |
148 |
double length = _GridSetting.Density * 0.0254; |
149 |
double tempX = x; |
150 |
double tempY = y; |
151 |
x = Math.Round(tempX / length) * length; |
152 |
y = Math.Round(tempY / length) * length; |
153 |
} |
154 |
} |
155 |
} |
156 |
|
157 |
public static SlopeType CalcSlope(double x1, double y1, double x2, double y2) |
158 |
{ |
159 |
if (x1 - x2 == 0) |
160 |
{ |
161 |
return SlopeType.VERTICAL; |
162 |
} |
163 |
else |
164 |
{ |
165 |
double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
166 |
if (angle <= 2) |
167 |
return SlopeType.HORIZONTAL; |
168 |
else if (angle >= 88) |
169 |
return SlopeType.VERTICAL; |
170 |
else |
171 |
return SlopeType.Slope; |
172 |
} |
173 |
} |
174 |
|
175 |
public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y) |
176 |
{ |
177 |
|
178 |
double distance = 0; |
179 |
if (lineX1 == lineX2) |
180 |
distance = Math.Abs(x - lineX1); |
181 |
else |
182 |
{ |
183 |
double a; |
184 |
double b; |
185 |
double c; |
186 |
|
187 |
a = (lineY2 - lineY1) / (lineX2 - lineX1); |
188 |
b = -1; |
189 |
c = -a * lineX1 + lineY1; |
190 |
|
191 |
distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5); |
192 |
} |
193 |
return distance; |
194 |
} |
195 |
|
196 |
public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) |
197 |
{ |
198 |
x1 = Math.Round(x1, 10); |
199 |
x2 = Math.Round(x2, 10); |
200 |
x3 = Math.Round(x3, 10); |
201 |
x4 = Math.Round(x4, 10); |
202 |
|
203 |
y1 = Math.Round(y1, 10); |
204 |
y2 = Math.Round(y2, 10); |
205 |
y3 = Math.Round(y3, 10); |
206 |
y4 = Math.Round(y4, 10); |
207 |
|
208 |
double a1; |
209 |
double a2; |
210 |
double b1; |
211 |
double b2; |
212 |
|
213 |
if (x1 == x2) |
214 |
a1 = 0; |
215 |
else |
216 |
a1 = (y2 - y1) / (x2 - x1); |
217 |
if (x3 == x4) |
218 |
a2 = 0; |
219 |
else |
220 |
a2 = (y4 - y3) / (x4 - x3); |
221 |
|
222 |
b1 = -a1 * x1 + y1; |
223 |
b2 = -a2 * x3 + y3; |
224 |
|
225 |
if ((x1 == x2 && x3 == x4) || |
226 |
(y1 == y2 && y3 == y4)) |
227 |
{ |
228 |
return null; |
229 |
} |
230 |
else if (x1 == x2) |
231 |
{ |
232 |
return new double[] { x1, a2*x1 + b2 }; |
233 |
} |
234 |
else if (x3 == x4) |
235 |
{ |
236 |
return new double[] { x3, a1 * x3 + b1 }; |
237 |
} |
238 |
else |
239 |
{ |
240 |
return new double[] { -(b1 - b2) / (a1 - a2), a1 * (-(b1 - b2) / (a1 - a2) + b1) }; |
241 |
} |
242 |
} |
243 |
public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2) |
244 |
{ |
245 |
return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5); |
246 |
} |
247 |
|
248 |
#region |
249 |
public static bool IsBranchLine(string UID, Line connectedLine) |
250 |
{ |
251 |
try |
252 |
{ |
253 |
if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID) |
254 |
return true; |
255 |
} |
256 |
catch (Exception ex) |
257 |
{ |
258 |
|
259 |
} |
260 |
|
261 |
return false; |
262 |
} |
263 |
public static object FindObjectByUID(Document document, string UID) |
264 |
{ |
265 |
foreach (Symbol item in document.SYMBOLS) |
266 |
{ |
267 |
if (item.UID == UID) |
268 |
return item; |
269 |
} |
270 |
|
271 |
foreach (Line item in document.LINES) |
272 |
{ |
273 |
if (item.UID == UID) |
274 |
return item; |
275 |
} |
276 |
|
277 |
foreach (Text item in document.TEXTINFOS) |
278 |
{ |
279 |
if (item.UID == UID) |
280 |
return item; |
281 |
} |
282 |
|
283 |
foreach (Note item in document.NOTES) |
284 |
{ |
285 |
if (item.UID == UID) |
286 |
return item; |
287 |
} |
288 |
|
289 |
foreach (LineNumber item in document.LINENUMBERS) |
290 |
{ |
291 |
if (item.UID == UID) |
292 |
return item; |
293 |
} |
294 |
|
295 |
foreach (Equipment item in document.Equipments) |
296 |
{ |
297 |
if (item.UID == UID) |
298 |
return item; |
299 |
} |
300 |
|
301 |
return null; |
302 |
} |
303 |
public static List<Line> FindLinesByModelId(Document document, string ModelItemId) |
304 |
{ |
305 |
List<Line> lines = new List<Line>(); |
306 |
foreach (Line item in document.LINES) |
307 |
{ |
308 |
if (item.SPPID.ModelItemId == ModelItemId) |
309 |
lines.Add(item); |
310 |
} |
311 |
|
312 |
return lines; |
313 |
} |
314 |
#endregion |
315 |
} |
316 |
} |