프로젝트

일반

사용자정보

개정판 016701e5

ID016701e50c4968cb90456c08e3f36ba3090dbb77
상위 53344e2c
하위 da4c0bf8

gaqhf 이(가) 5년 이상 전에 추가함

dev issue #1230 : group line modeling

Change-Id: I9cd59da201f59af907eac2ad741f00b74f66bbbf

차이점 보기:

DTI_PID/APIDConverter/AutoModeling.cs
1 1
using System;
2 2
using System.Collections.Generic;
3
using System.Collections;
3 4
using System.Configuration;
4 5
using System.Data;
5 6
using System.Data.Common;
......
76 77
        }
77 78
        public void Run()
78 79
        {
79
            RunLineModeling();
80
            try
81
            {
82
                RunLineModeling();
83
                RunSymbolModeling();
84
            }
85
            catch (System.Exception ex)
86
            {
87
                System.Windows.Forms.MessageBox.Show(ex.Message + @"\n" + ex.StackTrace);
88
            }
80 89
        }
81 90

  
82 91
        #region Run Method
......
88 97
                    LineModeling(item);
89 98
            }
90 99
        }
100
        private void RunSymbolModeling()
101
        {
102

  
103
        }
91 104
        #endregion
92 105

  
93 106
        #region Modeling Method
......
95 108
        {
96 109
            List<Model.Line> groupLine = new List<Model.Line>();
97 110
            List<string> points = new List<string>();
98
            GetConnectedGroupLine(line, null, groupLine);
111
            GetConnectedGroupLine(line, groupLine, false);
99 112
            GetGroupLinePoints(groupLine, points);
100 113

  
101 114
            long handle = 0;
......
107 120
            foreach (var item in groupLine)
108 121
                item.Aveva.Handle = handle;
109 122
        }
123

  
110 124
        #endregion
111 125

  
112 126
        #region Drawing Method
......
274 288

  
275 289
            return result;
276 290
        }
277
        private void GetConnectedGroupLine(Model.Line line, Model.Line prevLine, List<Model.Line> group)
291

  
292

  
293

  
294
        #endregion
295

  
296
        #region
297
        private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert)
278 298
        {
279 299
            if (!group.Contains(line))
280 300
            {
281
                if (prevLine != null && prevLine.CONNECTORS[0].ConnectedObject == line)
301
                if (isInsert)
282 302
                    group.Insert(0, line);
283
                else if (prevLine != null && prevLine.CONNECTORS[1].ConnectedObject == line)
284
                    group.Add(line);
285 303
                else
286 304
                    group.Add(line);
287 305

  
288
                if (line.CONNECTORS[0].ConnectedObject != null &&
289
                    line.CONNECTORS[0].ConnectedObject.GetType() == typeof(Model.Line) &&
290
                    APIDUtils.IsConnectedLine(line.CONNECTORS[0].ConnectedObject as Model.Line, line))
291
                    GetConnectedGroupLine(line.CONNECTORS[0].ConnectedObject as Model.Line, line, group);
292
                if (line.CONNECTORS[1].ConnectedObject != null &&
293
                    line.CONNECTORS[1].ConnectedObject.GetType() == typeof(Model.Line) &&
294
                    APIDUtils.IsConnectedLine(line.CONNECTORS[1].ConnectedObject as Model.Line, line))
295
                    GetConnectedGroupLine(line.CONNECTORS[1].ConnectedObject as Model.Line, line, group);
306
                if (line.CONNECTORS[0].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[0].ConnectedObject))
307
                {
308
                    object connObj = line.CONNECTORS[0].ConnectedObject;
309
                    if (connObj.GetType() == typeof(Model.Line) &&
310
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
311
                        GetConnectedGroupLine(connObj as Model.Line, group, true);
312
                    else if (connObj.GetType() == typeof(Model.Symbol))
313
                    {
314
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
315
                        if (connLine != null)
316
                            GetConnectedGroupLine(connLine as Model.Line, group, true);
317
                    }
318
                }
319
                if (line.CONNECTORS[1].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[1].ConnectedObject))
320
                {
321
                    object connObj = line.CONNECTORS[1].ConnectedObject;
322
                    if (connObj.GetType() == typeof(Model.Line) &&
323
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
324
                        GetConnectedGroupLine(connObj as Model.Line, group, false);
325
                    else if (connObj.GetType() == typeof(Model.Symbol))
326
                    {
327
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
328
                        if (connLine != null)
329
                            GetConnectedGroupLine(connLine as Model.Line, group, false);
330
                    }
331
                }
296 332
            }
297 333
        }
