프로젝트

일반

사용자정보

개정판 9fcc54bb

ID9fcc54bb4edadc8b8faab5810e9d31774a5822d1
상위 b53b591f
하위 434eb5c7

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

dev issue #507 : samsung test source

Change-Id: I5706ec798ada240db3e4a9fed4b699fa2d64e63a

차이점 보기:

DTI_PID/SPPIDConverter/ConverterDocking.cs
53 53
                if (Project_DB.ConnTestAndCreateTable())
54 54
                {
55 55
                    _ProjectInfo.Enable = true;
56
                    layoutControlGroup3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
56
                    layoutControlGroupUtils.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
57 57

  
58 58
                    DataTable dt = Project_DB.SelectSetting();
59 59
                    foreach (DataRow item in dt.Rows)
......
67 67
                }
68 68
                else
69 69
                {
70
                    layoutControlGroup3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
70
                    layoutControlGroupUtils.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
71 71
                }
72 72

  
73 73
                if (!addEvent)
......
83 83
                sb.AppendLine(ex.StackTrace);
84 84
                MessageBox.Show(sb.ToString());
85 85
            }
86

  
87
#if DEBUG
88
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
89
            layoutControlGroup1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
90

  
91
#else
92
            layoutControlGroup1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
93
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
94
#endif
95

  
96
            //#if DEBUG
97
            //            layoutControlGroupConverter.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
98
            //            layoutControlGroupUtils.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
99
            //            layoutControlGroupShortCut.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
100
            //            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
101
            //            this.layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
102
            //#endif
86 103
        }
87 104
        private void ApplicationEvents_ApplicationExit(out bool cancel)
88 105
        {
......
1191 1208
            width = x2 - x1;
1192 1209
            height = y2 - y1;
1193 1210
        }
1194

  
1195 1211
        private void FindRangeWithOutLineString2dAndTextBox(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2)
