hytos / DTI_PID / SPPIDConverter_AutoModeling / Utill / SPPIDUtill.cs @ 70268347
이력 | 보기 | 이력해설 | 다운로드 (7.87 KB)
1 | bf42803b | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using SPPID.Model; |
||
7 | using SPPID.Modeling; |
||
8 | using System.Xml.Linq; |
||
9 | |||
10 | namespace SPPID.Utill |
||
11 | { |
||
12 | public static class SPPIDUtill |
||
13 | { |
||
14 | private static readonly double _DWG_X = 0.875; |
||
15 | private static readonly double _DWG_Y = 0.617; |
||
16 | public static string defaultPath = ""; |
||
17 | public static string mappingFilePath = ""; |
||
18 | |||
19 | public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY) |
||
20 | { |
||
21 | double calcX = 0; |
||
22 | double calcY = 0; |
||
23 | calcX = (dX * _DWG_X) / dDwgX; |
||
24 | calcX = Math.Truncate(calcX * 1000) / 1000; |
||
25 | calcY = _DWG_Y - ((dY * _DWG_Y) / dDwgY); |
||
26 | calcY = Math.Truncate(calcY * 1000) / 1000; |
||
27 | dX = calcX; |
||
28 | dY = calcY; |
||
29 | } |
||
30 | |||
31 | public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
||
32 | { |
||
33 | try |
||
34 | { |
||
35 | string[] pointArr = sPoint.Split(new char[] { ',' }); |
||
36 | if (pointArr.Length == 2) |
||
37 | { |
||
38 | dX = Convert.ToDouble(pointArr[0]); |
||
39 | dY = Convert.ToDouble(pointArr[1]); |
||
40 | } |
||
41 | } |
||
42 | catch (Exception) |
||
43 | { |
||
44 | dX = 0; |
||
45 | dY = 0; |
||
46 | return false; |
||
47 | } |
||
48 | |||
49 | return true; |
||
50 | } |
||
51 | |||
52 | public static Line.SlopeType CalcSlop(PointInfo point1, PointInfo point2) |
||
53 | { |
||
54 | Line.SlopeType _type = Line.SlopeType.NONE; |
||
55 | |||
56 | if (point1.X - point2.X == 0) |
||
57 | _type = Line.SlopeType.VERTICAL; |
||
58 | else |
||
59 | { |
||
60 | double angle = Math.Atan(Math.Abs(point2.Y - point1.Y) / Math.Abs(point2.X - point1.X)) * 180 / Math.PI; |
||
61 | if (angle < 20) |
||
62 | _type = Line.SlopeType.HORIZONTAL; |
||
63 | else if (angle > 70) |
||
64 | _type = Line.SlopeType.VERTICAL; |
||
65 | else |
||
66 | _type = Line.SlopeType.SLOPE; |
||
67 | } |
||
68 | |||
69 | return _type; |
||
70 | } |
||
71 | |||
72 | public static object FindObjectByUID(Document document, string UID) |
||
73 | { |
||
74 | foreach (Symbol item in document.SYMBOLS) |
||
75 | { |
||
76 | if (item.UID == UID) |
||
77 | return item; |
||
78 | } |
||
79 | |||
80 | foreach (Line item in document.LINES) |
||
81 | { |
||
82 | if (item.UID == UID) |
||
83 | return item; |
||
84 | } |
||
85 | |||
86 | foreach (Text item in document.TEXTS) |
||
87 | { |
||
88 | if (item.UID == UID) |
||
89 | return item; |
||
90 | } |
||
91 | |||
92 | foreach (LineNumber item in document.LINENUMBERS) |
||
93 | { |
||
94 | if (item.UID == UID) |
||
95 | return item; |
||
96 | } |
||
97 | |||
98 | return null; |
||
99 | } |
||
100 | |||
101 | public static string GetSPPIDSymbolMappingName(string name, Dictionary<string, string> symbolMapping) |
||
102 | { |
||
103 | if (name == "SIZE") |
||
104 | { |
||
105 | if (symbolMapping.ContainsKey(Text.pipingCompSize) && symbolMapping.ContainsKey(Text.instrumentSize)) |
||
106 | { |
||
107 | return "true"; |
||
108 | } |
||
109 | else |
||
110 | { |
||
111 | return ""; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | if (symbolMapping.ContainsKey(name)) |
||
116 | return symbolMapping[name]; |
||
117 | else |
||
118 | return ""; |
||
119 | } |
||
120 | |||
121 | public static string GetSPPIDAttributeMappingName(string name, Dictionary<string, string> attributeMapping) |
||
122 | { |
||
123 | if (attributeMapping.ContainsKey(name)) |
||
124 | return attributeMapping[name]; |
||
125 | else |
||
126 | return ""; |
||
127 | } |
||
128 | |||
129 | public static bool IsBranchLine(string UID, Line connectedLine) |
||
130 | { |
||
131 | try |
||
132 | { |
||
133 | if (connectedLine.CONNECTORS[0].CONNECTEDITEM != UID && connectedLine.CONNECTORS[1].CONNECTEDITEM != UID) |
||
134 | return true; |
||
135 | } |
||
136 | catch (Exception ex) |
||
137 | { |
||
138 | Log.WriteLine(ex); |
||
139 | } |
||
140 | |||
141 | return false; |
||
142 | } |
||
143 | |||
144 | public static double CalcPointToPointdDistance(PointInfo point1, PointInfo point2) |
||
145 | { |
||
146 | return Math.Pow(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2), 0.5); |
||
147 | } |
||
148 | |||
149 | public static double CalcLineToPointDistance(PointInfo linePoint1, PointInfo linePoint2, PointInfo point) |
||
150 | { |
||
151 | double distance = 0; |
||
152 | if (linePoint1.X == linePoint2.X) |
||
153 | distance = Math.Abs(point.X - linePoint1.X); |
||
154 | else |
||
155 | { |
||
156 | double a; |
||
157 | double b; |
||
158 | double c; |
||
159 | |||
160 | a = (linePoint2.Y - linePoint1.Y) / (linePoint2.X - linePoint1.X); |
||
161 | b = -1; |
||
162 | c = -a * linePoint1.X + linePoint1.Y; |
||
163 | |||
164 | distance = Math.Abs(a * point.X + b * point.Y + c) / Math.Pow(a * a + b * b, 0.5); |
||
165 | } |
||
166 | return distance; |
||
167 | } |
||
168 | |||
169 | public static bool GroupValidationCheck(Group group) |
||
170 | { |
||
171 | bool result = true; |
||
172 | |||
173 | foreach (SPPID_ITEM item in group.Items) |
||
174 | { |
||
175 | |||
176 | } |
||
177 | |||
178 | |||
179 | |||
180 | return result; |
||
181 | } |
||
182 | |||
183 | |||
184 | public static void SaveMapping(Dictionary<string, string> symbolMapping, Dictionary<string,string> attributeMapping) |
||
185 | { |
||
186 | XElement mappingElement = new XElement("Mapping"); |
||
187 | |||
188 | XElement symbolElement = new XElement("Symbol"); |
||
189 | foreach (var item in symbolMapping) |
||
190 | { |
||
191 | string name = item.Key; |
||
192 | string SPPID_Name = item.Value; |
||
193 | |||
194 | XElement element = new XElement("DATA"); |
||
195 | element.SetAttributeValue("SPPID", SPPID_Name); |
||
196 | element.Value = name; |
||
197 | |||
198 | symbolElement.Add(element); |
||
199 | } |
||
200 | mappingElement.Add(symbolElement); |
||
201 | |||
202 | XElement attributeElement = new XElement("Attribute"); |
||
203 | foreach (var item in attributeMapping) |
||
204 | { |
||
205 | string name = item.Key; |
||
206 | string SPPID_Name = item.Value; |
||
207 | |||
208 | XElement element = new XElement("DATA"); |
||
209 | element.SetAttributeValue("SPPID", SPPID_Name); |
||
210 | element.Value = name; |
||
211 | |||
212 | attributeElement.Add(element); |
||
213 | } |
||
214 | mappingElement.Add(attributeElement); |
||
215 | |||
216 | mappingElement.Save(mappingFilePath); |
||
217 | } |
||
218 | |||
219 | public static void LoadMapping(Dictionary<string, string> symbolMapping, Dictionary<string, string> attributeMapping) |
||
220 | { |
||
221 | try |
||
222 | { |
||
223 | if (System.IO.File.Exists(mappingFilePath)) |
||
224 | { |
||
225 | XElement xml = XElement.Load(mappingFilePath); |
||
226 | |||
227 | XElement symbolXml = xml.Element("Symbol"); |
||
228 | foreach (XElement mappingData in symbolXml.Elements("DATA")) |
||
229 | { |
||
230 | if (symbolMapping.ContainsKey(mappingData.Value)) |
||
231 | symbolMapping[mappingData.Value] = mappingData.Attribute("SPPID").Value; |
||
232 | else |
||
233 | symbolMapping.Add(mappingData.Value, mappingData.Attribute("SPPID").Value); |
||
234 | } |
||
235 | |||
236 | XElement attributeXml = xml.Element("Attribute"); |
||
237 | foreach (XElement mappingData in attributeXml.Elements("DATA")) |
||
238 | { |
||
239 | if (attributeMapping.ContainsKey(mappingData.Value)) |
||
240 | attributeMapping[mappingData.Value] = mappingData.Attribute("SPPID").Value; |
||
241 | else |
||
242 | attributeMapping.Add(mappingData.Value, mappingData.Attribute("SPPID").Value); |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | catch (Exception ex) |
||
247 | { |
||
248 | Log.WriteLine(ex); |
||
249 | } |
||
250 | } |
||
251 | } |
||
252 | } |