프로젝트

일반

사용자정보

개정판 20f9fa83

ID20f9fa83264d4583a9eaf750bc44872cb9609747
상위 a48fde55
하위 adc77117, 3f3f05af

조봉훈이(가) 약 2년 전에 추가함

Fix symbol equal spacing when using Grid Snap

Change-Id: I270fb3904a65a511c735d6524c8b08333e0351f3

차이점 보기:

DTI_PID/SPPIDConverter/AutoModeling.cs
300 300
        private void RunLineModeling()
301 301
        {
302 302
            List<Line> AllLine = document.LINES.ToList();
303
            List<Line> stepLast_Line = document.LINES.FindAll(x => x.CONNECTORS.FindAll(y => y.ConnectedObject != null && y.ConnectedObject.GetType() == typeof(Symbol)).Count == 2 &&
304
            !SPPIDUtil.IsBranchedLine(document, x));
303
            List<Line> stepLast_Line = document.LINES.FindAll(x => x.CONNECTORS.FindAll(y => y.ConnectedObject != null
304
                                                                                     && y.ConnectedObject.GetType() == typeof(Symbol)).Count == 2
305
                                                                                     && !SPPIDUtil.IsBranchedLine(document, x));
305 306
            List<Line> step1_Line = AllLine.FindAll(x => !stepLast_Line.Contains(x));
306 307

  
307 308
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, step1_Line.Count);
......
1100 1101
            Log.Write("Drawing name : " + drawingName);
1101 1102
            Log.Write("Drawing number : " + drawingNumber);
1102 1103
            Thread.Sleep(1000);
1103
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
1104
            try
1105
            {
1106
                newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
1107
            }
1108
            catch (Exception ex)
1109
            {
1110
                if (ex.Message == "Invalid procedure call or argument")
1111
                {
1112
                    Exception newEx = new Exception(string.Format("Invalid Unit [0]", document.Unit), ex.InnerException);
1113
                    throw newEx;
1114
                }
1115
                else
1116
                {
1117
                    throw ex;
1118
                }
1119
            }
1120
            
1104 1121
            if (newDrawing != null)
1105 1122
            {
1106 1123
                document.SPPID_DrawingNumber = drawingNumber;
......
1362 1379
                {
1363 1380
                    double currentX = _LMSymbol.get_XCoordinate();
1364 1381
                    double currentY = _LMSymbol.get_YCoordinate();
1365

  
1366

  
1367 1382
                }
1368 1383

  
1369 1384
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
......
1383 1398
                symbol.SPPID.SPPID_Max_X = range[2];
1384 1399
                symbol.SPPID.SPPID_Max_Y = range[3];
1385 1400

  
1386
                foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols)
1387
                    item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
1388
                foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols)
1389
                    item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
1401
                double xGap = symbol.SPPID.SPPID_X - symbol.SPPID.ORIGINAL_X;
1402
                double yGap = symbol.SPPID.SPPID_Y - symbol.SPPID.ORIGINAL_Y;
1403

  
1404
                List<Symbol> xGroupSymbols = symbol.SPPID.CorrectionX_GroupSymbols;
1405
                List<Symbol> yGroupSymbols = symbol.SPPID.CorrectionY_GroupSymbols;
1406
                xGroupSymbols.Sort(SPPIDUtil.SortSymbolPriority);
1407
                yGroupSymbols.Sort(SPPIDUtil.SortSymbolPriority);
1408
                int xDrawnCount = xGroupSymbols.Count(c => c.SPPID.RepresentationId != null);
1409
                int yDrawnCount = yGroupSymbols.Count(c => c.SPPID.RepresentationId != null);
1410

  
1411
                if (xDrawnCount == 1 || xDrawnCount == 2)