1196 1212
        {
1197 1213
            x1 = double.MaxValue;
......
1602 1618

  
1603 1619
        #endregion
1604 1620

  
1621
        
1605 1622
        #region TEST
1606

  
1607 1623
        private void simpleButton1_Click(object sender, EventArgs e)
1608 1624
        {
1609 1625
            //SPPIDUtil.test();
......
1667 1683
            //relationships.Collect(dataSource, Filter: filter);
1668 1684

  
1669 1685
        }
1670

  
1671 1686
        private void AutoJoinPipeRun()
1672 1687
        {
1673 1688
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
......
1702 1717
        [DllImport("user32.dll", SetLastError = true)]
1703 1718
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
1704 1719

  
1705
        private void ConverterDocking_Load(object sender, EventArgs e)
1706
        {
1707
#if DEBUG
1708
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
1709
#else
1710
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
1711
#endif
1712

  
1713
        }
1714

  
1715 1720
        private void btnLinkOPCTest_Click(object sender, EventArgs e)
1716 1721
        {
1717 1722
            Placement placement = new Placement();
......
1758 1763
            ReleaseCOMObjects(dataSource);
1759 1764
            ReleaseCOMObjects(placement);
1760 1765
        }
1766

  
1767
        #region Test For SECL
1768
        private void btnAutoBreakTest_Click(object sender, EventArgs e)
1769
        {
1770
            
1771
        }
1772

  
1773
        private void FindRun(LMSymbol startSymbol, LMSymbol endSymbol, string model)
1774
        {
1775
            Placement placement = new Placement();
1776
            LMADataSource dataSource = placement.PIDDataSource;
1777
            List<string> endRepID = new List<string>();
1778
            List<string> findRepID = new List<string>();
1779
            endRepID.Add(startSymbol.AsLMRepresentation().Id);
1780
            findRepID.Add(startSymbol.AsLMRepresentation().Id);
1781
            bool end = false;
1782
            LoopRunTest(startSymbol.AsLMRepresentation(), endRepID, endSymbol.AsLMRepresentation().Id, ref end, findRepID);
1783

  
1784

  
1785
            //findRepID.Reverse();
1786
            for (int i = 0; i < findRepID.Count; i++)
1787
            {
1788
                string repID = findRepID[i];
1789

  
1790
                LMRepresentation representation = dataSource.GetRepresentation(repID);
1791
                if (representation != null)
1792
                {
1793
                    string fileName = representation.get_FileName().ToString();
1794
                    if (fileName.Contains(@"\Piping\Valves"))
1795
                    {
1796
                        LMModelItem modelItem = representation.ModelItemObject;
1797
                        LMSymbol tarsym = dataSource.GetSymbol(representation.Id);
1798
                        LMRepresentation prevRep = dataSource.GetRepresentation(findRepID[i - 1]);
1799
                        LMConnector removeConnector = dataSource.GetConnector(prevRep.Id);
1800

  
1801
                        List<double[]> vertices = GetConnectorVertices(removeConnector);
1802

  
1803
                        ZoomObjectByGraphicOID(vertices[0][0], vertices[0][1]);
1804
                        Array array = new double[] { 0, vertices[0][0], vertices[0][1] };
1805
                        LMLabelPersist _LmLabelPersist = placement.PIDPlaceLabel(model, ref array, LabeledItem: removeConnector.AsLMRepresentation(), IsLeaderVisible: true);
1806
                        if (_LmLabelPersist == null)
1807
                        {
1808
                            if (removeConnector.get_ItemStatus() == "Active")
1809
                            {
1810
                                LMConnector newConnector = ReModelingLine(removeConnector, removeConnector.ConnectItem1SymbolObject, removeConnector.ConnectItem2SymbolObject, true, false);
1811
                                FindRun(startSymbol, endSymbol, model);
1812
                            }
1813
                        }
1814
                        
1815

  
1816

  
1817
                        //string dd = startSymbol.ModelItemObject.Attributes["SteamOutTemperature"].get_Value();
1818
                        //string dd2 = endSymbol.ModelItemObject.Attributes["SteamOutTemperature"].get_Value();
1819
                        //double value1 = Convert.ToDouble(dd.Split(new char[] { ' ' })[0]);
1820
                        //double value2 = Convert.ToDouble(dd2.Split(new char[] { ' ' })[0]);
1821

  
1822
                        //if (value1 > value2)
1823
                        //{
1824
                        //    LMRepresentation prevRep = dataSource.GetRepresentation(endRepID[i + 1]);
1825
                        //    placement.PIDRemovePlacement(prevRep);
1826
                        //}
1827
                        //else
1828
                        //{
1829
                        //    LMRepresentation prevRep = dataSource.GetRepresentation(endRepID[i - 1]);
1830
                        //    placement.PIDRemovePlacement(prevRep);
1831
                        //}
1832

  
1833
                        //LMRepresentation prevRep = dataSource.GetRepresentation(endRepID[i - 1]);
1834
                        //placement.PIDRemovePlacement(prevRep);
1835

  
1836

  
1837
                        //application.ActiveDocument.Save();
1838
                        //ReleaseCOMObjects(modelItem);
1839
                        break;
1840
                    }
1841
                }
1842

  
1843
                ReleaseCOMObjects(representation);
1844
            }
1845
        }
1846
        private LMConnector ReModelingLine(LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
1847
        {
1848
            Placement _placement = new Placement();
1849
            LMADataSource dataSource = _placement.PIDDataSource;
1850

  
1851
            string symbolPath = string.Empty;
1852
            #region get symbol path
1853
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
1854
            symbolPath = GetSPPIDFileName(modelItem);
1855
            ReleaseCOMObjects(modelItem);
1856
            #endregion
1857
            bool diagonal = false;
1858
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1859
            LMConnector newConnector = null;
1860
            dynamic OID = prevLMConnector.get_GraphicOID().ToString();
1861
            DependencyObject drawingObject = application.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1862
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1863
            int verticesCount = lineStringGeometry.VertexCount;
1864
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1865

  
1866
            List<double[]> vertices = new List<double[]>();
1867
            for (int i = 1; i <= verticesCount; i++)
1868
            {
1869
                double x = 0;
1870
                double y = 0;
1871
                lineStringGeometry.GetVertex(i, ref x, ref y);
1872
                vertices.Add(new double[] { x, y });
1873
            }
1874

  
1875
            for (int i = 0; i < vertices.Count; i++)
1876
            {
1877
                double[] points = vertices[i];
1878
                // 시작 심볼이 있고 첫번째 좌표일 때
1879
                if (startSymbol != null && i == 0)
1880
                {
1881
                    if (bStart)
1882
                    {
1883
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
1884
                        if (slopeType == SlopeType.HORIZONTAL)
1885
                            placeRunInputs.AddPoint(points[0], -0.1);
1886
                        else if (slopeType == SlopeType.VERTICAL)
1887
                            placeRunInputs.AddPoint(-0.1, points[1]);
1888
                        else
1889
                            placeRunInputs.AddPoint(points[0], -0.1);
1890

  
1891
                        placeRunInputs.AddPoint(points[0], points[1]);
1892
                    }
1893
                    else
1894
                    {
1895
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1], diagonal);
1896
                    }
1897
                }
1898
                // 마지막 심볼이 있고 마지막 좌표일 때
1899
                else if (endSymbol != null && i == vertices.Count - 1)
1900
                {
1901
                    if (bEnd)
1902
                    {
1903
                        placeRunInputs.AddPoint(points[0], points[1]);
1904

  
1905
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
1906
                        if (slopeType == SlopeType.HORIZONTAL)
1907
                            placeRunInputs.AddPoint(points[0], -0.1);
1908
                        else if (slopeType == SlopeType.VERTICAL)
1909
                            placeRunInputs.AddPoint(-0.1, points[1]);
1910
                        else
1911
                            placeRunInputs.AddPoint(points[0], -0.1);
1912
                    }
1913
                    else
1914
                    {
1915
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1], diagonal);
1916
                    }
1917
                }
1918
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
1919
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
1920
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1], diagonal);
1921
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
1922
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
1923
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1], diagonal);
1924
                else
