프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (8.82 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 1a3a74a8 gaqhf
                _ETCSetting.TextLocation = jsonETCSetting.TextLocation;
67
                _ETCSetting.NoteLocation = jsonETCSetting.NoteLocation;
68
                _ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation;
69 e00e891d gaqhf
70
            }
71
            catch (Exception ex)
72
            {
73
                return false;
74
            }
75
            return true;
76
        }
77 bca81f4c gaqhf
78 39a2a688 gaqhf
        public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY)
79
        {
80
            try
81
            {
82
                string[] pointArr = sPoint.Split(new char[] { ',' });
83
                if (pointArr.Length == 2)
84
                {
85
                    dX = Convert.ToDouble(pointArr[0]);
86
                    dY = Convert.ToDouble(pointArr[1]);
87
                }
88
            }
89
            catch (Exception)
90
            {
91
                dX = 0;
92
                dY = 0;
93
                return false;
94
            }
95
96
            return true;
97
        }
98 bca81f4c gaqhf
99 39a2a688 gaqhf
        public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height)
100
        {
101 1b261371 gaqhf
            decimal calcX = 0;
102
            decimal calcY = 0;
103
            decimal tempX = Convert.ToDecimal(dX);
104
            decimal tempY = Convert.ToDecimal(dY);
105
            decimal tempWidth = Convert.ToDecimal(SPPID_Width);
106
            decimal tempHeight = Convert.ToDecimal(SPPID_Height);
107
            decimal tempDwgX = Convert.ToDecimal(dDwgX);
108
            decimal tempDwgY = Convert.ToDecimal(dDwgY);
109
110 c3d2e266 gaqhf
            //calcX = (tempX * tempWidth) / tempDwgX;
111
            //calcX = Math.Truncate(calcX * 1000) / 1000;
112
            //calcY = tempHeight - ((tempY * tempHeight) / tempDwgY);
113
            //calcY = Math.Truncate(calcY * 1000) / 1000;
114
            //dX = Math.Round(Convert.ToDouble(calcX), 10);
115
            //dY = Math.Round(Convert.ToDouble(calcY), 10);
116
117 1b261371 gaqhf
            calcX = (tempX * tempWidth) / tempDwgX;
118
            calcY = tempHeight - ((tempY * tempHeight) / tempDwgY);
119 c3d2e266 gaqhf
            dX = Convert.ToDouble(calcX);
120
            dY = Convert.ToDouble(calcY);
121 39a2a688 gaqhf
        }
122 bca81f4c gaqhf
123 5dfb8a24 gaqhf
        public static SlopeType CalcSlope(double x1, double y1, double x2, double y2)
124
        {
125
            if (x1 - x2 == 0)
126
            {
127
                return SlopeType.VERTICAL;
128
            }
129
            else
130
            {
131
                double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
132 c3d2e266 gaqhf
                if (angle <= 2)
133 5dfb8a24 gaqhf
                    return SlopeType.HORIZONTAL;
134 c3d2e266 gaqhf
                else if (angle >= 88)
135 5dfb8a24 gaqhf
                    return SlopeType.VERTICAL;
136
                else
137
                    return SlopeType.Slope;
138
            }
139
        }
140
141 5e6ecf05 gaqhf
        public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y)
142
        {
143
144
            double distance = 0;
145
            if (lineX1 == lineX2)
146
                distance = Math.Abs(x - lineX1);
147
            else
148
            {
149
                double a;
150
                double b;
151
                double c;
152
153
                a = (lineY2 - lineY1) / (lineX2 - lineX1);
154
                b = -1;
155
                c = -a * lineX1 + lineY1;
156
157
                distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5);
158
            }
159
            return distance;
160
        }
161
162 56bc67e1 gaqhf
        public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
163
        {
164
            x1 = Math.Round(x1, 10);
165
            x2 = Math.Round(x2, 10);
166
            x3 = Math.Round(x3, 10);
167
            x4 = Math.Round(x4, 10);
168
169
            y1 = Math.Round(y1, 10);
170
            y2 = Math.Round(y2, 10);
171
            y3 = Math.Round(y3, 10);
172
            y4 = Math.Round(y4, 10);
173
174
            double a1;
175
            double a2;
176
            double b1;
177
            double b2;
178
179
            if (x1 == x2)
180
                a1 = 0;
181
            else
182
                a1 = (y2 - y1) / (x2 - x1);
183
            if (x3 == x4)
184
                a2 = 0;
185
            else
186
                a2 = (y4 - y3) / (x4 - x3);
187
188
            b1 = -a1 * x1 + y1;
189
            b2 = -a2 * x3 + y3;
190
191
            if ((x1 == x2 && x3 == x4) ||
192
                (y1 == y2 && y3 == y4))
193
            {
194
                return null;
195
            }
196
            else if (x1 == x2)
197
            {
198
                return new double[] { x1, a2*x1 + b2 };
199
            }
200
            else if (x3 == x4)
201
            {
202
                return new double[] { x3, a1 * x3 + b1 };
203
            }
204
            else
205
            {
206
                return new double[] { -(b1 - b2) / (a1 - a2), a1 * (-(b1 - b2) / (a1 - a2) + b1) };
207
            }
208
        }
209 30a9ffce gaqhf
        public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
210
        {
211
            return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
212
        }
213
214 bca81f4c gaqhf
        #region
215
        public static bool IsBranchLine(string UID, Line connectedLine)
216
        {
217
            try
218
            {
219
                if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID)
220
                    return true;
221
            }
222
            catch (Exception ex)
223
            {
224
                
225
            }
226
227
            return false;
228
        }
229
        public static object FindObjectByUID(Document document, string UID)
230
        {
231
            foreach (Symbol item in document.SYMBOLS)
232
            {
233
                if (item.UID == UID)
234
                    return item;
235
            }
236
237
            foreach (Line item in document.LINES)
238
            {
239
                if (item.UID == UID)
240
                    return item;
241
            }
242
243
            foreach (Text item in document.TEXTINFOS)
244
            {
245
                if (item.UID == UID)
246
                    return item;
247
            }
248
249
            foreach (Note item in document.NOTES)
250
            {
251
                if (item.UID == UID)
252
                    return item;
253
            }
254
255
            foreach (LineNumber item in document.LINENUMBERS)
256
            {
257
                if (item.UID == UID)
258
                    return item;
259
            }
260
261 809a7640 gaqhf
            foreach (Equipment item in document.Equipments)
262
            {
263
                if (item.UID == UID)
264
                    return item;
265
            }
266
267 bca81f4c gaqhf
            return null;
268
        }
269 335b7a24 gaqhf
        public static List<Line> FindLinesByModelId(Document document, string ModelItemId)
270
        {
271
            List<Line> lines = new List<Line>();
272
            foreach (Line item in document.LINES)
273
            {
274
                if (item.SPPID.ModelItemId == ModelItemId)
275
                    lines.Add(item);
276
            }
277
278
            return lines;
279
        }
280 bca81f4c gaqhf
        #endregion
281 23eb98bf gaqhf
    }
282
}
클립보드 이미지 추가 (최대 크기: 500 MB)