1412
                {
1413
                    for (int i = 0; i < xGroupSymbols.Count; i++)
1414
                    {
1415
                        var item = xGroupSymbols[i];
1416
                        if (!string.IsNullOrWhiteSpace(item.SPPID.RepresentationId)) continue;
1417

  
1418
                        if (xDrawnCount == 1)
1419
                        {                            
1420
                            item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
1421
                            item.SPPID.ORIGINAL_Y = item.SPPID.ORIGINAL_Y + yGap;
1422
                        }
1423
                        else if (xDrawnCount == 2)
1424
                        {
1425
                            if (item.SPPID.IsEqualSpacingY)
1426
                            {
1427
                                double ppValue = xGroupSymbols[i - 2].SPPID.SPPID_Y != 0 ? xGroupSymbols[i - 2].SPPID.SPPID_Y : xGroupSymbols[i - 2].SPPID.ORIGINAL_Y;
1428
                                double pValue = xGroupSymbols[i - 1].SPPID.SPPID_Y != 0 ? xGroupSymbols[i - 1].SPPID.SPPID_Y : xGroupSymbols[i - 1].SPPID.ORIGINAL_Y;
1429
                                double gap = pValue - ppValue;
1430
                                double value = pValue + gap;
1431
                                item.SPPID.ORIGINAL_Y = value;
1432
                            }
1433
                        }
1434
                    }
1435
                }
1436

  
1437
                if (yDrawnCount == 1 || yDrawnCount == 2)
1438
                {
1439
                    for (int i = 0; i < yGroupSymbols.Count; i++)
1440
                    {
1441
                        var item = yGroupSymbols[i];
1442
                        if (!string.IsNullOrWhiteSpace(item.SPPID.RepresentationId)) continue;
1443

  
1444
                        if (yDrawnCount == 1)
1445
                        {
1446
                            item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
1447
                            item.SPPID.ORIGINAL_X = item.SPPID.ORIGINAL_X + xGap;
1448
                        }
1449
                        else if (yDrawnCount == 2)
1450
                        {
1451
                            if (item.SPPID.IsEqualSpacingX)
1452
                            {
1453
                                double ppValue = yGroupSymbols[i - 2].SPPID.SPPID_X != 0 ? yGroupSymbols[i - 2].SPPID.SPPID_X : yGroupSymbols[i - 2].SPPID.ORIGINAL_X;
1454
                                double pValue = yGroupSymbols[i - 1].SPPID.SPPID_X != 0 ? yGroupSymbols[i - 1].SPPID.SPPID_X : yGroupSymbols[i - 1].SPPID.ORIGINAL_X;
1455
                                double gap = pValue - ppValue;
1456
                                double value = pValue + gap;
1457
                                item.SPPID.ORIGINAL_X = value;
1458
                            }
1459
                        }
1460
                    }
1461
                }
1390 1462

  
1391 1463
                ReleaseCOMObjects(_LMSymbol);
1392 1464
            }
......
2114 2186
            List<object> endObjects = new List<object>();
2115 2187
            endObjects.Add(symbol);
2116 2188

  
2117
            /// 심볼에 연결되어 있는 항목들을 모델링한다
2189
            // 심볼에 연결되어 있는 항목들을 모델링한다
2118 2190
            foreach (var connector in symbol.CONNECTORS)
2119 2191
            {
2120 2192
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
......
2776 2848

  
2777 2849
        private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true)
