hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 1b261371
이력 | 보기 | 이력해설 | 다운로드 (5.7 KB)
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 | 23eb98bf | gaqhf | |
14 | b8e2644e | gaqhf | namespace Converter.SPPID.Util |
15 | 23eb98bf | gaqhf | { |
16 | 5dfb8a24 | gaqhf | public enum SlopeType |
17 | { |
||
18 | Slope, |
||
19 | HORIZONTAL, |
||
20 | VERTICAL |
||
21 | } |
||
22 | 23eb98bf | gaqhf | public class SPPIDUtil |
23 | { |
||
24 | fab4f207 | gaqhf | public static bool ConvertToSPPIDInfo(string jsonString) |
25 | 23eb98bf | gaqhf | { |
26 | 2e1e3c12 | gaqhf | SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
27 | 23eb98bf | gaqhf | try |
28 | { |
||
29 | fab4f207 | gaqhf | SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString); |
30 | 23eb98bf | gaqhf | |
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 | fab4f207 | gaqhf | _SPPIDInfo.Enable = false; |
51 | 23eb98bf | gaqhf | return false; |
52 | } |
||
53 | return true; |
||
54 | } |
||
55 | 5dfb8a24 | gaqhf | |
56 | e00e891d | gaqhf | 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 | bca81f4c | gaqhf | |
75 | 39a2a688 | gaqhf | 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 | bca81f4c | gaqhf | |
96 | 39a2a688 | gaqhf | public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
97 | { |
||
98 | 1b261371 | gaqhf | 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 | 39a2a688 | gaqhf | calcX = Math.Truncate(calcX * 1000) / 1000; |
109 | 1b261371 | gaqhf | calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
110 | 39a2a688 | gaqhf | calcY = Math.Truncate(calcY * 1000) / 1000; |
111 | 1b261371 | gaqhf | dX = Convert.ToDouble(calcX); |
112 | dY = Convert.ToDouble(calcY); |
||
113 | 39a2a688 | gaqhf | } |
114 | bca81f4c | gaqhf | |
115 | 5dfb8a24 | gaqhf | 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 | 1b261371 | gaqhf | if (angle < 5) |
125 | 5dfb8a24 | gaqhf | return SlopeType.HORIZONTAL; |
126 | 1b261371 | gaqhf | else if (angle > 85) |
127 | 5dfb8a24 | gaqhf | return SlopeType.VERTICAL; |
128 | else |
||
129 | return SlopeType.Slope; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | bca81f4c | gaqhf | #region |
134 | public static bool IsBranchLine(string UID, Line connectedLine) |
||
135 | { |
||
136 | try |
||
137 | { |
||
138 | if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID) |
||
139 | return true; |
||
140 | } |
||
141 | catch (Exception ex) |
||
142 | { |
||
143 | |||
144 | } |
||
145 | |||
146 | return false; |
||
147 | } |
||
148 | public static object FindObjectByUID(Document document, string UID) |
||
149 | { |
||
150 | foreach (Symbol item in document.SYMBOLS) |
||
151 | { |
||
152 | if (item.UID == UID) |
||
153 | return item; |
||
154 | } |
||
155 | |||
156 | foreach (Line item in document.LINES) |
||
157 | { |
||
158 | if (item.UID == UID) |
||
159 | return item; |
||
160 | } |
||
161 | |||
162 | foreach (Text item in document.TEXTINFOS) |
||
163 | { |
||
164 | if (item.UID == UID) |
||
165 | return item; |
||
166 | } |
||
167 | |||
168 | foreach (Note item in document.NOTES) |
||
169 | { |
||
170 | if (item.UID == UID) |
||
171 | return item; |
||
172 | } |
||
173 | |||
174 | foreach (LineNumber item in document.LINENUMBERS) |
||
175 | { |
||
176 | if (item.UID == UID) |
||
177 | return item; |
||
178 | } |
||
179 | |||
180 | return null; |
||
181 | } |
||
182 | #endregion |
||
183 | 23eb98bf | gaqhf | } |
184 | } |