1925
                    placeRunInputs.AddPoint(points[0], points[1]);
1926
            }
1927

  
1928
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
1929
            Thread.Sleep(1000);
1930
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1931

  
1932
            ReleaseCOMObjects(placeRunInputs);
1933
            ReleaseCOMObjects(_LMAItem);
1934
            ReleaseCOMObjects(modelItem);
1935

  
1936
            if (newConnector != null)
1937
            {
1938
                newConnector.Commit();
1939
                if (startSymbol != null && bStart)
1940
                {
1941
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1942
                    placeRunInputs = new PlaceRunInputs();
1943
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
1944
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
1945
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1946
                    if (_LMConnector != null)
1947
                    {
1948
                        _LMConnector.Commit();
1949
                        newConnector = RemoveConnectorForReModelingLine(newConnector);
1950
                        ReleaseCOMObjects(_LMConnector);
1951
                    }
1952
                    ReleaseCOMObjects(placeRunInputs);
1953
                    ReleaseCOMObjects(_LMAItem);
1954
                }
1955

  
1956
                if (endSymbol != null && bEnd)
1957
                {
1958
                    if (startSymbol != null)
1959
                    {
1960
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
1961
                        newConnector = dicVertices.First().Key;
1962
                    }
1963

  
1964
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1965
                    placeRunInputs = new PlaceRunInputs();
1966
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1967
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1968
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1969
                    if (_LMConnector != null)
1970
                    {
1971
                        _LMConnector.Commit();
1972
                        newConnector = RemoveConnectorForReModelingLine(newConnector);
1973
                        ReleaseCOMObjects(_LMConnector);
1974
                    }
1975
                    ReleaseCOMObjects(placeRunInputs);
1976
                    ReleaseCOMObjects(_LMAItem);
1977
                }
1978

  
1979
                
1980
            }
1981
            ReleaseCOMObjects(modelItem);
1982
            return newConnector;
1983
            
1984
        }
1985

  
1986
        private LMConnector RemoveConnectorForReModelingLine(LMConnector connector)
1987
        {
1988
            Placement _placement = new Placement();
1989
            LMADataSource dataSource = _placement.PIDDataSource;
1990

  
1991
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
1992
            foreach (var item in dicVertices)
1993
            {
1994
                if (item.Value.Count == 2)
1995
                {
1996
                    bool result = false;
1997
                    foreach (var point in item.Value)
1998
                    {
1999
                        if (point[0] < 0 || point[1] < 0)
2000
                        {
2001
                            result = true;
2002
                            _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
2003
                            break;
2004
                        }
2005
                    }
2006

  
2007
                    if (result)
2008
                        break;
2009
                }
2010
            }
2011

  
2012
            LMConnector result111 = null;
2013
            foreach (var item in dicVertices)
2014
            {
2015
                if (item.Key.get_ItemStatus() == "Active")
2016
                    result111 = item.Key;
2017
                else
2018
                    ReleaseCOMObjects(item.Key);
2019
            }
2020

  
2021
            return result111;
2022
        }
