hytos / DTI_PID / APIDConverter / AutoModeling.cs @ 74a0c9d6
이력 | 보기 | 이력해설 | 다운로드 (5.94 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Configuration; |
4 |
using System.Data; |
5 |
using System.Data.Common; |
6 |
using System.Data.SqlClient; |
7 |
using System.IO; |
8 |
|
9 |
using Autodesk.AutoCAD.ApplicationServices; |
10 |
using Autodesk.AutoCAD.ApplicationServices.Core; |
11 |
using Autodesk.AutoCAD.DatabaseServices; |
12 |
using Autodesk.AutoCAD.EditorInput; |
13 |
using Autodesk.AutoCAD.Geometry; |
14 |
using Autodesk.AutoCAD.Interop; |
15 |
using Autodesk.AutoCAD.Interop.Common; |
16 |
using Autodesk.AutoCAD.Runtime; |
17 |
using Autodesk.AutoCAD.Windows; |
18 |
|
19 |
|
20 |
namespace AVEVA.PID.CustomizationUtility |
21 |
{ |
22 |
public class AutoModeling |
23 |
{ |
24 |
Autodesk.Windows.RibbonCombo pipeStyleCombo = null; |
25 |
Autodesk.Windows.RibbonChecklistButton autoLabelCheckListButton = null; |
26 |
|
27 |
private void InitGUI() |
28 |
{ |
29 |
Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_PIPE_PANEL"); |
30 |
object objPipeStyle = GUIUtils.FindItem(items, "PIPESTYLE"); |
31 |
if (objPipeStyle != null) |
32 |
pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo; |
33 |
object objAutoLabel = GUIUtils.FindItem(items, "Auto Label"); |
34 |
if (objAutoLabel != null) |
35 |
autoLabelCheckListButton = objAutoLabel as Autodesk.Windows.RibbonChecklistButton; |
36 |
|
37 |
|
38 |
} |
39 |
private void SetAutoLabelUnCehck() |
40 |
{ |
41 |
if (autoLabelCheckListButton != null) |
42 |
{ |
43 |
foreach (var item in autoLabelCheckListButton.Items) |
44 |
{ |
45 |
if (item.GetType() == typeof(Autodesk.Windows.RibbonButton)) |
46 |
{ |
47 |
Autodesk.Windows.RibbonButton ribbonButton = item as Autodesk.Windows.RibbonButton; |
48 |
if (ribbonButton.IsChecked) |
49 |
ribbonButton.IsChecked = false; |
50 |
} |
51 |
} |
52 |
} |
53 |
} |
54 |
|
55 |
private void SetPipeStyle(string style) |
56 |
{ |
57 |
if (pipeStyleCombo.Current != null) |
58 |
{ |
59 |
Autodesk.Windows.RibbonButton button = pipeStyleCombo.Current as Autodesk.Windows.RibbonButton; |
60 |
if (button.AutomationName != style) |
61 |
{ |
62 |
foreach (var item in pipeStyleCombo.Items) |
63 |
{ |
64 |
Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
65 |
if (loop.AutomationName == style) |
66 |
{ |
67 |
pipeStyleCombo.Current = loop; |
68 |
break; |
69 |
} |
70 |
} |
71 |
} |
72 |
} |
73 |
} |
74 |
|
75 |
private string ReadDrawingLastLine() |
76 |
{ |
77 |
string sHandle = string.Empty; |
78 |
SqlConnection connection = null; |
79 |
try |
80 |
{ |
81 |
connection = new SqlConnection(); |
82 |
connection.ConnectionString = DB.DB.GetConnectionString(); |
83 |
connection.Open(); |
84 |
|
85 |
string strQry = string.Format("Select Handle from Pipe Where id = (SELECT MAX(id) FROM Pipe WHERE DrawingId = '{0}')", "Test"); |
86 |
SqlCommand cmd = new SqlCommand(); |
87 |
cmd.Connection = connection; |
88 |
cmd.CommandText = strQry; |
89 |
cmd.CommandType = CommandType.Text; |
90 |
|
91 |
SqlDataAdapter da = new SqlDataAdapter(cmd); |
92 |
System.Data.DataTable dt = new System.Data.DataTable(); |
93 |
da.Fill(dt); |
94 |
if (dt.Rows.Count == 1) |
95 |
sHandle = dt.Rows[0][0].ToString(); |
96 |
|
97 |
dt.Dispose(); |
98 |
da.Dispose(); |
99 |
} |
100 |
catch (System.Exception) |
101 |
{ } |
102 |
finally |
103 |
{ |
104 |
if (connection != null) |
105 |
connection.Close(); |
106 |
} |
107 |
|
108 |
return sHandle; |
109 |
} |
110 |
|
111 |
#region Drawing Method |
112 |
|
113 |
private string DrawPipe(string style, List<string> coordinates) |
114 |
{ |
115 |
SetPipeStyle(style); |
116 |
|
117 |
string prevHandle = ReadDrawingLastLine(); |
118 |
|
119 |
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
120 |
Editor editor = acDoc.Editor; |
121 |
List<object> commandParam = new List<object>(); |
122 |
//command name |
123 |
commandParam.Add("DRPIPE"); |
124 |
//coordinate |
125 |
foreach (var item in coordinates) |
126 |
commandParam.Add(item); |
127 |
//enter |
128 |
commandParam.Add(null); |
129 |
//enter |
130 |
commandParam.Add(null); |
131 |
|
132 |
editor.Command(commandParam.ToArray()); |
133 |
|
134 |
string newHandle = ReadDrawingLastLine(); |
135 |
if (prevHandle == newHandle) |
136 |
return string.Empty; |
137 |
|
138 |
return newHandle; |
139 |
} |
140 |
private void DrawPipe(string style, List<string> coordinates, ObjectId objectId) |
141 |
{ |
142 |
SetPipeStyle(style); |
143 |
|
144 |
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
145 |
Editor editor = acDoc.Editor; |
146 |
List<object> commandParam = new List<object>(); |
147 |
//command name |
148 |
commandParam.Add("DRPIPE"); |
149 |
//coordinate |
150 |
foreach (var item in coordinates) |
151 |
commandParam.Add(item); |
152 |
//enter |
153 |
commandParam.Add(null); |
154 |
|
155 |
//Input Object ID |
156 |
commandParam.Add(objectId); |
157 |
|
158 |
//enter |
159 |
commandParam.Add(null); |
160 |
|
161 |
editor.Command(commandParam.ToArray()); |
162 |
} |
163 |
|
164 |
#endregion |
165 |
|
166 |
#region Test Source |
167 |
|
168 |
public void test() |
169 |
{ |
170 |
InitGUI(); |
171 |
|
172 |
DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" }); |
173 |
|
174 |
DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" }); |
175 |
|
176 |
DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" }); |
177 |
} |
178 |
|
179 |
public static void TEST() |
180 |
{ |
181 |
AutoModeling auto = new AutoModeling(); |
182 |
auto.test(); |
183 |
} |
184 |
#endregion |
185 |
} |
186 |
} |