프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 56bc67e1

이력 | 보기 | 이력해설 | 다운로드 (7.83 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 = Math.Round(Convert.ToDouble(calcX), 10);
112
            dY = Math.Round(Convert.ToDouble(calcY), 10);
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
        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
        #region
202
        public static bool IsBranchLine(string UID, Line connectedLine)
203
        {
204
            try
205
            {
206
                if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID)
207
                    return true;
208
            }
209
            catch (Exception ex)
210
            {
211
                
212
            }
213

    
214
            return false;
215
        }
216
        public static object FindObjectByUID(Document document, string UID)
217
        {
218
            foreach (Symbol item in document.SYMBOLS)
219
            {
220
                if (item.UID == UID)
221
                    return item;
222
            }
223

    
224
            foreach (Line item in document.LINES)
225
            {
226
                if (item.UID == UID)
227
                    return item;
228
            }
229

    
230
            foreach (Text item in document.TEXTINFOS)
231
            {
232
                if (item.UID == UID)
233
                    return item;
234
            }
235

    
236
            foreach (Note item in document.NOTES)
237
            {
238
                if (item.UID == UID)
239
                    return item;
240
            }
241

    
242
            foreach (LineNumber item in document.LINENUMBERS)
243
            {
244
                if (item.UID == UID)
245
                    return item;
246
            }
247

    
248
            foreach (Equipment item in document.Equipments)
249
            {
250
                if (item.UID == UID)
251
                    return item;
252
            }
253

    
254
            return null;
255
        }
256
        #endregion
257
    }
258
}
클립보드 이미지 추가 (최대 크기: 500 MB)