hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 5e6ecf05
이력 | 보기 | 이력해설 | 다운로드 (6.48 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 |
|
67 |
} |
68 |
catch (Exception ex) |
69 |
{ |
70 |
return false; |
71 |
} |
72 |
return true; |
73 |
} |
74 |
|
75 |
public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
76 |
{ |
77 |
try |
78 |
{ |
79 |
string[] pointArr = sPoint.Split(new char[] { ',' }); |
80 |
if (pointArr.Length == 2) |
81 |
{ |
82 |
dX = Convert.ToDouble(pointArr[0]); |
83 |
dY = Convert.ToDouble(pointArr[1]); |
84 |
} |
85 |
} |
86 |
catch (Exception) |
87 |
{ |
88 |
dX = 0; |
89 |
dY = 0; |
90 |
return false; |
91 |
} |
92 |
|
93 |
return true; |
94 |
} |
95 |
|
96 |
public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
97 |
{ |
98 |
decimal calcX = 0; |
99 |
decimal calcY = 0; |
100 |
decimal tempX = Convert.ToDecimal(dX); |
101 |
decimal tempY = Convert.ToDecimal(dY); |
102 |
decimal tempWidth = Convert.ToDecimal(SPPID_Width); |
103 |
decimal tempHeight = Convert.ToDecimal(SPPID_Height); |
104 |
decimal tempDwgX = Convert.ToDecimal(dDwgX); |
105 |
decimal tempDwgY = Convert.ToDecimal(dDwgY); |
106 |
|
107 |
calcX = (tempX * tempWidth) / tempDwgX; |
108 |
calcX = Math.Truncate(calcX * 1000) / 1000; |
109 |
calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
110 |
calcY = Math.Truncate(calcY * 1000) / 1000; |
111 |
dX = Convert.ToDouble(calcX); |
112 |
dY = Convert.ToDouble(calcY); |
113 |
} |
114 |
|
115 |
public static SlopeType CalcSlope(double x1, double y1, double x2, double y2) |
116 |
{ |
117 |
if (x1 - x2 == 0) |
118 |
{ |
119 |
return SlopeType.VERTICAL; |
120 |
} |
121 |
else |
122 |
{ |
123 |
double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
124 |
if (angle < 5) |
125 |
return SlopeType.HORIZONTAL; |
126 |
else if (angle > 85) |
127 |
return SlopeType.VERTICAL; |
128 |
else |
129 |
return SlopeType.Slope; |
130 |
} |
131 |
} |
132 |
|
133 |
public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y) |
134 |
{ |
135 |
|
136 |
double distance = 0; |
137 |
if (lineX1 == lineX2) |
138 |
distance = Math.Abs(x - lineX1); |
139 |
else |
140 |
{ |
141 |
double a; |
142 |
double b; |
143 |
double c; |
144 |
|
145 |
a = (lineY2 - lineY1) / (lineX2 - lineX1); |
146 |
b = -1; |
147 |
c = -a * lineX1 + lineY1; |
148 |
|
149 |
distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5); |
150 |
} |
151 |
return distance; |
152 |
} |
153 |
|
154 |
#region |
155 |
public static bool IsBranchLine(string UID, Line connectedLine) |
156 |
{ |
157 |
try |
158 |
{ |
159 |
if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID) |
160 |
return true; |
161 |
} |
162 |
catch (Exception ex) |
163 |
{ |
164 |
|
165 |
} |
166 |
|
167 |
return false; |
168 |
} |
169 |
public static object FindObjectByUID(Document document, string UID) |
170 |
{ |
171 |
foreach (Symbol item in document.SYMBOLS) |
172 |
{ |
173 |
if (item.UID == UID) |
174 |
return item; |
175 |
} |
176 |
|
177 |
foreach (Line item in document.LINES) |
178 |
{ |
179 |
if (item.UID == UID) |
180 |
return item; |
181 |
} |
182 |
|
183 |
foreach (Text item in document.TEXTINFOS) |
184 |
{ |
185 |
if (item.UID == UID) |
186 |
return item; |
187 |
} |
188 |
|
189 |
foreach (Note item in document.NOTES) |
190 |
{ |
191 |
if (item.UID == UID) |
192 |
return item; |
193 |
} |
194 |
|
195 |
foreach (LineNumber item in document.LINENUMBERS) |
196 |
{ |
197 |
if (item.UID == UID) |
198 |
return item; |
199 |
} |
200 |
|
201 |
foreach (Equipment item in document.Equipments) |
202 |
{ |
203 |
if (item.UID == UID) |
204 |
return item; |
205 |
} |
206 |
|
207 |
return null; |
208 |
} |
209 |
#endregion |
210 |
} |
211 |
} |