2023

  
2024
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId, bool ContainZeroLength = true)
2025
        {
2026
            Placement _placement = new Placement();
2027
            LMADataSource dataSource = _placement.PIDDataSource;
2028

  
2029
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2030
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2031

  
2032
            if (modelItem != null)
2033
            {
2034
                foreach (LMRepresentation rep in modelItem.Representations)
2035
                {
2036
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2037
                    {
2038
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2039
                        if (!ContainZeroLength && Convert.ToBoolean(_LMConnector.get_IsZeroLength()))
2040
                        {
2041
                            ReleaseCOMObjects(_LMConnector);
2042
                            _LMConnector = null;
2043
                            continue;
2044
                        }
2045
                        connectorVertices.Add(_LMConnector, new List<double[]>());
2046
                        dynamic OID = rep.get_GraphicOID().ToString();
2047
                        DependencyObject drawingObject = application.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2048
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2049
                        int verticesCount = lineStringGeometry.VertexCount;
2050
                        double[] vertices = null;
2051
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2052
                        for (int i = 0; i < verticesCount; i++)
2053
                        {
2054
                            double x = 0;
2055
                            double y = 0;
2056
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2057
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
2058
                        }
2059
                    }
2060
                }
2061

  
2062
                ReleaseCOMObjects(modelItem);
2063
            }
2064

  
2065
            return connectorVertices;
2066
        }
2067
        private string GetSPPIDFileName(LMModelItem modelItem)
2068
        {
2069
            string symbolPath = null;
2070
            foreach (LMRepresentation rep in modelItem.Representations)
2071
            {
2072
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
2073
                {
2074
                    symbolPath = rep.get_FileName();
2075
                    break;
2076
                }
2077
            }
2078
            return symbolPath;
2079
        }
2080
        private string GetSPPIDFileName(string modelItemId)
2081
        {
2082
            Placement placement = new Placement();
2083
            LMADataSource dataSource = placement.PIDDataSource;
2084

  
2085
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
2086
            string symbolPath = null;
2087
            foreach (LMRepresentation rep in modelItem.Representations)
2088
            {
2089
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
2090
                {
2091
                    symbolPath = rep.get_FileName();
2092
                    break;
2093
                }
2094
            }
2095
            ReleaseCOMObjects(modelItem);
2096
            return symbolPath;
2097
        }
2098
        private List<double[]> GetConnectorVertices(LMConnector connector)
2099
        {
2100
            List<double[]> vertices = new List<double[]>();
2101
            if (connector != null)
2102
            {
2103
                dynamic OID = connector.get_GraphicOID().ToString();
2104
                DependencyObject drawingObject = application.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2105
                Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2106
                int verticesCount = lineStringGeometry.VertexCount;
2107
                double[] value = null;
2108
                lineStringGeometry.GetVertices(ref verticesCount, ref value);
2109
                for (int i = 0; i < verticesCount; i++)
2110
                {
2111
                    double x = 0;
2112
                    double y = 0;
2113
                    lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2114
                    vertices.Add(new double[] { x, y });
2115
                }
2116
            }
2117
            return vertices;
2118
        }
2119
        private void LoopRunTest(LMRepresentation rep, List<string> endRepID, string endID,ref bool end, List<string> findRepID)
2120
        {
2121
            if (!end)
2122
            {
2123
                foreach (LMRelationship item in rep.Relation1Relationships)
2124
                {
2125
                    if (end)
2126
                        break;
2127

  
2128
                    if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID) && item.Item1RepresentationObject.get_ItemStatus() == "Active" &&
2129
                        (item.Item1RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item1RepresentationObject.get_RepresentationClass() == "Connector"))
2130
                    {
2131
                        if (endID != item.Item1RepresentationID)
2132
                        {
2133
                            endRepID.Add(item.Item1RepresentationID);
2134
                            LoopRunTest(item.Item1RepresentationObject, endRepID, endID, ref end, findRepID);
2135
                            if (end)
2136
                                findRepID.Add(item.Item1RepresentationID);
2137
                        }
2138
                        else
2139
                            end = true;
2140
                    }
2141

  
2142
                    if (end)
2143
                        break;
2144

  
2145
                    if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID) && item.Item2RepresentationObject.get_ItemStatus() == "Active" &&
2146
                        (item.Item2RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item2RepresentationObject.get_RepresentationClass() == "Connector"))
2147
                    {
2148
                        if (endID != item.Item2RepresentationID)
2149
                        {
2150
                            endRepID.Add(item.Item2RepresentationID);
2151
                            LoopRunTest(item.Item2RepresentationObject, endRepID, endID, ref end, findRepID);
2152
                            if (end)
2153
                                findRepID.Add(item.Item2RepresentationID);
2154
                        }
2155
                        else
2156
                            end = true;
2157
                    }
2158
                }
2159
            }
2160

  
2161
            if (!end)