2778 2850
        {
2851
            bool isReverseX = line.SPPID.END_X - line.SPPID.START_X < 0;
2852
            bool isReverseY = line.SPPID.END_Y - line.SPPID.START_Y < 0;
2853

  
2779 2854
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
2780 2855
            int index = line.CONNECTORS.IndexOf(connector);
2781 2856
            if (index == 0)
2782
            {
2857
            {                
2783 2858
                line.SPPID.START_X = x;
2784 2859
                line.SPPID.START_Y = y;
2785 2860
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
2861
                {
2786 2862
                    line.SPPID.END_Y = y;
2863
                    // START_X가 END_X 값을 벗어날 경우 END_X 값 보정
2864
                    if ((line.SPPID.END_X - line.SPPID.START_X) * (!isReverseX ? 1 : -1) <= 0)
2865
                    {
2866
                        GridSetting grid = GridSetting.GetInstance();
2867
                        line.SPPID.END_X = line.SPPID.START_X + (grid.Length * (!isReverseX ? 1 : -1));
2868
                    }
2869
                }
2787 2870
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
2871
                {
2788 2872
                    line.SPPID.END_X = x;
2873
                    // START_Y가 END_Y 값을 벗어날 경우 END_Y 값 보정
2874
                    if ((line.SPPID.END_Y - line.SPPID.START_Y) * (!isReverseY ? 1 : -1) <= 0)
2875
                    {
2876
                        GridSetting grid = GridSetting.GetInstance();
2877
                        line.SPPID.END_Y = line.SPPID.START_Y + (grid.Length * (!isReverseY ? 1 : -1));
2878
                    }
2879
                }
2789 2880
            }
2790 2881
            else
2791 2882
            {
2792 2883
                line.SPPID.END_X = x;
2793 2884
                line.SPPID.END_Y = y;
2794 2885
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
2886
                {
2795 2887
                    line.SPPID.START_Y = y;
2888
                    // END_X가 START_X 값을 벗어날 경우 START_X 값 보정
2889
                    if ((line.SPPID.END_X - line.SPPID.START_X) * (isReverseX ? 1 : -1) <= 0)
2890
                    {
2891
                        GridSetting grid = GridSetting.GetInstance();
2892
                        line.SPPID.START_X = line.SPPID.END_X + (grid.Length * (!isReverseX ? 1 : -1));
2893
                    }
2894
                }
2796 2895
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
2896
                {
2797 2897
                    line.SPPID.START_X = x;
2898
                    // END_Y가 START_Y 값을 벗어날 경우 START_Y 값 보정
2899
                    if ((line.SPPID.END_Y - line.SPPID.START_Y) * (isReverseY ? 1 : -1) <= 0)
2900
                    {
2901
                        GridSetting grid = GridSetting.GetInstance();
2902
                        line.SPPID.START_Y = line.SPPID.END_Y + (grid.Length * (!isReverseY ? 1 : -1));
2903
                    }
2904
                }
2798 2905
            }
2799 2906
        }
2800 2907

  
......
6442 6549
                if (!symbols.Contains(item))
6443 6550
                    tempSymbols.Add(item);
6444 6551
            }
6445
            tempSymbols.Sort(SortSymbolPriority);
6552
            tempSymbols.Sort(SPPIDUtil.SortSymbolPriority);
6446 6553
            symbols.AddRange(tempSymbols);
6447 6554

  
6448 6555
            return symbols;
......
6644 6751
            }
6645 6752
        }
6646 6753

  
6647
        private static int SortSymbolPriority(Symbol a, Symbol b)
6648
        {
6649
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
6650
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
6651
            int retval = countB.CompareTo(countA);
6652
            if (retval != 0)
6653
                return retval;
6654
            else
6655
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
6656
        }
6754
        
6657 6755

  
6658 6756
        private string GetSPPIDFileName(LMModelItem modelItem)
6659 6757
        {
DTI_PID/SPPIDConverter/BaseModel/SPPID/SPPIDSymbolInfo.cs
16 16
        public string GraphicOID { get; set; }
17 17
        public bool IsCorrectionX { get; set; }
18 18
        public bool IsCorrectionY { get; set; }
19
        public bool IsEqualSpacingX { get; set; }
20
        public bool IsEqualSpacingY { get; set; }
19 21

  
20 22
        private double[] _Range;
21 23
        private List<string[]> _Attributes = new List<string[]>();
DTI_PID/SPPIDConverter/SPPIDConverter.csproj
292 292
    <EmbeddedResource Include="Form\UnitForm.resx">
293 293
      <DependentUpon>UnitForm.cs</DependentUpon>
294 294
    </EmbeddedResource>
295
    <EmbeddedResource Include="Properties\licenses.licx" />
296 295
    <EmbeddedResource Include="Properties\Resources.resx">
297 296
      <Generator>ResXFileCodeGenerator</Generator>
298 297
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
DTI_PID/SPPIDConverter/SPPIDModel/SPPID_Document.cs
239 239
        /// </summary>
240 240
        public void CoordinateCorrection()
241 241
        {
242
            foreach (Symbol symbol in SYMBOLS)
242
            List<Symbol> symbols = SYMBOLS;
243
            symbols.Sort(SPPIDUtil.SortSymbolPriority);
244
            foreach (Symbol symbol in symbols)
243 245
            {
244 246
                if (!symbol.SPPID.IsCorrectionX)
245 247
                {
......
249 251

  
250 252
                    List<Symbol> groupSymbols = (from sym in @group
251 253
                                                 where sym.GetType() == typeof(Symbol)
252
                                                 select sym as Symbol).ToList();
254
                                                 select sym as Symbol).OrderBy(o => o.SPPID.ORIGINAL_Y).ToList();
253 255

  
254 256
                    // X 좌표만 보정
255 257
                    Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionX);
......
259 261
                    else
260 262
                        value = correctionSymbol.SPPID.ORIGINAL_X;
261 263

  
262
                    foreach (var item in groupSymbols)
264
                    for (int i = 0; i < groupSymbols.Count; i++)
263 265
                    {
266
                        var item = groupSymbols[i];
267
                    
264 268
                        item.SPPID.IsCorrectionX = true;
265 269
                        item.SPPID.ORIGINAL_X = value;
266
                        item.SPPID.CorrectionX_GroupSymbols = groupSymbols;
270
                        item.SPPID.CorrectionX_GroupSymbols = groupSymbols;                    
271

  
272
                        if (i > 1)
273
                        {
274
                            double pGap = groupSymbols[i - 2].SPPID.ORIGINAL_Y - groupSymbols[i - 1].SPPID.ORIGINAL_Y;
275
                            double cGap = groupSymbols[i - 1].SPPID.ORIGINAL_Y - groupSymbols[i].SPPID.ORIGINAL_Y;
276
                            if (SPPIDUtil.EqualSpacing(pGap, cGap))
277
                                item.SPPID.IsEqualSpacingY = true;
278
                        }
267 279
                    }
268 280
                }
269 281

  
......
275 287

  
276 288
                    List<Symbol> groupSymbols = (from sym in @group
277 289
                                                 where sym.GetType() == typeof(Symbol)
278
                                                 select sym as Symbol).ToList();
290
                                                 select sym as Symbol).OrderBy(o => o.SPPID.ORIGINAL_X).ToList();
