프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ a7e9beec

이력 | 보기 | 이력해설 | 다운로드 (8.38 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 56bc67e1 gaqhf
            dX = Math.Round(Convert.ToDouble(calcX), 10);
112
            dY = Math.Round(Convert.ToDouble(calcY), 10);
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 5e6ecf05 gaqhf
        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 56bc67e1 gaqhf
        public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
155
        {
156
            x1 = Math.Round(x1, 10);
157
            x2 = Math.Round(x2, 10);
158
            x3 = Math.Round(x3, 10);
159
            x4 = Math.Round(x4, 10);
160
161
            y1 = Math.Round(y1, 10);
162
            y2 = Math.Round(y2, 10);
163
            y3 = Math.Round(y3, 10);
164
            y4 = Math.Round(y4, 10);
165
166
            double a1;
167
            double a2;
168
            double b1;
169
            double b2;
170
171
            if (x1 == x2)
172
                a1 = 0;
173
            else
174
                a1 = (y2 - y1) / (x2 - x1);
175
            if (x3 == x4)
176
                a2 = 0;
177
            else
178
                a2 = (y4 - y3) / (x4 - x3);
179
180
            b1 = -a1 * x1 + y1;
181
            b2 = -a2 * x3 + y3;
182
183
            if ((x1 == x2 && x3 == x4) ||
184
                (y1 == y2 && y3 == y4))
185
            {
186
                return null;
187
            }
188
            else if (x1 == x2)
189
            {
190
                return new double[] { x1, a2*x1 + b2 };
191
            }
192
            else if (x3 == x4)
193
            {
194
                return new double[] { x3, a1 * x3 + b1 };
195
            }
196
            else
197
            {
198
                return new double[] { -(b1 - b2) / (a1 - a2), a1 * (-(b1 - b2) / (a1 - a2) + b1) };
199
            }
200
        }
201 30a9ffce gaqhf
        public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
202
        {
203
            return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
204
        }
205
206 bca81f4c gaqhf
        #region
207
        public static bool IsBranchLine(string UID, Line connectedLine)
208
        {
209
            try
210
            {
211
                if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID)
212
                    return true;
213
            }
214
            catch (Exception ex)
215
            {
216
                
217
            }
218
219
            return false;
220
        }
221
        public static object FindObjectByUID(Document document, string UID)
222
        {
223
            foreach (Symbol item in document.SYMBOLS)
224
            {
225
                if (item.UID == UID)
226
                    return item;
227
            }
228
229
            foreach (Line item in document.LINES)
230
            {
231
                if (item.UID == UID)
232
                    return item;
233
            }
234
235
            foreach (Text item in document.TEXTINFOS)
236
            {
237
                if (item.UID == UID)
238
                    return item;
239
            }
240
241
            foreach (Note item in document.NOTES)
242
            {
243
                if (item.UID == UID)
244
                    return item;
245
            }
246
247
            foreach (LineNumber item in document.LINENUMBERS)
248
            {
249
                if (item.UID == UID)
250
                    return item;
251
            }
252
253 809a7640 gaqhf
            foreach (Equipment item in document.Equipments)
254
            {
255
                if (item.UID == UID)
256
                    return item;
257
            }
258
259 bca81f4c gaqhf
            return null;
260
        }
261 335b7a24 gaqhf
        public static List<Line> FindLinesByModelId(Document document, string ModelItemId)
262
        {
263
            List<Line> lines = new List<Line>();
264
            foreach (Line item in document.LINES)
265
            {
266
                if (item.SPPID.ModelItemId == ModelItemId)
267
                    lines.Add(item);
268
            }
269
270
            return lines;
271
        }
272 bca81f4c gaqhf
        #endregion
273 23eb98bf gaqhf
    }
274
}
클립보드 이미지 추가 (최대 크기: 500 MB)