2162
            {
2163
                foreach (LMRelationship item in rep.Relation2Relationships)
2164
                {
2165
                    if (end)
2166
                        break;
2167

  
2168
                    if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID) && item.Item1RepresentationObject.get_ItemStatus() == "Active" &&
2169
                        (item.Item1RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item1RepresentationObject.get_RepresentationClass() == "Connector"))
2170
                    {
2171
                        if (endID != item.Item1RepresentationID)
2172
                        {
2173
                            endRepID.Add(item.Item1RepresentationID);
2174
                            LoopRunTest(item.Item1RepresentationObject, endRepID, endID, ref end, findRepID);
2175
                            if (end)
2176
                                findRepID.Add(item.Item1RepresentationID);
2177
                        }
2178
                        else
2179
                            end = true;
2180
                    }
2181

  
2182
                    if (end)
2183
                        break;
2184

  
2185
                    if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID) && item.Item2RepresentationObject.get_ItemStatus() == "Active" &&
2186
                        (item.Item2RepresentationObject.get_RepresentationClass() == "Symbol" || item.Item2RepresentationObject.get_RepresentationClass() == "Connector"))
2187
                    {
2188
                        if (endID != item.Item2RepresentationID)
2189
                        {
2190
                            endRepID.Add(item.Item2RepresentationID);
2191
                            LoopRunTest(item.Item2RepresentationObject, endRepID, endID, ref end, findRepID);
2192
                            if (end)
2193
                                findRepID.Add(item.Item2RepresentationID);
2194
                        }
2195
                        else
2196
                            end = true;
2197
                    }
2198
                }
2199
            }
2200
        }
2201

  
2202
        private void btnOPC_Click(object sender, EventArgs e)
2203
        {
2204
            Placement _placement;
2205
            LMADataSource dataSource;
2206
            _placement = new Placement();
2207
            dataSource = _placement.PIDDataSource;
2208

  
2209
            OPCFlowDirection();
2210

  
2211
            void OPCFlowDirection()
2212
            {
2213
                //current LMDrawing 가져오기
2214
                LMAFilter filter = new LMAFilter();
2215
                LMACriterion criterion = new LMACriterion();
2216
                filter.ItemType = "Drawing";
2217
                criterion.SourceAttributeName = "Name";
2218
                criterion.Operator = "=";
2219
                criterion.set_ValueAttribute(application.ActiveDocument.Name.Replace(".pid", ""));
2220
                filter.get_Criteria().Add(criterion);
2221

  
2222
                LMDrawings drawings = new LMDrawings();
2223
                drawings.Collect(dataSource, Filter: filter);
2224

  
2225
                // Input Drawing Attribute
2226
                LMDrawing drawing = ((dynamic)drawings).Nth(1);
2227

  
2228
                LMAFilter filter2 = new LMAFilter();
2229
                filter2.ItemType = "REPRESENTATION";
2230

  
2231
                LMACriterion criterion2 = new LMACriterion();
2232
                criterion2.SourceAttributeName = "REPRESENTATIONTYPE";
2233
                criterion2.Operator = "=";
2234
                criterion2.set_ValueAttribute("39");
2235
                filter2.get_Criteria().Add(criterion2);
2236

  
2237
                LMRepresentations representations = new LMRepresentations();
2238
                representations.Collect(dataSource, Filter: filter2);
2239

  
2240
                foreach (LMRepresentation representation in representations)
2241
                {
2242
                    if (representation.DrawingID == drawing.Id)
2243
                    {
2244
                        RunOPC(representation);
2245
                    }
2246
                }
2247
                
2248
                ReleaseCOMObjects(filter);
2249
                ReleaseCOMObjects(filter2);
2250
                ReleaseCOMObjects(criterion);
2251
                ReleaseCOMObjects(criterion2);
2252
                ReleaseCOMObjects(drawing);
2253
                ReleaseCOMObjects(drawings);
2254
                ReleaseCOMObjects(representations);
2255
            }
2256

  
2257
            void RunOPC(LMRepresentation representation)
2258
            {
2259
                LMSymbol symbol = dataSource.GetSymbol(representation.Id);
2260
                List<string> endRepId = new List<string>();
2261
                endRepId.Add(symbol.AsLMRepresentation().Id);
2262
                LoopSymbol(symbol, endRepId);
2263
                
2264
                ReleaseCOMObjects(symbol);
2265

  
2266
                void LoopSymbol(LMSymbol loopSymbol, List<string> endRepID)
2267
                {
2268
                    foreach (LMRelationship item in loopSymbol.Relation1Relationships)
2269
                    {
2270
                        if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID))
2271
                        {
2272
                            endRepID.Add(item.Item1RepresentationID);
2273
                            if (item.Item1RepresentationObject.get_RepresentationClass() == "Connector")
2274
                            {
2275
                                LMModelItem modelItem = item.Item1RepresentationObject.ModelItemObject;
2276
                                SetAttribute(modelItem);
2277
                                LoopConnector(dataSource.GetConnector(item.Item1RepresentationID), endRepID);
2278
                            }
2279
                            else if (item.Item1RepresentationObject.get_RepresentationClass() == "Symbol")
2280
                            {
2281
                                LoopSymbol(dataSource.GetSymbol(item.Item1RepresentationID), endRepID);
2282
                            }
2283
                        }
2284

  
2285
                        if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID))
