프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (5.7 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 = Convert.ToDouble(calcX);
112
            dY = Convert.ToDouble(calcY);
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
        #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
    }
184
}
클립보드 이미지 추가 (최대 크기: 500 MB)