298 334
        private void GetGroupLinePoints(List<Model.Line> groupLine, List<string> points)
......
300 336
            for (int i = 0; i < groupLine.Count; i++)
301 337
            {
302 338
                Model.Line line = groupLine[i];
303
                points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
339
                if (i == 0)
340
                    points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
341
                else
342
                {
343
                    Model.Line prevLine = groupLine[i - 1];
344
                    if (line.SlopeType == SlopeType.HORIZONTAL &&
345
                        prevLine.SlopeType == SlopeType.VERTICAL)
346
                        points.Add(prevLine.Aveva.End_X + "," + line.Aveva.Start_Y);
347
                    else if (line.SlopeType == SlopeType.VERTICAL &&
348
                        prevLine.SlopeType == SlopeType.HORIZONTAL)
349
                        points.Add(line.Aveva.Start_X + "," + prevLine.Aveva.End_Y);
350
                    else
351
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
352
                }
353

  
304 354
                if (i == groupLine.Count - 1)
305 355
                    points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
306 356
            }
307 357
        }
358
        private bool IsExistEndBreak(object item1, object item2)
359
        {
360
            bool result = false;
361
            if (item1 != null && item2 != null)
362
            {
363
                EndBreak endBreak = document.EndBreaks.Find(x =>
364
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item1 &&
365
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item2) ||
366
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item2 &&
367
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item1));
368

  
369
                if (endBreak != null)
370
                    result = true;
371
            }
372

  
373
            return result;
374
        }
375
        private LineRun FindLineRun(Model.Line line)
376
        {
377
            List<LineRun> allLineRun = new List<LineRun>();
378
            foreach (var item in document.LINENUMBERS)
379
                allLineRun.AddRange(item.RUNS);
380
            foreach (var item in document.TRIMLINES)
381
                allLineRun.AddRange(item.RUNS);
382

  
383
            return allLineRun.Find(x => x.RUNITEMS.Contains(line));
384
        }
385
        private Model.Line FindOtherLineByRun(Model.Line line, Symbol symbol)
386
        {
387
            Model.Line result = null;
388
            LineRun run = FindLineRun(line);
389
            Connector connector = symbol.CONNECTORS.Find(x =>
390
            x.ConnectedObject != null &&
391
            x.ConnectedObject != line &&
392
            run.RUNITEMS.Contains(x.ConnectedObject) &&
393
            x.ConnectedObject.GetType() == typeof(Model.Line));
394

  
395
            if (connector != null)
396
                result = connector.ConnectedObject as Model.Line;
397

  
398
            return result;
399
        }
308 400
        #endregion
309 401

  
310 402
        #region Test Source
DTI_PID/APIDConverter/Model/PlantItem/Document.cs
269 269
                SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS);
270 270
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
271 271
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES);
272
                line.SetSlopeType();
272 273
                LINES.Add(line);
273 274
            }
274 275
            PlantItems.AddRange(LINES);
DTI_PID/APIDConverter/Model/PlantItem/Line.cs
76 76
        public List<Association> ASSOCIATIONS { get => _ASSOCIATIONS; set => _ASSOCIATIONS = value; }
77 77
        public List<Attribute> ATTRIBUTES { get => _ATTRIBUTES; set => _ATTRIBUTES = value; }
78 78
        public AvevaLineInfo Aveva { get; set; }
79

  
80
        public void SetSlopeType()
81
        {
82
            SlopeType = APIDUtils.CalcSlope(Start_X, Start_Y, End_X, End_Y);
83
        }
79 84
    }
80 85
}
DTI_PID/APIDConverter/Utils/APIDUtils.cs
64 64

  
65 65
            return result;
66 66
        }
67
        public static SlopeType CalcSlope(double x1, double y1, double x2, double y2)
68
        {
69
            if (x1 - x2 == 0)
70
            {
71
                return SlopeType.VERTICAL;
72
            }
73
            else
74
            {
75
                double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
76
                if (angle <= 15)
77
                    return SlopeType.HORIZONTAL;
78
                else if (angle >= 75)
79
                    return SlopeType.VERTICAL;
80
                else
81
                    return SlopeType.Slope;
82
            }
83
        }
67 84
        #endregion
68 85

  
69 86
        #region Only AVEVA

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)