2286
                        {
2287
                            endRepID.Add(item.Item2RepresentationID);
2288
                            if (item.Item2RepresentationObject.get_RepresentationClass() == "Connector")
2289
                            {
2290
                                LMModelItem modelItem = item.Item2RepresentationObject.ModelItemObject;
2291
                                SetAttribute(modelItem);
2292
                                LoopConnector(dataSource.GetConnector(item.Item2RepresentationID), endRepID);
2293
                            }
2294
                            else if (item.Item2RepresentationObject.get_RepresentationClass() == "Symbol")
2295
                            {
2296
                                LoopSymbol(dataSource.GetSymbol(item.Item2RepresentationID), endRepID);
2297
                            }
2298
                        }
2299
                    }
2300

  
2301
                    foreach (LMRelationship item in loopSymbol.Relation2Relationships)
2302
                    {
2303
                        if (!DBNull.Value.Equals(item.Item1RepresentationID) && !endRepID.Contains(item.Item1RepresentationID))
2304
                        {
2305
                            endRepID.Add(item.Item1RepresentationID);
2306
                            if (item.Item1RepresentationObject.get_RepresentationClass() == "Connector")
2307
                            {
2308
                                LMModelItem modelItem = item.Item1RepresentationObject.ModelItemObject;
2309
                                SetAttribute(modelItem);
2310
                                LoopConnector(dataSource.GetConnector(item.Item1RepresentationID), endRepID);
2311
                            }
2312
                            else if (item.Item1RepresentationObject.get_RepresentationClass() == "Symbol")
2313
                            {
2314
                                LoopSymbol(dataSource.GetSymbol(item.Item1RepresentationID), endRepID);
2315
                            }
2316
                        }
2317

  
2318
                        if (!DBNull.Value.Equals(item.Item2RepresentationID) && !endRepID.Contains(item.Item2RepresentationID))
2319
                        {
2320
                            endRepID.Add(item.Item2RepresentationID);
2321
                            if (item.Item2RepresentationObject.get_RepresentationClass() == "Connector")
2322
                            {
2323
                                LMModelItem modelItem = item.Item2RepresentationObject.ModelItemObject;
2324
                                SetAttribute(modelItem);
2325
                                LoopConnector(dataSource.GetConnector(item.Item2RepresentationID), endRepID);
2326
                            }
2327
                            else if (item.Item2RepresentationObject.get_RepresentationClass() == "Symbol")
2328
                            {
2329
                                LoopSymbol(dataSource.GetSymbol(item.Item2RepresentationID), endRepID);
2330
                            }
2331
                        }
2332
                    }
2333

  
2334
                    foreach (LMConnector item in loopSymbol.Connect1Connectors)//나가는것
2335
                    {
2336
                        if (item.get_ItemStatus() != "Active" || endRepID.Contains(item.AsLMRepresentation().Id))
2337
                            continue;
2338

  
2339
                        endRepID.Add(item.AsLMRepresentation().Id);
2340
                        if (item.get_ItemStatus() == "Active")
2341
                        {
2342
                            LMModelItem modelItem = item.ModelItemObject;
2343
                            SetAttribute(modelItem);
2344
                            LoopConnector(item, endRepID);
2345
                        }
2346
                    }
2347

  
2348
                    foreach (LMConnector item in loopSymbol.Connect2Connectors)//들어오는것
2349
                    {
2350
                        if (item.get_ItemStatus() != "Active" || endRepID.Contains(item.AsLMRepresentation().Id))
2351
                            continue;
2352

  
2353
                        endRepID.Add(item.AsLMRepresentation().Id);
2354
                        if (item.get_ItemStatus() == "Active")
2355
                        {
2356
                            LMModelItem modelItem = item.ModelItemObject;
2357
                            SetAttribute(modelItem);
2358
                            LoopConnector(item, endRepID);
2359
                        }
2360
                    }
