프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ cf924377

이력 | 보기 | 이력해설 | 다운로드 (12.5 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Data;
7
using Converter.BaseModel;
8
using Converter.SPPID.Util;
9

    
10
namespace Converter.SPPID.Model
11
{
12
    public class SPPID_Document : Document
13
    {
14
        public SPPID_Document(string xmlPath) : base(xmlPath)
15
        {
16
            
17
        }
18

    
19
        public List<SymbolMapping> SymbolMappings;
20
        public List<ChildSymbolMapping> ChildSymbolMappings;
21
        public List<LineMapping> LineMappings;
22
        public List<LineNumberMapping> LineNumberMappings;
23
        public List<AttributeMapping> AttributeMappings;
24
        public ETCSetting ETCSetting;
25

    
26
        public List<Group> GROUPS = new List<Group>();
27

    
28
        public string DrawingName { get; set; }
29
        public string DrawingNumber { get; set; }
30
        public string Unit { get; set; }
31
        public string Template { get; set; }
32

    
33
        public void SetSPPIDInfo()
34
        {
35
            foreach (var item in SYMBOLS)
36
            {
37
                if (item.SPPID == null)
38
                    item.SPPID = new SPPIDSymbolInfo();
39

    
40
                foreach (var childSymbol in item.ChildSymbols)
41
                {
42
                    if (childSymbol.SPPID == null)
43
                        childSymbol.SPPID = new SPPIDSymbolInfo();
44
                    SetChildSymbolSPPIDInfo(childSymbol);
45
                }
46
            }
47

    
48
            foreach (var item in LINES)
49
            {
50
                if (item.SPPID == null)
51
                    item.SPPID = new SPPIDLineInfo();
52
            }
53

    
54
            foreach (var item in Equipments)
55
            {
56
                if (item.SPPID == null)
57
                    item.SPPID = new SPPIDSymbolInfo();
58
            }
59

    
60
            foreach (var item in EndBreaks)
61
            {
62
                if (item.SPPID == null)
63
                    item.SPPID = new SPPIDSymbolInfo();
64
            }
65

    
66
            foreach (var item in LINENUMBERS)
67
            {
68
                if (item.SPPID == null)
69
                    item.SPPID = new SPPIDSymbolInfo();
70
            }
71

    
72
            foreach (var item in TEXTINFOS)
73
            {
74
                if (item.SPPID == null)
75
                    item.SPPID = new SPPIDSymbolInfo();
76
            }
77

    
78
            foreach (var item in NOTES)
79
            {
80
                if (item.SPPID == null)
81
                    item.SPPID = new SPPIDSymbolInfo();
82
            }
83
        }
84

    
85
        public void SetSPPIDLocation(double SPPIDDocumentX, double SPPIDDocumentY)
86
        {
87
            foreach (var item in SYMBOLS)
88
            {
89
                double x = double.NaN;
90
                double y = double.NaN;
91
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
92
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
93
                item.SPPID.ORIGINAL_X = x;
94
                item.SPPID.ORIGINAL_Y = y;
95
            }
96

    
97
            foreach (var item in LINES)
98
            {
99
                double x = double.NaN;
100
                double y = double.NaN;
101

    
102
                SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y);
103
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
104
                item.SPPID.START_X = x;
105
                item.SPPID.START_Y = y;
106

    
107
                SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y);
108
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
109
                item.SPPID.END_X = x;
110
                item.SPPID.END_Y = y;
111
            }
112

    
113
            foreach (var item in Equipments)
114
            {
115
                double x = double.NaN;
116
                double y = double.NaN;
117
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
118
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
119
                item.SPPID.ORIGINAL_X = x;
120
                item.SPPID.ORIGINAL_Y = y;
121
            }
122

    
123
            foreach (var item in EndBreaks)
124
            {
125
                double x = double.NaN;
126
                double y = double.NaN;
127
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
128
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
129
                item.SPPID.ORIGINAL_X = x;
130
                item.SPPID.ORIGINAL_Y = y;
131
            }
132

    
133
            foreach (var item in LINENUMBERS)
134
            {
135
                double x = double.NaN;
136
                double y = double.NaN;
137
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
138
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
139
                item.SPPID.ORIGINAL_X = x;
140
                item.SPPID.ORIGINAL_Y = y;
141

    
142
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
143
                double x1 = item.X1;
144
                double y1 = item.Y1;
145
                double x2 = item.X2;
146
                double y2 = item.Y2;
147
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
148
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
149
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
150
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
151
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
152
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
153
            }
154

    
155
            foreach (var item in TEXTINFOS)
156
            {
157
                double x = double.NaN;
158
                double y = double.NaN;
159
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
160
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
161
                item.SPPID.ORIGINAL_X = x;
162
                item.SPPID.ORIGINAL_Y = y;
163

    
164
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
165
                double x1 = item.X1;
166
                double y1 = item.Y1;
167
                double x2 = item.X2;
168
                double y2 = item.Y2;
169
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
170
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
171
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
172
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
173
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
174
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
175
            }
176

    
177
            foreach (var item in NOTES)
178
            {
179
                double x = double.NaN;
180
                double y = double.NaN;
181
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
182
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
183
                item.SPPID.ORIGINAL_X = x;
184
                item.SPPID.ORIGINAL_Y = y;
185

    
186
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
187
                double x1 = item.X1;
188
                double y1 = item.Y1;
189
                double x2 = item.X2;
190
                double y2 = item.Y2;
191
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
192
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
193
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
194
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
195
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
196
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
197
            }
198
        }
199

    
200
        private void SetChildSymbolSPPIDInfo(ChildSymbol item)
201
        {
202
            foreach (var childSymbol in item.ChildSymbols)
203
            {
204
                if (childSymbol.SPPID == null)
205
                    childSymbol.SPPID = new SPPIDSymbolInfo();
206
                SetChildSymbolSPPIDInfo(childSymbol);
207
            }
208
        }
209
      
210
        public bool SetSPPIDMapping()
211
        {
212
            foreach (var item in SYMBOLS)
213
            {
214
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
215
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
216
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
217
                    return false;
218

    
219
                foreach (var childSymbol in item.ChildSymbols)
220
                {
221
                    ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
222
                    childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
223
                    if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol))
224
                        return false;
225
                }
226
            }