279 291

  
280 292
                    // Y 좌표만 보정
281 293
                    Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionY);
......
285 297
                    else
286 298
                        value = correctionSymbol.SPPID.ORIGINAL_Y;
287 299

  
288
                    foreach (var item in groupSymbols)
300
                    for (int i = 0; i < groupSymbols.Count; i++)
289 301
                    {
302
                        var item = groupSymbols[i];
303
                    
290 304
                        item.SPPID.IsCorrectionY = true;
291 305
                        item.SPPID.ORIGINAL_Y = value;
292 306
                        item.SPPID.CorrectionY_GroupSymbols = groupSymbols;
307

  
308
                        if (i > 1)
309
                        {
310
                            double pGap = groupSymbols[i - 2].SPPID.ORIGINAL_X - groupSymbols[i - 1].SPPID.ORIGINAL_X;
311
                            double cGap = groupSymbols[i - 1].SPPID.ORIGINAL_X - groupSymbols[i].SPPID.ORIGINAL_X;
312
                            if (SPPIDUtil.EqualSpacing(pGap, cGap))
313
                                item.SPPID.IsEqualSpacingX = true;
314
                        }
293 315
                    }
294 316
                }
295 317
            }
DTI_PID/SPPIDConverter/Util/SPPIDUtil.cs
196 196
            return value;
197 197
        }
198 198

  
199
        public static bool EqualSpacing(double value1, double value2)
200
        {
201
            GridSetting _GridSetting = GridSetting.GetInstance();
202
            double multiplier = 100000000000000;
203
            value1 = Math.Truncate(value1 * multiplier) / multiplier;
204
            value2 = Math.Truncate(value2 * multiplier) / multiplier;
205

  
206
            return value1 == value2;
207
        }
208

  
199 209
        public static SlopeType CalcSlope(double x1, double y1, double x2, double y2, double degree = 15)
200 210
        {
201 211
            if (x1 - x2 == 0)
......
434 444
            }
435 445
        }
436 446

  
447
        public static int SortSymbolPriority(Symbol a, Symbol b)
448
        {
449
            int resultValue = a.SPPID.ORIGINAL_Y.CompareTo(b.SPPID.ORIGINAL_Y);
450
            if (resultValue == 0)
451
                resultValue = a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
452
            return resultValue;
453
        }
454

  
437 455
        public static Connector FindSymbolConnectorByUID(Document document, string uid, Symbol targetSymbol)
438 456
        {
439 457
            foreach (var connector in targetSymbol.CONNECTORS)

내보내기 Unified diff

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