2361
                }
2362

  
2363
                void LoopConnector(LMConnector connector, List<string> endRepID)
2364
                {
2365
                    if (connector.ConnectItem1SymbolObject != null && !endRepID.Contains(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id))
2366
                    {
2367
                        endRepID.Add(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id);
2368
                        //LoopSymbol(connector.ConnectItem1SymbolObject, endRepID);
2369
                    }
2370

  
2371
                    if (connector.ConnectItem2SymbolObject != null && !endRepID.Contains(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id))
2372
                    {
2373
                        endRepID.Add(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id);
2374
                        //LoopSymbol(connector.ConnectItem2SymbolObject, endRepID);
2375
                    }
2376
                }
2377
            }
2378

  
2379
            void SetAttribute(LMModelItem modelItem)
2380
            {
2381
                LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
2382
                if (attribute != null)
2383
                    attribute.set_Value("End 1 is upstream (Inlet)");
2384
                modelItem.Commit();
2385
            }
2386

  
2387
            ReleaseCOMObjects(_placement);
2388
            ReleaseCOMObjects(dataSource);
2389

  
2390
            MessageBox.Show("End OPC Flow Direction");
2391
        }
2392

  
2393
        private void btnCreateStreamBreak_Click(object sender, EventArgs e)
2394
        {
2395
            Placement _placement;
2396
            LMADataSource dataSource;
2397

  
2398
            StreamNoBreak();
2399

  
2400
            void StreamNoBreak()
2401
            {
2402
                
2403
                _placement = new Placement();
2404
                dataSource = _placement.PIDDataSource;
2405

  
2406
                OPCFlowDirection();
2407

  
2408
                void OPCFlowDirection()
2409
                {
2410
                    //current LMDrawing 가져오기
2411
                    LMAFilter filter = new LMAFilter();
2412
                    LMACriterion criterion = new LMACriterion();
2413
                    filter.ItemType = "Drawing";
2414
                    criterion.SourceAttributeName = "Name";
2415
                    criterion.Operator = "=";
2416
                    criterion.set_ValueAttribute(application.ActiveDocument.Name.Replace(".pid", ""));
2417
                    filter.get_Criteria().Add(criterion);
2418

  
2419
                    LMDrawings drawings = new LMDrawings();
2420
                    drawings.Collect(dataSource, Filter: filter);
2421

  
2422
                    // Input Drawing Attribute
2423
                    LMDrawing drawing = ((dynamic)drawings).Nth(1);
2424

  
2425
                    LMAFilter filter2 = new LMAFilter();
2426
                    filter2.ItemType = "REPRESENTATION";
2427

  
2428
                    LMACriterion criterion2 = new LMACriterion();
2429
                    criterion2.SourceAttributeName = "REPRESENTATIONTYPE";
2430
                    criterion2.Operator = "=";
2431
                    criterion2.set_ValueAttribute("46");
2432
                    filter2.get_Criteria().Add(criterion2);
2433

  
2434
                    LMRepresentations representations = new LMRepresentations();
2435
                    representations.Collect(dataSource, Filter: filter2);
2436

  
2437
                    foreach (LMRepresentation representation in representations)
2438
                    {
2439
                        if (representation.DrawingID == drawing.Id)
2440
                        {
2441
                            LMSymbol symbol = dataSource.GetSymbol(representation.Id);
2442
                            CreateSpec(symbol);
2443
                        }
2444
                    }
2445

  
2446
                    ReleaseCOMObjects(filter);
2447
                    ReleaseCOMObjects(filter2);
2448
                    ReleaseCOMObjects(criterion);
2449
                    ReleaseCOMObjects(criterion2);
2450
                    ReleaseCOMObjects(drawing);
2451
                    ReleaseCOMObjects(drawings);
2452
                    ReleaseCOMObjects(representations);
2453
                }
2454
            }
2455

  
2456
            void CreateSpec(LMSymbol symbol)
2457
            {
2458
                ZoomObjectByGraphicOID(symbol.get_XCoordinate(), symbol.get_YCoordinate());
2459

  
2460
                foreach (LMConnector item in symbol.Connect1Connectors)
2461
                {
2462
                    if (item.get_ItemStatus() == "Active")
2463
                    {
2464
                        Array array = new double[] { 0, symbol.get_XCoordinate(), symbol.get_YCoordinate() };
2465
                        LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(@"\Piping\Segment Breaks\Above\stream Number Break.sym", ref array, LabeledItem: item.AsLMRepresentation(), IsLeaderVisible: true);
2466
                    }
2467
                }
2468

  
2469
                foreach (LMConnector item in symbol.Connect2Connectors)
2470
                {
2471
                    if (item.get_ItemStatus() == "Active")
2472
                    {
2473
                        Array array = new double[] { 0, symbol.get_XCoordinate(), symbol.get_YCoordinate() };
2474
                        LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(@"\Piping\Segment Breaks\Above\stream Number Break.sym", ref array, LabeledItem: item.AsLMRepresentation(), IsLeaderVisible: true);
2475
                    }
2476
                }
2477

  
2478
                Thread.Sleep(500);
2479
            }
2480

  
2481
            MessageBox.Show("End Modeling");
2482
        }