227

    
228
            foreach (var item in LINES)
229
            {
230
                LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID);
231
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
232
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
233
                    return false;
234
            }
235

    
236
            foreach (var item in Equipments)
237
            {
238
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
239
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
240
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
241
                    return false;
242
            }
243

    
244
            foreach (var item in EndBreaks)
245
            {
246
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
247
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
248
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
249
                    return false;
250
            }
251

    
252
            foreach (var item in LINENUMBERS)
253
            {
254
                if (LineNumberMappings.Count > 0)
255
                    item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME;
256
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
257
                    return false;
258
            }
259

    
260
            ETCSetting etc = ETCSetting.GetInstance();
261
            foreach (var item in NOTES)
262
            {
263
                item.SPPID.MAPPINGNAME = etc.NoteSymbolPath;
264
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
265
                    return false;
266
            }
267

    
268
            foreach (var item in TEXTINFOS)
269
            {
270
                item.SPPID.MAPPINGNAME = etc.TextSymbolPath;
271
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
272
                    return false;
273
            }
274

    
275
            return true;
276
        }
277

    
278
        public void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height)
279
        {
280
            decimal calcX = 0;
281
            decimal calcY = 0;
282
            decimal tempX = Convert.ToDecimal(dX);
283
            decimal tempY = Convert.ToDecimal(dY);
284
            decimal tempWidth = Convert.ToDecimal(SPPID_Width);
285
            decimal tempHeight = Convert.ToDecimal(SPPID_Height);
286
            decimal tempDwgX = Convert.ToDecimal(dDwgX);
287
            decimal tempDwgY = Convert.ToDecimal(dDwgY);
288

    
289
            //calcX = (tempX * tempWidth) / tempDwgX;
290
            //calcX = Math.Truncate(calcX * 1000) / 1000;
291
            //calcY = tempHeight - ((tempY * tempHeight) / tempDwgY);
292
            //calcY = Math.Truncate(calcY * 1000) / 1000;
293
            //dX = Math.Round(Convert.ToDouble(calcX), 10);
294
            //dY = Math.Round(Convert.ToDouble(calcY), 10);
295

    
296
            calcX = (tempX * tempWidth) / tempDwgX;
297
            calcY = tempHeight - ((tempY * tempHeight) / tempDwgY);
298
            dX = Convert.ToDouble(calcX);
299
            dY = Convert.ToDouble(calcY);
300
        }
301

    
302
        private bool SetChildSymbolMapping(ChildSymbol item)
303
        {
304
            foreach (var childSymbol in item.ChildSymbols)
305
            {
306
                ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
307
                childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
308
                if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME))
309
                    return false;
310
                else
311
                    return SetChildSymbolMapping(childSymbol);
312
            }
313

    
314
            return true;
315
        }
316
    }
317
}
클립보드 이미지 추가 (최대 크기: 500 MB)