프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 1a3a74a8

이력 | 보기 | 이력해설 | 다운로드 (8.61 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 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

    
99
        public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height)
100
        {
101
            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
            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

    
118
        public static SlopeType CalcSlope(double x1, double y1, double x2, double y2)
119
        {
120
            if (x1 - x2 == 0)
121
            {
122
                return SlopeType.VERTICAL;
123
            }
124
            else
125
            {
126
                double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
127
                if (angle <= 1)
128
                    return SlopeType.HORIZONTAL;
129
                else if (angle >= 89)
130
                    return SlopeType.VERTICAL;
131
                else
132
                    return SlopeType.Slope;
133
            }
134
        }
135

    
136
        public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y)
137
        {
138

    
139
            double distance = 0;
140
            if (lineX1 == lineX2)
141
                distance = Math.Abs(x - lineX1);
142
            else
143
            {
144
                double a;
145
                double b;
146
                double c;
147

    
148
                a = (lineY2 - lineY1) / (lineX2 - lineX1);
149
                b = -1;
150
                c = -a * lineX1 + lineY1;
151

    
152
                distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5);
153
            }
154
            return distance;
155
        }
156

    
157
        public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
158
        {
159
            x1 = Math.Round(x1, 10);
160
            x2 = Math.Round(x2, 10);
161
            x3 = Math.Round(x3, 10);
162
            x4 = Math.Round(x4, 10);
163

    
164
            y1 = Math.Round(y1, 10);
165
            y2 = Math.Round(y2, 10);
166
            y3 = Math.Round(y3, 10);
167
            y4 = Math.Round(y4, 10);
168

    
169
            double a1;
170
            double a2;
171
            double b1;
172
            double b2;
173

    
174
            if (x1 == x2)
175
                a1 = 0;
176
            else
177
                a1 = (y2 - y1) / (x2 - x1);
178
            if (x3 == x4)
179
                a2 = 0;
180
            else
181
                a2 = (y4 - y3) / (x4 - x3);
182

    
183
            b1 = -a1 * x1 + y1;
184
            b2 = -a2 * x3 + y3;
185

    
186
            if ((x1 == x2 && x3 == x4) ||
187
                (y1 == y2 && y3 == y4))
188
            {
189
                return null;
190
            }
191
            else if (x1 == x2)
192
            {
193
                return new double[] { x1, a2*x1 + b2 };
194
            }
195
            else if (x3 == x4)
196
            {
197
                return new double[] { x3, a1 * x3 + b1 };
198
            }
199
            else
200
            {
201
                return new double[] { -(b1 - b2) / (a1 - a2), a1 * (-(b1 - b2) / (a1 - a2) + b1) };
202
            }
203
        }
204
        public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
205
        {
206
            return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
207
        }
208

    
209
        #region
210
        public static bool IsBranchLine(string UID, Line connectedLine)
211
        {
212
            try
213
            {
214
                if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID)
215
                    return true;
216
            }
217
            catch (Exception ex)
218
            {
219
                
220
            }
221

    
222
            return false;
223
        }
224
        public static object FindObjectByUID(Document document, string UID)
225
        {
226
            foreach (Symbol item in document.SYMBOLS)
227
            {
228
                if (item.UID == UID)
229
                    return item;
230
            }
231

    
232
            foreach (Line item in document.LINES)
233
            {
234
                if (item.UID == UID)
235
                    return item;
236
            }
237

    
238
            foreach (Text item in document.TEXTINFOS)
239
            {
240
                if (item.UID == UID)
241
                    return item;
242
            }
243

    
244
            foreach (Note item in document.NOTES)
245
            {
246
                if (item.UID == UID)
247
                    return item;
248
            }
249

    
250
            foreach (LineNumber item in document.LINENUMBERS)
251
            {
252
                if (item.UID == UID)
253
                    return item;
254
            }
255

    
256
            foreach (Equipment item in document.Equipments)
257
            {
258
                if (item.UID == UID)
259
                    return item;
260
            }
261

    
262
            return null;
263
        }
264
        public static List<Line> FindLinesByModelId(Document document, string ModelItemId)
265
        {
266
            List<Line> lines = new List<Line>();
267
            foreach (Line item in document.LINES)
268
            {
269
                if (item.SPPID.ModelItemId == ModelItemId)
270
                    lines.Add(item);
271
            }
272

    
273
            return lines;
274
        }
275
        #endregion
276
    }
277
}
클립보드 이미지 추가 (최대 크기: 500 MB)