2483
        
2484
        private void btnPipeRunBreak_Click(object sender, EventArgs e)
2485
        {
2486
            Placement placement = new Placement();
2487
            LMADataSource dataSource = placement.PIDDataSource;
2488

  
2489
            string sFrom = textEdit1.EditValue.ToString();
2490
            string sTo = textEdit2.EditValue.ToString();
2491

  
2492
            LMModelItem item1 = dataSource.GetModelItem(sFrom);
2493
            LMModelItem item2 = dataSource.GetModelItem(sTo);
2494
            if (item1 != null && item1.Representations.Count == 1 &&
2495
                item2 != null && item2.Representations.Count == 1)
2496
            {
2497
                LMSymbol startSymbol = dataSource.GetSymbol(item1.Representations.Nth[1].Id);
2498
                LMSymbol endSymbol = dataSource.GetSymbol(item2.Representations.Nth[1].Id);
2499

  
2500
                if (startSymbol != null && endSymbol != null)
2501
                {
2502
                    FindRun(startSymbol, endSymbol, @"\Piping\Segment Breaks\End of Group.sym");
2503
                }
2504
                else
2505
                {
2506
                    MessageBox.Show("From To 심볼 확인");
2507
                }
2508
            }
2509
            else
2510
            {
2511
                MessageBox.Show("From To 심볼 확인");
2512
            }
2513
        }
2514

  
2515
        private void btnSegmentBreak_Click(object sender, EventArgs e)
2516
        {
2517
            Placement placement = new Placement();
2518
            LMADataSource dataSource = placement.PIDDataSource;
2519

  
2520
            string sFrom = textEdit1.EditValue.ToString();
2521
            string sTo = textEdit2.EditValue.ToString();
2522

  
2523
            LMModelItem item1 = dataSource.GetModelItem(sFrom);
2524
            LMModelItem item2 = dataSource.GetModelItem(sTo);
2525
            if (item1 != null && item1.Representations.Count == 1 &&
2526
                item2 != null && item2.Representations.Count == 1)
2527
            {
2528
                LMSymbol startSymbol = dataSource.GetSymbol(item1.Representations.Nth[1].Id);
2529
                LMSymbol endSymbol = dataSource.GetSymbol(item2.Representations.Nth[1].Id);
2530

  
2531
                if (startSymbol != null && endSymbol != null)
2532
                {
2533
                    FindRun(startSymbol, endSymbol, @"\Piping\Segment Breaks\Max Design Press - Temp.sym");
2534
                }
2535
                else
2536
                {
2537
                    MessageBox.Show("From To 심볼 확인");
2538
                }
2539
            }
2540
            else
2541
            {
2542
                MessageBox.Show("From To 심볼 확인");
2543
            }
2544
        }
2545

  
2546
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
2547
        {
2548
            if (application.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
2549
            {
2550
                double minX = 0;
2551
                double minY = 0;
2552
                double maxX = 0;
2553
                double maxY = 0;
2554
                application.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
2555
                application.ActiveWindow.ZoomArea2(minX - 0.01, minY - 0.01, maxX + 0.01, maxY + 0.01, null);
2556

  
2557
                Thread.Sleep(milliseconds);
2558
            }
2559
        }
2560

  
2561
        private void ZoomObjectByGraphicOID(double x, double y, int milliseconds = 150)
2562
        {
2563
            application.ActiveWindow.ZoomArea2(x - 0.01, y - 0.01, x + 0.01, y + 0.01, null);
2564
            Thread.Sleep(milliseconds);
2565
        }
2566
        #endregion
2567

  
2568
        
1761 2569
    }
1762 2570
}

내보내기 Unified diff

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