hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 64922e03
이력 | 보기 | 이력해설 | 다운로드 (72.4 KB)
1 | 65881d60 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Drawing; |
||
5 | using System.Data; |
||
6 | using System.Linq; |
||
7 | using System.Text; |
||
8 | using System.Threading.Tasks; |
||
9 | using System.Windows.Forms; |
||
10 | using System.Threading; |
||
11 | 69b7387a | gaqhf | using System.IO; |
12 | 65881d60 | gaqhf | using Microsoft.VisualBasic; |
13 | e3e2d41f | gaqhf | using Ingr.RAD2D; |
14 | d19ae675 | gaqhf | using Converter.BaseModel; |
15 | using Converter.SPPID.Properties; |
||
16 | using Converter.SPPID.DB; |
||
17 | using Converter.SPPID.Util; |
||
18 | using Converter.SPPID.Form; |
||
19 | using Converter.SPPID.Model; |
||
20 | 1ba9c671 | gaqhf | using Plaice; |
21 | using Llama; |
||
22 | ca214bc3 | gaqhf | using DevExpress.XtraSplashScreen; |
23 | 224535bb | gaqhf | using Newtonsoft.Json; |
24 | 9628f54b | gaqhf | using System.Runtime.InteropServices; |
25 | 4941f5fe | gaqhf | using System.Reflection; |
26 | 154d8f43 | gaqhf | using Converter.SPPID.OPC; |
27 | 65881d60 | gaqhf | |
28 | namespace Converter.SPPID.Wrapper |
||
29 | { |
||
30 | public partial class ConverterDocking : UserControl |
||
31 | { |
||
32 | 4941f5fe | gaqhf | Ingr.RAD2D.Application application; |
33 | f14b4e3b | gaqhf | static bool addEvent = false; |
34 | 65881d60 | gaqhf | public ConverterDocking() |
35 | { |
||
36 | InitializeComponent(); |
||
37 | c3e8fa8e | gaqhf | spinEditSymmetry.Properties.Mask.EditMask = "f0"; |
38 | 4941f5fe | gaqhf | dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
39 | WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
||
40 | application = wApp.RADApplication; |
||
41 | d4c3e39f | gaqhf | |
42 | 4941f5fe | gaqhf | ReleaseCOMObjects(dApplication); |
43 | dApplication = null; |
||
44 | 6a7573b0 | gaqhf | try |
45 | { |
||
46 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
47 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
48 | 154d8f43 | gaqhf | |
49 | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
||
50 | 8847ea67 | gaqhf | _ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
51 | _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
||
52 | _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
||
53 | _ProjectInfo.Port = Settings.Default.ProjectPort; |
||
54 | _ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
||
55 | _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
||
56 | 25c5df17 | gaqhf | if (Project_DB.ConnTestAndCreateTable()) |
57 | { |
||
58 | _ProjectInfo.Enable = true; |
||
59 | layoutControlGroup3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
||
60 | |||
61 | DataTable dt = Project_DB.SelectSetting(); |
||
62 | foreach (DataRow item in dt.Rows) |
||
63 | { |
||
64 | string settingType = item["SettingType"].ToString(); |
||
65 | if (settingType == "ETCSetting") |
||
66 | SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString()); |
||
67 | else if (settingType == "GridSetting") |
||
68 | SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString()); |
||
69 | } |
||
70 | } |
||
71 | else |
||
72 | { |
||
73 | layoutControlGroup3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
||
74 | } |
||
75 | f14b4e3b | gaqhf | |
76 | if (!addEvent) |
||
77 | { |
||
78 | application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit; |
||
79 | addEvent = true; |
||
80 | } |
||
81 | 6a7573b0 | gaqhf | } |
82 | catch (Exception ex) |
||
83 | { |
||
84 | StringBuilder sb = new StringBuilder(); |
||
85 | sb.AppendLine(ex.Message); |
||
86 | sb.AppendLine(ex.StackTrace); |
||
87 | MessageBox.Show(sb.ToString()); |
||
88 | } |
||
89 | 65881d60 | gaqhf | } |
90 | 1b09fe17 | gaqhf | private void ApplicationEvents_ApplicationExit(out bool cancel) |
91 | { |
||
92 | cancel = false; |
||
93 | } |
||
94 | 5a9396ae | humkyung | /// <summary> |
95 | /// 선택한 도면들을 읽어서 SPPID로 변환한다. |
||
96 | /// </summary> |
||
97 | /// <param name="sender"></param> |
||
98 | /// <param name="e"></param> |
||
99 | e3e2d41f | gaqhf | private void btnConverter_Click(object sender, EventArgs e) |
100 | 65881d60 | gaqhf | { |
101 | 1ba9c671 | gaqhf | ConverterForm converterForm = new ConverterForm(); |
102 | if (converterForm.ShowDialog() == DialogResult.OK) |
||
103 | 65881d60 | gaqhf | { |
104 | 4941f5fe | gaqhf | //Ingr.RAD2D.Document doc = application.Documents.Add(); |
105 | |||
106 | 1ba9c671 | gaqhf | try |
107 | { |
||
108 | CloseOPCForm.Run(); |
||
109 | ca214bc3 | gaqhf | |
110 | d5ec4d0f | gaqhf | for (int i = 0; i < converterForm.Documents.Count; i++) |
111 | 1ba9c671 | gaqhf | { |
112 | d5ec4d0f | gaqhf | SPPID_Document document = converterForm.Documents[i]; |
113 | 1ba9c671 | gaqhf | if (document.SetSPPIDMapping() && document.Enable) |
114 | { |
||
115 | bccacd6c | gaqhf | using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked)) |
116 | 5a9396ae | humkyung | { |
117 | modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
||
118 | modeling.Run(); |
||
119 | } |
||
120 | 1ba9c671 | gaqhf | } |
121 | } |
||
122 | } |
||
123 | catch (Exception ex) |
||
124 | { |
||
125 | MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
126 | } |
||
127 | finally |
||
128 | d19ae675 | gaqhf | { |
129 | 1ba9c671 | gaqhf | CloseOPCForm.Stop(); |
130 | 4941f5fe | gaqhf | |
131 | //doc.SaveOnClose = false; |
||
132 | //doc.Close(false); |
||
133 | |||
134 | //dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
||
135 | //dApplication.Drawings[1].CloseDrawing(false); |
||
136 | //ReleaseCOMObjects(dApplication); |
||
137 | //dApplication = null; |
||
138 | 1ba9c671 | gaqhf | } |
139 | |||
140 | MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | 69b7387a | gaqhf | private void btnLinkOPC_Click(object sender, EventArgs e) |
145 | { |
||
146 | 154d8f43 | gaqhf | DataTable tOPCInfo = Project_DB.SelectOPCInfo(); |
147 | DataTable tOPCRelations = Project_DB.SelectOPCRelations(); |
||
148 | DataTable tDrawingInfo = Project_DB.SelectDrawingInfo(); |
||
149 | dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
||
150 | |||
151 | foreach (DataRow row in tOPCInfo.Rows) |
||
152 | { |
||
153 | if (!Convert.ToBoolean(row["PAIRED"])) |
||
154 | { |
||
155 | string drawingUID = row["ID2_DRAWING_UID"].ToString(); |
||
156 | string OPCUID = row["ID2_OPC_UID"].ToString(); |
||
157 | DataRow[] rows = tOPCRelations.Select(string.Format("(From_Drawings_UID = '{0}' AND From_OPC_UID = '{1}') OR (To_Drawings_UID = '{0}' AND To_OPC_UID = '{1}')", drawingUID, OPCUID)); |
||
158 | 69b7387a | gaqhf | |
159 | 154d8f43 | gaqhf | if (rows.Length == 2) |
160 | { |
||
161 | string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString(); |
||
162 | string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString(); |
||
163 | string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString(); |
||
164 | string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString(); |
||
165 | string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString(); |
||
166 | string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString(); |
||
167 | string toOPCUID1 = rows[0]["To_OPC_UID"].ToString(); |
||
168 | string toOPCUID2 = rows[1]["To_OPC_UID"].ToString(); |
||
169 | |||
170 | DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1)); |
||
171 | DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1)); |
||
172 | 58993ba9 | gaqhf | DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1)); |
173 | DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1)); |
||
174 | 154d8f43 | gaqhf | |
175 | 58993ba9 | gaqhf | if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1) |
176 | 154d8f43 | gaqhf | { |
177 | 58993ba9 | gaqhf | DataRow fromOPCInfoRow = fromOPCInfoRows[0]; |
178 | DataRow toOPCInfoRow = toOPCInfoRows[0]; |
||
179 | 154d8f43 | gaqhf | string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
180 | string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
||
181 | string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString(); |
||
182 | 58993ba9 | gaqhf | List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString()); |
183 | b7a29053 | gaqhf | AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes); |
184 | 154d8f43 | gaqhf | if (opc.Run()) |
185 | { |
||
186 | fromOPCInfoRow["PAIRED"] = true; |
||
187 | toOPCInfoRow["PAIRED"] = true; |
||
188 | |||
189 | Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
||
190 | Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | |||
197 | tOPCInfo.Dispose(); |
||
198 | tOPCRelations.Dispose(); |
||
199 | tDrawingInfo.Dispose(); |
||
200 | ReleaseCOMObjects(dApplication); |
||
201 | dApplication = null; |
||
202 | 58993ba9 | gaqhf | |
203 | MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
204 | 69b7387a | gaqhf | } |
205 | |||
206 | 4fb0f8d5 | gaqhf | public void ReleaseCOMObjects(params object[] objVars) |
207 | { |
||
208 | int intNewRefCount = 0; |
||
209 | foreach (object obj in objVars) |
||
210 | { |
||
211 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
212 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
213 | } |
||
214 | } |
||
215 | |||
216 | 6a7573b0 | gaqhf | private void btnGetDrawingSize_Click(object sender, EventArgs e) |
217 | 1ba9c671 | gaqhf | { |
218 | d4c3e39f | gaqhf | dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
219 | WrapperApplication wApp = new WrapperApplication(application.Application); |
||
220 | Ingr.RAD2D.Application radApp = wApp.RADApplication; |
||
221 | |||
222 | 6a7573b0 | gaqhf | if (radApp.ActiveSelectSet.Count > 0) |
223 | 65881d60 | gaqhf | { |
224 | 6a7573b0 | gaqhf | DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
225 | if (line2D != null) |
||
226 | 1ba9c671 | gaqhf | { |
227 | 6a7573b0 | gaqhf | double minX = 0; |
228 | double minY = 0; |
||
229 | double maxX = 0; |
||
230 | double maxY = 0; |
||
231 | line2D.Range(out minX, out minY, out maxX, out maxY); |
||
232 | |||
233 | Settings.Default.DrawingX = maxX - minX; |
||
234 | Settings.Default.DrawingY = maxY - minY; |
||
235 | Settings.Default.Save(); |
||
236 | |||
237 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
238 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
239 | 1ba9c671 | gaqhf | } |
240 | 6a7573b0 | gaqhf | else |
241 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
242 | 65881d60 | gaqhf | } |
243 | 6a7573b0 | gaqhf | else |
244 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
245 | } |
||
246 | 7e4a64a3 | gaqhf | |
247 | 82c7f66d | gaqhf | #region SPPID Utils |
248 | 5a47c65c | gaqhf | |
249 | 29ac1959 | gaqhf | #region Symmetry |
250 | 82c7f66d | gaqhf | private void btnSymmetry_Click(object sender, EventArgs e) |
251 | { |
||
252 | c3e8fa8e | gaqhf | if (application.ActiveSelectSet.Count == 1 && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d)) |
253 | { |
||
254 | int symCount = (int)spinEditSymmetry.Value; |
||
255 | Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
||
256 | double x, y; |
||
257 | symbol.GetOrigin(out x, out y); |
||
258 | string rep = GetRepresentationId(symbol); |
||
259 | List<string> verticalRepID = new List<string>(); |
||
260 | List<string> horizontalRepID = new List<string>(); |
||
261 | |||
262 | if ((symbol.LinearName.Contains("Piping") || |
||
263 | symbol.LinearName.Contains("Instrument")) && |
||
264 | !string.IsNullOrEmpty(rep)) |
||
265 | { |
||
266 | Placement placement = new Placement(); |
||
267 | LMADataSource dataSource = placement.PIDDataSource; |
||
268 | List<List<string>> datas = SetSymbol(dataSource, rep, x, y, symCount); |
||
269 | Dictionary<SymmetryArrow, List<string>> resultDatas = new Dictionary<SymmetryArrow, List<string>>(); |
||
270 | if (datas.Count >= 2 && datas.Find(loop => loop.Count != symCount) == null) |
||
271 | { |
||
272 | SymmetryArrow arrow = SymmetryArrow.None; |
||
273 | foreach (var data in datas) |
||
274 | { |
||
275 | LMSymbol firstSymbol = dataSource.GetSymbol(data[0]); |
||
276 | double fX = firstSymbol.get_XCoordinate(); |
||
277 | double fY = firstSymbol.get_YCoordinate(); |
||
278 | |||
279 | SlopeType type = SPPIDUtil.CalcSlope(x, y, fX, fY, 1); |
||
280 | if (type == SlopeType.HORIZONTAL) |
||
281 | { |
||
282 | if (fX < x) |
||
283 | { |
||
284 | arrow |= SymmetryArrow.Left; |
||
285 | resultDatas.Add(SymmetryArrow.Left, data); |
||
286 | } |
||
287 | else |
||
288 | { |
||
289 | arrow |= SymmetryArrow.Right; |
||
290 | resultDatas.Add(SymmetryArrow.Right, data); |
||
291 | } |
||
292 | |||
293 | } |
||
294 | else if (type == SlopeType.VERTICAL) |
||
295 | { |
||
296 | if (fY < y) |
||
297 | { |
||
298 | arrow |= SymmetryArrow.Down; |
||
299 | resultDatas.Add(SymmetryArrow.Down, data); |
||
300 | } |
||
301 | else |
||
302 | { |
||
303 | arrow |= SymmetryArrow.Up; |
||
304 | resultDatas.Add(SymmetryArrow.Up, data); |
||
305 | } |
||
306 | } |
||
307 | |||
308 | ReleaseCOMObjects(firstSymbol); |
||
309 | } |
||
310 | |||
311 | SymmetryForm form = new SymmetryForm(arrow); |
||
312 | if (form.ShowDialog() == DialogResult.OK) |
||
313 | { |
||
314 | MoveByResult(dataSource, resultDatas, x, y, form.Result, rep); |
||
315 | } |
||
316 | } |
||
317 | else |
||
318 | MessageBox.Show("Check Symmetry Rules", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
319 | ReleaseCOMObjects(dataSource); |
||
320 | ReleaseCOMObjects(placement); |
||
321 | } |
||
322 | } |
||
323 | |||
324 | return; |
||
325 | |||
326 | List<Symbol2d> symbols = new List<Symbol2d>(); |
||
327 | foreach (var item in application.ActiveSelectSet) |
||
328 | { |
||
329 | Type type = item.GetType(); |
||
330 | if (type == typeof(Symbol2d)) |
||
331 | { |
||
332 | Symbol2d symbol = item as Symbol2d; |
||
333 | if (symbol.LinearName.Contains("Piping") || |
||
334 | symbol.LinearName.Contains("Instrument")) |
||
335 | symbols.Add(symbol); |
||
336 | } |
||
337 | //if (item.GetType() == typeof(Symbol2d) || item.GetType() == typeof(Point2d)) |
||
338 | // items.Add(item); |
||
339 | } |
||
340 | |||
341 | List<Symbol2d> verticalSymbols = new List<Symbol2d>(); |
||
342 | List<Symbol2d> horizontalSymbols = new List<Symbol2d>(); |
||
343 | Symbol2d mainSymbol = null; |
||
344 | for (int i = 0; i < symbols.Count - 1; i++) |
||
345 | { |
||
346 | Symbol2d symbol1 = symbols[i]; |
||
347 | for (int j = 1; j < symbols.Count; j++) |
||
348 | { |
||
349 | Symbol2d symbol2 = symbols[j]; |
||
350 | |||
351 | if (symbol1 != symbol2) |
||
352 | { |
||
353 | double x1, y1, x2, y2; |
||
354 | symbol1.GetOrigin(out x1, out y1); |
||
355 | symbol2.GetOrigin(out x2, out y2); |
||
356 | SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 1); |
||
357 | if (slopeType == SlopeType.HORIZONTAL) |
||
358 | { |
||
359 | if (!horizontalSymbols.Contains(symbol1)) |
||
360 | horizontalSymbols.Add(symbol1); |
||
361 | if (!horizontalSymbols.Contains(symbol2)) |
||
362 | horizontalSymbols.Add(symbol2); |
||
363 | |||
364 | if (verticalSymbols.Contains(symbol1)) |
||
365 | mainSymbol = symbol1; |
||
366 | if (verticalSymbols.Contains(symbol2)) |
||
367 | mainSymbol = symbol2; |
||
368 | } |
||
369 | else if (slopeType == SlopeType.VERTICAL) |
||
370 | { |
||
371 | if (!verticalSymbols.Contains(symbol1)) |
||
372 | verticalSymbols.Add(symbol1); |
||
373 | if (!verticalSymbols.Contains(symbol2)) |
||
374 | verticalSymbols.Add(symbol2); |
||
375 | |||
376 | if (horizontalSymbols.Contains(symbol1)) |
||
377 | mainSymbol = symbol1; |
||
378 | if (horizontalSymbols.Contains(symbol2)) |
||
379 | mainSymbol = symbol2; |
||
380 | } |
||
381 | } |
||
382 | } |
||
383 | } |
||
384 | |||
385 | application.ActiveSelectSet.RemoveAll(); |
||
386 | foreach (var item in verticalSymbols) |
||
387 | application.ActiveSelectSet.Add(item); |
||
388 | foreach (var item in horizontalSymbols) |
||
389 | application.ActiveSelectSet.Add(item); |
||
390 | |||
391 | |||
392 | if (MessageBox.Show("Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) |
||
393 | { |
||
394 | application.ActiveSelectSet.RemoveAll(); |
||
395 | |||
396 | } |
||
397 | } |
||
398 | private void MoveByResult(LMADataSource dataSource,Dictionary<SymmetryArrow, List<string>> resultDatas, double x, double y, SymmetryArrow arrow, string centerRepID) |
||
399 | { |
||
400 | List<string> datas = resultDatas[arrow]; |
||
401 | foreach (var item in resultDatas) |
||
402 | { |
||
403 | if (item.Key != arrow) |
||
404 | { |
||
405 | for (int i = 0; i < item.Value.Count; i++) |
||
406 | { |
||
407 | Symbol2d moveSymbol2d = GetSymbol2DByRepID(dataSource, item.Value[i]); |
||
408 | Symbol2d symbol2d = GetSymbol2DByRepID(dataSource, datas[i]); |
||
409 | |||
410 | double x1, y1, x2, y2; |
||
411 | symbol2d.GetOrigin(out x1, out y1); |
||
412 | moveSymbol2d.GetOrigin(out x2, out y2); |
||
413 | double distance = SPPIDUtil.CalcPointToPointdDistance(x, y, x1, y1); |
||
414 | |||
415 | 77d6e710 | gaqhf | string symbol1RepID; |
416 | string symbol2RepID; |
||
417 | c3e8fa8e | gaqhf | List<Point2d> point2ds; |
418 | if (i == 0) |
||
419 | 77d6e710 | gaqhf | { |
420 | symbol1RepID = centerRepID; |
||
421 | symbol2RepID = item.Value[i]; |
||
422 | } |
||
423 | c3e8fa8e | gaqhf | else |
424 | 77d6e710 | gaqhf | { |
425 | symbol1RepID = item.Value[i - 1]; |
||
426 | symbol2RepID = item.Value[i]; |
||
427 | } |
||
428 | point2ds = FindAllPoint2d(dataSource, symbol1RepID, symbol2RepID); |
||
429 | c3e8fa8e | gaqhf | double moveX = 0; |
430 | double moveY = 0; |
||
431 | |||
432 | if (item.Key == SymmetryArrow.Left) |
||
433 | moveX = x - distance - x2; |
||
434 | else if (item.Key == SymmetryArrow.Right) |
||
435 | moveX = x + distance - x2; |
||
436 | else if (item.Key == SymmetryArrow.Down) |
||
437 | moveY = y - distance - y2; |
||
438 | else if (item.Key == SymmetryArrow.Up) |
||
439 | moveY = y + distance - y2; |
||
440 | |||
441 | moveSymbol2d.Move(0, 0, moveX, moveY); |
||
442 | MovePoint2d(dataSource, item.Value[i], arrow, moveX, moveY); |
||
443 | foreach (var point in point2ds) |
||
444 | 77d6e710 | gaqhf | { |
445 | LMSymbol branch = dataSource.GetSymbol(GetRepresentationId(point)); |
||
446 | LMSymbol connSymbol = GetFirstSymbolBySlope(dataSource, branch, symbol1RepID, symbol2RepID); |
||
447 | c3e8fa8e | gaqhf | point.Move(0, 0, moveX, moveY); |
448 | 77d6e710 | gaqhf | if (connSymbol != null) |
449 | { |
||
450 | Symbol2d connSymbol2d = GetSymbol2DByRepID(dataSource, connSymbol.AsLMRepresentation().Id); |
||
451 | connSymbol2d.Move(0, 0, moveX, moveY); |
||
452 | ReleaseCOMObjects(connSymbol); |
||
453 | } |
||
454 | ReleaseCOMObjects(branch); |
||
455 | } |
||
456 | |||
457 | c3e8fa8e | gaqhf | } |
458 | } |
||
459 | } |
||
460 | } |
||
461 | 77d6e710 | gaqhf | private LMSymbol GetFirstSymbolBySlope(LMADataSource dataSource, LMSymbol branch, string symbol1RepID, string symbol2RepID) |
462 | { |
||
463 | LMSymbol result = null; |
||
464 | foreach (LMConnector connector in branch.Connect1Connectors) |
||
465 | { |
||
466 | if (connector.ConnectItem1SymbolObject != null && |
||
467 | connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
||
468 | connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
||
469 | { |
||
470 | string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
||
471 | if (repID != symbol1RepID && repID != symbol2RepID) |
||
472 | result = connector.ConnectItem1SymbolObject; |
||
473 | } |
||
474 | |||
475 | if (connector.ConnectItem2SymbolObject != null && |
||
476 | connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
||
477 | connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
||
478 | { |
||
479 | string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
||
480 | if (repID != symbol1RepID && repID != symbol2RepID) |
||
481 | result = connector.ConnectItem2SymbolObject; |
||
482 | } |
||
483 | } |
||
484 | |||
485 | foreach (LMConnector connector in branch.Connect2Connectors) |
||
486 | { |
||
487 | if (connector.ConnectItem1SymbolObject != null && |
||
488 | connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
||
489 | connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
||
490 | { |
||
491 | string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
||
492 | if (repID != symbol1RepID && repID != symbol2RepID) |
||
493 | result = connector.ConnectItem1SymbolObject; |
||
494 | } |
||
495 | |||
496 | if (connector.ConnectItem2SymbolObject != null && |
||
497 | connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
||
498 | connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
||
499 | { |
||
500 | string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
||
501 | if (repID != symbol1RepID && repID != symbol2RepID) |
||
502 | result = connector.ConnectItem2SymbolObject; |
||
503 | } |
||
504 | } |
||
505 | |||
506 | |||
507 | return result; |
||
508 | } |
||
509 | c3e8fa8e | gaqhf | private string GetRepresentationId(Symbol2d symbol) |
510 | { |
||
511 | foreach (var attributes in symbol.AttributeSets) |
||
512 | { |
||
513 | foreach (var attribute in attributes) |
||
514 | { |
||
515 | string name = attribute.Name; |
||
516 | object value = attribute.GetValue(); |
||
517 | if (name == "DrawingID") |
||
518 | { |
||
519 | return value.ToString(); |
||
520 | } |
||
521 | } |
||
522 | } |
||
523 | return null; |
||
524 | } |
||
525 | 77d6e710 | gaqhf | private string GetRepresentationId(Point2d point2d) |
526 | { |
||
527 | foreach (var attributes in point2d.AttributeSets) |
||
528 | { |
||
529 | foreach (var attribute in attributes) |
||
530 | { |
||
531 | string name = attribute.Name; |
||
532 | object value = attribute.GetValue(); |
||
533 | if (name == "DrawingID") |
||
534 | { |
||
535 | return value.ToString(); |
||
536 | } |
||
537 | } |
||
538 | } |
||
539 | return null; |
||
540 | } |
||
541 | c3e8fa8e | gaqhf | private List<List<string>> SetSymbol(LMADataSource dataSource, string rep, double x, double y, int count) |
542 | { |
||
543 | LMSymbol _LMSymbol = dataSource.GetSymbol(rep); |
||
544 | List<List<string>> result = new List<List<string>>(); |
||
545 | List<string> oldIDs = new List<string>() { rep }; |
||
546 | foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
||
547 | { |
||
548 | if (connector.get_ItemStatus() != "Active") |
||
549 | continue; |
||
550 | |||
551 | string repID = connector.AsLMRepresentation().Id; |
||
552 | string status = connector.get_ItemStatus(); |
||
553 | if (status == "Active" && !oldIDs.Contains(repID)) |
||
554 | { |
||
555 | List<string> symbols = new List<string>(); |
||
556 | oldIDs.Add(repID); |
||
557 | loop(dataSource, oldIDs, symbols, connector, x, y, count); |
||
558 | result.Add(symbols); |
||
559 | } |
||
560 | } |
||
561 | |||
562 | foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
||
563 | { |
||
564 | if (connector.get_ItemStatus() != "Active") |
||
565 | continue; |
||
566 | |||
567 | string repID = connector.AsLMRepresentation().Id; |
||
568 | string status = connector.get_ItemStatus(); |
||
569 | if (status == "Active" && !oldIDs.Contains(repID)) |
||
570 | { |
||
571 | List<string> symbols = new List<string>(); |
||
572 | oldIDs.Add(repID); |
||
573 | loop(dataSource, oldIDs, symbols, connector, x, y, count); |
||
574 | result.Add(symbols); |
||
575 | } |
||
576 | } |
||
577 | |||
578 | ReleaseCOMObjects(_LMSymbol); |
||
579 | return result; |
||
580 | } |
||
581 | private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMConnector connector, double x, double y, int count) |
||
582 | { |
||
583 | if (symbols.Count >= count) |
||
584 | return; |
||
585 | |||
586 | if (connector.ConnectItem1SymbolObject != null && !oldIDs.Contains(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id)) |
||
587 | { |
||
588 | string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
||
589 | oldIDs.Add(repID); |
||
590 | if (connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
||
591 | { |
||
592 | double sX = connector.ConnectItem1SymbolObject.get_XCoordinate(), sY = connector.ConnectItem1SymbolObject.get_YCoordinate(); ; |
||
593 | SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1); |
||
594 | if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL) |
||
595 | symbols.Add(repID); |
||
596 | } |
||
597 | |||
598 | loop(dataSource, oldIDs, symbols, connector.ConnectItem1SymbolObject, x, y, count); |
||
599 | } |
||
600 | |||
601 | if (symbols.Count >= count) |
||
602 | return; |
||
603 | |||
604 | if (connector.ConnectItem2SymbolObject != null && !oldIDs.Contains(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id)) |
||
605 | { |
||
606 | string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
||
607 | oldIDs.Add(repID); |
||
608 | if (connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
||
609 | { |
||
610 | double sX = connector.ConnectItem2SymbolObject.get_XCoordinate(), sY = connector.ConnectItem2SymbolObject.get_YCoordinate(); ; |
||
611 | SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1); |
||
612 | if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL) |
||
613 | symbols.Add(repID); |
||
614 | } |
||
615 | |||
616 | loop(dataSource, oldIDs, symbols, connector.ConnectItem2SymbolObject, x, y, count); |
||
617 | } |
||
618 | } |
||
619 | private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMSymbol _LMSymbol, double x, double y, int count) |
||
620 | { |
||
621 | if (symbols.Count >= count) |
||
622 | return; |
||
623 | |||
624 | foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
||
625 | { |
||
626 | if (connector.get_ItemStatus() != "Active") |
||
627 | continue; |
||
628 | |||
629 | string repID = connector.AsLMRepresentation().Id; |
||
630 | string status = connector.get_ItemStatus(); |
||
631 | if (status == "Active" && !oldIDs.Contains(repID)) |
||
632 | { |
||
633 | oldIDs.Add(repID); |
||
634 | loop(dataSource, oldIDs, symbols, connector, x, y, count); |
||
635 | } |
||
636 | } |
||
637 | 82c7f66d | gaqhf | |
638 | c3e8fa8e | gaqhf | foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
639 | { |
||
640 | if (connector.get_ItemStatus() != "Active") |
||
641 | continue; |
||
642 | |||
643 | string repID = connector.AsLMRepresentation().Id; |
||
644 | string status = connector.get_ItemStatus(); |
||
645 | if (status == "Active" && !oldIDs.Contains(repID)) |
||
646 | { |
||
647 | oldIDs.Add(repID); |
||
648 | loop(dataSource, oldIDs, symbols, connector, x, y, count); |
||
649 | } |
||
650 | } |
||
651 | } |
||
652 | private Symbol2d GetSymbol2DByRepID(LMADataSource dataSource, string repID) |
||
653 | { |
||
654 | LMSymbol _LMSymbol = dataSource.GetSymbol(repID); |
||
655 | Symbol2d symbol2D = application.ActiveDocument.ActiveSheet.DrawingObjects[_LMSymbol.get_GraphicOID().ToString()]; |
||
656 | ReleaseCOMObjects(_LMSymbol); |
||
657 | return symbol2D; |
||
658 | 82c7f66d | gaqhf | } |
659 | c3e8fa8e | gaqhf | private void MovePoint2d(LMADataSource datasource, string repID, SymmetryArrow arrow, double moveX, double moveY) |
660 | { |
||
661 | LMSymbol _LMSymbol = datasource.GetSymbol(repID); |
||
662 | foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
||
663 | { |
||
664 | if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength())) |
||
665 | { |
||
666 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
||
667 | { |
||
668 | Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
||
669 | point.X += moveX; |
||
670 | point.Y += moveY; |
||
671 | } |
||
672 | else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
||
673 | { |
||
674 | Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
||
675 | point.X += moveX; |
||
676 | point.Y += moveY; |
||
677 | } |
||
678 | } |
||
679 | } |
||
680 | foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
||
681 | { |
||
682 | if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength())) |
||
683 | { |
||
684 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
||
685 | { |
||
686 | Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
||
687 | point.X += moveX; |
||
688 | point.Y += moveY; |
||
689 | } |
||
690 | else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
||
691 | { |
||
692 | Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
||
693 | point.X += moveX; |
||
694 | point.Y += moveY; |
||
695 | } |
||
696 | } |
||
697 | } |
||
698 | ReleaseCOMObjects(_LMSymbol); |
||
699 | } |
||
700 | private List<Point2d> FindAllPoint2d(LMADataSource dataSource, string repID, string nextRepID) |
||
701 | { |
||
702 | LMSymbol _LMSymbol = dataSource.GetSymbol(repID); |
||
703 | List<string> endIDs = new List<string>() { repID }; |
||
704 | List<string> graphicOIDs = new List<string>(); |
||
705 | List<Point2d> result = new List<Point2d>(); |
||
706 | FindPointsLoop(dataSource, _LMSymbol, endIDs, nextRepID, graphicOIDs); |
||
707 | ReleaseCOMObjects(_LMSymbol); |
||
708 | foreach (var item in graphicOIDs) |
||
709 | { |
||
710 | Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[item] as Point2d; |
||
711 | result.Add(point); |
||
712 | } |
||
713 | |||
714 | return result; |
||
715 | } |
||
716 | private bool FindPointsLoop(LMADataSource dataSource, LMSymbol _LMSymbol, List<string> endIDs, string targetRepID, List<string> graphicOIDs) |
||
717 | { |
||
718 | foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
||
719 | { |
||
720 | if (connector.get_ItemStatus() != "Active") |
||
721 | continue; |
||
722 | |||
723 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
||
724 | { |
||
725 | string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
||
726 | if (!endIDs.Contains(repID)) |
||
727 | { |
||
728 | endIDs.Add(repID); |
||
729 | if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
||
730 | { |
||
731 | if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs)) |
||
732 | { |
||
733 | if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
||
734 | graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()); |
||
735 | return true; |
||
736 | } |
||
737 | } |
||
738 | else if (targetRepID == repID) |
||
739 | { |
||
740 | return true; |
||
741 | } |
||
742 | } |
||
743 | } |
||
744 | if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
||
745 | { |
||
746 | string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
||
747 | if (!endIDs.Contains(repID)) |
||
748 | { |
||
749 | endIDs.Add(repID); |
||
750 | if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
||
751 | { |
||
752 | if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs)) |
||
753 | { |
||
754 | if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
||
755 | graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()); |
||
756 | return true; |
||
757 | } |
||
758 | } |
||
759 | else if (targetRepID == repID) |
||
760 | { |
||
761 | return true; |
||
762 | } |
||
763 | } |
||
764 | } |
||
765 | } |
||
766 | foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
||
767 | { |
||
768 | if (connector.get_ItemStatus() != "Active") |
||
769 | continue; |
||
770 | |||
771 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
||
772 | { |
||
773 | string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
||
774 | if (!endIDs.Contains(repID)) |
||
775 | { |
||
776 | endIDs.Add(repID); |
||
777 | if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
||
778 | { |
||
779 | if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs)) |
||
780 | { |
||
781 | if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
||
782 | graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()); |
||
783 | return true; |
||
784 | } |
||
785 | } |
||
786 | else if (targetRepID == repID) |
||
787 | { |
||
788 | return true; |
||
789 | } |
||
790 | } |
||
791 | } |
||
792 | if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
||
793 | { |
||
794 | string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
||
795 | if (!endIDs.Contains(repID)) |
||
796 | { |
||
797 | endIDs.Add(repID); |
||
798 | if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
||
799 | { |
||
800 | if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs)) |
||
801 | { |
||
802 | if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
||
803 | graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()); |
||
804 | return true; |
||
805 | } |
||
806 | } |
||
807 | else if (targetRepID == repID) |
||
808 | { |
||
809 | return true; |
||
810 | } |
||
811 | } |
||
812 | } |
||
813 | } |
||
814 | |||
815 | return false; |
||
816 | } |
||
817 | 29ac1959 | gaqhf | #endregion |
818 | 5a47c65c | gaqhf | |
819 | 29ac1959 | gaqhf | #region SpecBreak |
820 | private void btnSpecBreakRelocation_Click(object sender, EventArgs e) |
||
821 | { |
||
822 | dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
||
823 | WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
||
824 | application = wApp.RADApplication; |
||
825 | |||
826 | int count = application.ActiveSelectSet.Count; |
||
827 | int dependencyCount = 0; |
||
828 | foreach (var item in application.ActiveSelectSet) |
||
829 | if (item.GetType() == typeof(DependencyObject)) |
||
830 | dependencyCount++; |
||
831 | 979a91b9 | gaqhf | |
832 | if (count > 0 && application.ActiveSelectSet[0].GetType() == typeof(DependencyObject)) |
||
833 | { |
||
834 | MessageBox.Show("First selected item is DependencyObject!\r\nPlease move symbol", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
835 | return; |
||
836 | } |
||
837 | |||
838 | 29ac1959 | gaqhf | if ((count == 3 || count == 4) && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d) && |
839 | (dependencyCount == 2 || dependencyCount == 3)) |
||
840 | { |
||
841 | Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
||
842 | |||
843 | if (!symbol.DefinitionName.Contains(@"Design\Annotation\Graphics\")) |
||
844 | { |
||
845 | MessageBox.Show("Select SpecBreak!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
846 | return; |
||
847 | } |
||
848 | c3e8fa8e | gaqhf | |
849 | 29ac1959 | gaqhf | DependencyObject dependency1 = application.ActiveSelectSet[1] as DependencyObject; |
850 | DependencyObject dependency2 = application.ActiveSelectSet[2] as DependencyObject; |
||
851 | DependencyObject dependency3 = null; |
||
852 | if (count == 4) |
||
853 | dependency3 = application.ActiveSelectSet[3] as DependencyObject; |
||
854 | |||
855 | application.ActiveSelectSet.RemoveAll(); |
||
856 | double angle = symbol.Angle; |
||
857 | if (symbol.GetTransform().HasReflection) |
||
858 | angle += Math.PI; |
||
859 | |||
860 | double degree = double.NaN; |
||
861 | if (angle > -0.1 && angle < 0.1) |
||
862 | degree = 0; |
||
863 | else if (angle > 1.56 && angle < 1.58) |
||
864 | degree = 90; |
||
865 | else if (angle > 3.13 && angle < 3.15) |
||
866 | degree = 180; |
||
867 | else if (angle > 4.7 && angle < 4.72) |
||
868 | degree = 270; |
||
869 | else if (angle > 6.27 && angle < 6.29) |
||
870 | degree = 0; |
||
871 | else if (angle > -1.58 && angle < -1.56) |
||
872 | degree = 270; |
||
873 | 30a774f6 | gaqhf | else if (angle > -3.15 && angle < -3.13) |
874 | degree = 180; |
||
875 | 29ac1959 | gaqhf | else |
876 | 30a774f6 | gaqhf | throw new Exception("Check Angle"); |
877 | c3e8fa8e | gaqhf | |
878 | |||
879 | 29ac1959 | gaqhf | double originX, originY; |
880 | symbol.GetOrigin(out originX, out originY); |
||
881 | |||
882 | double crossX = 0; |
||
883 | double crossY = 0; |
||
884 | double topX = 0; |
||
885 | double topY = 0; |
||
886 | foreach (var item in symbol.DrawingObjects) |
||
887 | { |
||
888 | Line2d line2d = item as Line2d; |
||
889 | if (line2d != null) |
||
890 | { |
||
891 | double x1, y1, x2, y2; |
||
892 | line2d.GetStartPoint(out x1, out y1); |
||
893 | line2d.GetEndPoint(out x2, out y2); |
||
894 | SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 0.1); |
||
895 | |||
896 | if (slopeType == SlopeType.HORIZONTAL) |
||
897 | { |
||
898 | if (crossY == 0) |
||
899 | crossY = y1; |
||
900 | else |
||
901 | crossY = (crossY + y1) / 2; |
||
902 | |||
903 | switch (degree) |
||
904 | { |
||
905 | case 90: |
||
906 | if (topX == 0) |
||
907 | topX = Math.Min(x1, x2); |
||
908 | else |
||
909 | topX = Math.Min(topX, Math.Min(x1, x2)); |
||
910 | break; |
||
911 | case 270: |
||
912 | if (topX == 0) |
||
913 | topX = Math.Max(x1, x2); |
||
914 | else |
||
915 | topX = Math.Max(topX, Math.Max(x1, x2)); |
||
916 | break; |
||
917 | default: |
||
918 | break; |
||
919 | } |
||
920 | } |
||
921 | else if (slopeType == SlopeType.VERTICAL) |
||
922 | { |
||
923 | if (crossX == 0) |
||
924 | crossX = x1; |
||
925 | else |
||
926 | crossX = (crossX + x1) / 2; |
||
927 | |||
928 | switch (degree) |
||
929 | { |
||
930 | case 0: |
||
931 | if (topY == 0) |
||
932 | topY = Math.Max(y1, y2); |
||
933 | else |
||
934 | topY = Math.Max(topY, Math.Max(y1, y2)); |
||
935 | break; |
||
936 | case 180: |
||
937 | if (topY == 0) |
||
938 | topY = Math.Min(y1, y2); |
||
939 | else |
||
940 | topY = Math.Min(topY, Math.Min(y1, y2)); |
||
941 | break; |
||
942 | default: |
||
943 | break; |
||
944 | } |
||
945 | } |
||
946 | } |
||
947 | } |
||
948 | switch (degree) |
||
949 | { |
||
950 | case 0: |
||
951 | crossX = originX; |
||
952 | topX = crossX; |
||
953 | break; |
||
954 | case 90: |
||
955 | crossY = originY; |
||
956 | topY = crossY; |
||
957 | break; |
||
958 | case 180: |
||
959 | crossX = originX; |
||
960 | topX = crossX; |
||
961 | break; |
||
962 | case 270: |
||
963 | crossY = originY; |
||
964 | topY = crossY; |
||
965 | break; |
||
966 | default: |
||
967 | break; |
||
968 | } |
||
969 | |||
970 | e7ea221d | gaqhf | SpecBreakRelocation(degree, originX, originY, crossX, crossY, topX, topY, dependency1, dependency2, dependency3); |
971 | 29ac1959 | gaqhf | } |
972 | else |
||
973 | { |
||
974 | MessageBox.Show("Check Rule!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
975 | } |
||
976 | } |
||
977 | e7ea221d | gaqhf | private void SpecBreakRelocation(double degree, double originX, double originY, double crossX, double crossY, double topX, double topY, DependencyObject dependency1, DependencyObject dependency2, DependencyObject dependency3) |
978 | 29ac1959 | gaqhf | { |
979 | 519902b7 | gaqhf | double d1X1, d1Y1, d1X2, d1Y2, d2X1, d2Y1, d2X2, d2Y2, d3X1 = 0, d3Y1 = 0, d3X2 = 0, d3Y2 = 0; |
980 | 30a774f6 | gaqhf | |
981 | 54311b41 | gaqhf | FindRangeWithOutLineString2d(dependency1, out d1X1, out d1Y1, out d1X2, out d1Y2); |
982 | FindRangeWithOutLineString2d(dependency2, out d2X1, out d2Y1, out d2X2, out d2Y2); |
||
983 | 519902b7 | gaqhf | if (dependency3 != null) |
984 | cf520d0d | gaqhf | FindRangeWithOutLineString2dAndTextBox(dependency3, out d3X1, out d3Y1, out d3X2, out d3Y2); |
985 | 29ac1959 | gaqhf | |
986 | 25c5df17 | gaqhf | GridSetting gridSetting = GridSetting.GetInstance(); |
987 | double move = gridSetting.Length / 2; |
||
988 | 29ac1959 | gaqhf | switch (degree) |
989 | { |
||
990 | case 0: |
||
991 | 25c5df17 | gaqhf | MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY); |
992 | MoveDependency(dependency2, d2X1, d2Y2, crossX + move, crossY); |
||
993 | 519902b7 | gaqhf | if (dependency3 != null) |
994 | MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y1, topX, topY); |
||
995 | 29ac1959 | gaqhf | break; |
996 | case 90: |
||
997 | 25c5df17 | gaqhf | MoveDependency(dependency1, d1X1, d1Y2, crossX + move, crossY); |
998 | MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY); |
||
999 | 519902b7 | gaqhf | if (dependency3 != null) |
1000 | e7ea221d | gaqhf | MoveDependency(dependency3, d3X1, (d3Y1 + d3Y2) / 2, originX, originY); |
1001 | 29ac1959 | gaqhf | break; |
1002 | case 180: |
||
1003 | 25c5df17 | gaqhf | MoveDependency(dependency1, d1X2, d1Y1, crossX - move, crossY); |
1004 | MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY); |
||
1005 | 519902b7 | gaqhf | if (dependency3 != null) |
1006 | MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y2, topX, topY); |
||
1007 | 29ac1959 | gaqhf | break; |
1008 | case 270: |
||
1009 | 25c5df17 | gaqhf | MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY); |
1010 | MoveDependency(dependency2, d2X2, d2Y1, crossX - move, crossY); |
||
1011 | 519902b7 | gaqhf | if (dependency3 != null) |
1012 | e7ea221d | gaqhf | MoveDependency(dependency3, d3X2, (d3Y1 + d3Y2) / 2, originX, originY); |
1013 | 29ac1959 | gaqhf | break; |
1014 | default: |
||
1015 | break; |
||
1016 | } |
||
1017 | } |
||
1018 | 6a659fd9 | gaqhf | private void MoveDependency(DependencyObject dependency, double xFrom, double yFrom, double xTo, double yTo) |
1019 | { |
||
1020 | 54311b41 | gaqhf | application.ActiveSelectSet.Add(dependency); |
1021 | |||
1022 | Transform transform = dependency.GetTransform(); |
||
1023 | transform.DefineByMove2d(xTo - xFrom, yTo - yFrom); |
||
1024 | application.ActiveSelectSet.Transform(transform, false); |
||
1025 | |||
1026 | application.ActiveSelectSet.RemoveAll(); |
||
1027 | 6a659fd9 | gaqhf | } |
1028 | 29ac1959 | gaqhf | private string GetDrawingItemType(DependencyObject dependency) |
1029 | { |
||
1030 | string result = string.Empty; |
||
1031 | |||
1032 | foreach (var attributes in dependency.AttributeSets) |
||
1033 | { |
||
1034 | foreach (var attribute in attributes) |
||
1035 | { |
||
1036 | if (attribute.Name == "DrawingItemType") |
||
1037 | return attribute.GetValue().ToString(); |
||
1038 | } |
||
1039 | } |
||
1040 | |||
1041 | return result; |
||
1042 | } |
||
1043 | 54311b41 | gaqhf | private void FindRangeWithOutLineString2d(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2) |
1044 | 29ac1959 | gaqhf | { |
1045 | 54311b41 | gaqhf | x1 = double.MaxValue; |
1046 | y1 = double.MaxValue; |
||
1047 | x2 = double.MinValue; |
||
1048 | y2 = double.MinValue; |
||
1049 | foreach (DrawingObjectBase item in dependency.DrawingObjects) |
||
1050 | 29ac1959 | gaqhf | { |
1051 | 54311b41 | gaqhf | if (item.GetType() != typeof(LineString2d)) |
1052 | 29ac1959 | gaqhf | { |
1053 | 54311b41 | gaqhf | double minX, minY, maxX, maxY; |
1054 | item.Range(out minX, out minY, out maxX, out maxY); |
||
1055 | if (x1 > minX) |
||
1056 | x1 = minX; |
||
1057 | if (y1 > minY) |
||
1058 | y1 = minY; |
||
1059 | cf520d0d | gaqhf | if (x2 < maxX) |
1060 | x2 = maxX; |
||
1061 | if (y2 < maxY) |
||
1062 | y2 = maxY; |
||
1063 | } |
||
1064 | } |
||
1065 | |||
1066 | } |
||
1067 | private void FindRangeWithOutLineString2dAndTextBox(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2) |
||
1068 | { |
||
1069 | x1 = double.MaxValue; |
||
1070 | y1 = double.MaxValue; |
||
1071 | x2 = double.MinValue; |
||
1072 | y2 = double.MinValue; |
||
1073 | foreach (DrawingObjectBase item in dependency.DrawingObjects) |
||
1074 | { |
||
1075 | if (item.GetType() != typeof(LineString2d) && item.GetType() != typeof(Ingr.RAD2D.TextBox)) |
||
1076 | { |
||
1077 | double minX, minY, maxX, maxY; |
||
1078 | item.Range(out minX, out minY, out maxX, out maxY); |
||
1079 | if (x1 > minX) |
||
1080 | x1 = minX; |
||
1081 | if (y1 > minY) |
||
1082 | y1 = minY; |
||
1083 | 54311b41 | gaqhf | if (x2 < maxX) |
1084 | x2 = maxX; |
||
1085 | if (y2 < maxY) |
||
1086 | y2 = maxY; |
||
1087 | 29ac1959 | gaqhf | } |
1088 | } |
||
1089 | |||
1090 | } |
||
1091 | #endregion |
||
1092 | 5a47c65c | gaqhf | |
1093 | 1b09fe17 | gaqhf | #region Hot Key |
1094 | 5a47c65c | gaqhf | private void toggleSwitchSnapGrid_Toggled(object sender, EventArgs e) |
1095 | { |
||
1096 | if (toggleSwitchSnapGrid.IsOn) |
||
1097 | { |
||
1098 | RegisterHotKey(this.Handle, 0, (int)KeyModifier.Shift, Keys.A.GetHashCode()); |
||
1099 | } |
||
1100 | else |
||
1101 | { |
||
1102 | UnregisterHotKey(this.Handle, 0); |
||
1103 | } |
||
1104 | } |
||
1105 | private void toggleSwitchMoveSymbol_Toggled(object sender, EventArgs e) |
||
1106 | { |
||
1107 | if (toggleSwitchMoveSymbol.IsOn) |
||
1108 | { |
||
1109 | RegisterHotKey(this.Handle, 1, (int)KeyModifier.Shift, Keys.Left.GetHashCode()); |
||
1110 | RegisterHotKey(this.Handle, 2, (int)KeyModifier.Shift, Keys.Up.GetHashCode()); |
||
1111 | RegisterHotKey(this.Handle, 3, (int)KeyModifier.Shift, Keys.Right.GetHashCode()); |
||
1112 | RegisterHotKey(this.Handle, 4, (int)KeyModifier.Shift, Keys.Down.GetHashCode()); |
||
1113 | } |
||
1114 | else |
||
1115 | { |
||
1116 | UnregisterHotKey(this.Handle, 1); |
||
1117 | UnregisterHotKey(this.Handle, 2); |
||
1118 | UnregisterHotKey(this.Handle, 3); |
||
1119 | UnregisterHotKey(this.Handle, 4); |
||
1120 | } |
||
1121 | } |
||
1122 | public void ClearHotKey() |
||
1123 | { |
||
1124 | if (toggleSwitchMoveSymbol.IsOn) |
||
1125 | { |
||
1126 | UnregisterHotKey(this.Handle, 1); |
||
1127 | UnregisterHotKey(this.Handle, 2); |
||
1128 | UnregisterHotKey(this.Handle, 3); |
||
1129 | UnregisterHotKey(this.Handle, 4); |
||
1130 | } |
||
1131 | if (toggleSwitchSnapGrid.IsOn) |
||
1132 | { |
||
1133 | UnregisterHotKey(this.Handle, 0); |
||
1134 | } |
||
1135 | } |
||
1136 | 70b0b5d7 | gaqhf | [System.Runtime.InteropServices.DllImport("user32.dll")] |
1137 | private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); |
||
1138 | [System.Runtime.InteropServices.DllImport("user32.dll")] |
||
1139 | private static extern bool UnregisterHotKey(IntPtr hWnd, int id); |
||
1140 | enum KeyModifier |
||
1141 | { |
||
1142 | None = 0, |
||
1143 | Alt = 1, |
||
1144 | Control = 2, |
||
1145 | Shift = 4, |
||
1146 | WinKey = 8 |
||
1147 | } |
||
1148 | protected override void WndProc(ref Message m) |
||
1149 | { |
||
1150 | base.WndProc(ref m); |
||
1151 | if (m.Msg == 0x0312) |
||
1152 | { |
||
1153 | Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); |
||
1154 | KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF); |
||
1155 | int id = m.WParam.ToInt32(); |
||
1156 | 5a47c65c | gaqhf | switch (id) |
1157 | { |
||
1158 | case 0: |
||
1159 | application.RunCommand(CommandConstants.igcmdGridSnap); |
||
1160 | break; |
||
1161 | case 1: |
||
1162 | MoveSymbol(Arrow.Left); |
||
1163 | break; |
||
1164 | case 2: |
||
1165 | MoveSymbol(Arrow.Up); |
||
1166 | break; |
||
1167 | case 3: |
||
1168 | MoveSymbol(Arrow.Right); |
||
1169 | break; |
||
1170 | case 4: |
||
1171 | MoveSymbol(Arrow.Down); |
||
1172 | break; |
||
1173 | default: |
||
1174 | break; |
||
1175 | } |
||
1176 | |||
1177 | 70b0b5d7 | gaqhf | } |
1178 | |||
1179 | } |
||
1180 | 1b09fe17 | gaqhf | #endregion |
1181 | 5a47c65c | gaqhf | |
1182 | #region Move Symbol |
||
1183 | enum Arrow |
||
1184 | { |
||
1185 | Left, |
||
1186 | Up, |
||
1187 | Right, |
||
1188 | Down |
||
1189 | } |
||
1190 | private void MoveSymbol(Arrow arrow) |
||
1191 | { |
||
1192 | if (application.ActiveSelectSet.Count > 0) |
||
1193 | { |
||
1194 | Placement placement = new Placement(); |
||
1195 | LMADataSource dataSource = placement.PIDDataSource; |
||
1196 | System.Collections.ObjectModel.Collection<DrawingObjectBase> drawingObjectBases = new System.Collections.ObjectModel.Collection<DrawingObjectBase>(); |
||
1197 | Transform transform = null; |
||
1198 | foreach (DrawingObjectBase drawingObject in application.ActiveSelectSet) |
||
1199 | { |
||
1200 | 901feb22 | gaqhf | if (drawingObject.GetType() == typeof(Symbol2d)) |
1201 | 5a47c65c | gaqhf | { |
1202 | 901feb22 | gaqhf | Symbol2d symbol2D = drawingObject as Symbol2d; |
1203 | 5a47c65c | gaqhf | if (transform == null) |
1204 | transform = symbol2D.GetTransform(); |
||
1205 | drawingObjectBases.Add(symbol2D); |
||
1206 | LMSymbol _LMSymbol = dataSource.GetSymbol(GetRepresentationId(symbol2D)); |
||
1207 | if (_LMSymbol != null) |
||
1208 | { |
||
1209 | foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
||
1210 | { |
||
1211 | if (connector.get_ItemStatus() == "Active") |
||
1212 | { |
||
1213 | #region Zero Length And Branch |
||
1214 | if (Convert.ToBoolean(connector.get_IsZeroLength())) |
||
1215 | { |
||
1216 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolID != _LMSymbol.Id) |
||
1217 | { |
||
1218 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1219 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1220 | drawingObjectBases.Add(point2D); |
||
1221 | } |
||
1222 | else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolID != _LMSymbol.Id) |
||
1223 | { |
||
1224 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1225 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1226 | drawingObjectBases.Add(point2D); |
||
1227 | } |
||
1228 | } |
||
1229 | #endregion |
||
1230 | #region Not Zero Length And Branch And Vertical,Horizontal |
||
1231 | else |
||
1232 | { |
||
1233 | if (connector.ConnectItem1SymbolObject != null && |
||
1234 | connector.ConnectItem1SymbolID != _LMSymbol.Id && |
||
1235 | connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
||
1236 | connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch" && |
||
1237 | IsMovePoint2D(connector.ConnectItem1SymbolObject, connector, arrow)) |
||
1238 | { |
||
1239 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1240 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1241 | drawingObjectBases.Add(point2D); |
||
1242 | } |
||
1243 | |||
1244 | else if (connector.ConnectItem2SymbolObject != null && |
||
1245 | connector.ConnectItem2SymbolID != _LMSymbol.Id && |
||
1246 | connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
||
1247 | connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch" && |
||
1248 | IsMovePoint2D(connector.ConnectItem2SymbolObject, connector, arrow)) |
||
1249 | { |
||
1250 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1251 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1252 | drawingObjectBases.Add(point2D); |
||
1253 | } |
||
1254 | |||
1255 | } |
||
1256 | #endregion |
||
1257 | } |
||
1258 | } |
||
1259 | foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
||
1260 | { |
||
1261 | if (connector.get_ItemStatus() == "Active") |
||
1262 | { |
||
1263 | #region Zero Length And Branch |
||
1264 | if (Convert.ToBoolean(connector.get_IsZeroLength())) |
||
1265 | { |
||
1266 | if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolID != _LMSymbol.Id) |
||
1267 | { |
||
1268 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1269 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1270 | drawingObjectBases.Add(point2D); |
||
1271 | } |
||
1272 | else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolID != _LMSymbol.Id) |
||
1273 | { |
||
1274 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1275 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1276 | drawingObjectBases.Add(point2D); |
||
1277 | } |
||
1278 | } |
||
1279 | #endregion |
||
1280 | #region Not Zero Length And Branch And Vertical,Horizontal |
||
1281 | else |
||
1282 | { |
||
1283 | if (connector.ConnectItem1SymbolObject != null && |
||
1284 | connector.ConnectItem1SymbolID != _LMSymbol.Id && |
||
1285 | connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
||
1286 | connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch" && |
||
1287 | IsMovePoint2D(connector.ConnectItem1SymbolObject, connector, arrow)) |
||
1288 | { |
||
1289 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1290 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1291 | drawingObjectBases.Add(point2D); |
||
1292 | } |
||
1293 | |||
1294 | else if (connector.ConnectItem2SymbolObject != null && |
||
1295 | connector.ConnectItem2SymbolID != _LMSymbol.Id && |
||
1296 | connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
||
1297 | connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch" && |
||
1298 | IsMovePoint2D(connector.ConnectItem2SymbolObject, connector, arrow)) |
||
1299 | { |
||
1300 | Point2d point2D = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()] as Point2d; |
||
1301 | if (point2D != null && !drawingObjectBases.Contains(point2D)) |
||
1302 | drawingObjectBases.Add(point2D); |
||
1303 | } |
||
1304 | |||
1305 | } |
||
1306 | #endregion |
||
1307 | } |
||
1308 | } |
||
1309 | } |
||
1310 | ReleaseCOMObjects(_LMSymbol); |
||
1311 | } |
||
1312 | 901feb22 | gaqhf | else if (drawingObject.GetType() == typeof(Point2d)) |
1313 | { |
||
1314 | Point2d point2D = drawingObject as Point2d; |
||
1315 | if (!drawingObjectBases.Contains(point2D)) |
||
1316 | drawingObjectBases.Add(point2D); |
||
1317 | } |
||
1318 | 5a47c65c | gaqhf | } |
1319 | |||
1320 | application.ActiveSelectSet.RemoveAll(); |
||
1321 | 64922e03 | gaqhf | if (drawingObjectBases.Count > 0 && transform != null) |
1322 | 5a47c65c | gaqhf | { |
1323 | application.ActiveSelectSet.AddObjects(drawingObjectBases); |
||
1324 | SetTransform(transform, arrow); |
||
1325 | application.ActiveSelectSet.Transform(transform, false); |
||
1326 | |||
1327 | application.ActiveSelectSet.RemoveAll(); |
||
1328 | application.ActiveSelectSet.AddObjects(drawingObjectBases); |
||
1329 | } |
||
1330 | |||
1331 | //foreach (DrawingObjectBaseEx item in drawingObjectBases) |
||
1332 | // MoveSymbol(item, arrow); |
||
1333 | |||
1334 | ReleaseCOMObjects(dataSource); |
||
1335 | ReleaseCOMObjects(placement); |
||
1336 | } |
||
1337 | } |
||
1338 | private bool IsMovePoint2D(LMSymbol branchSymbol, LMConnector targetConnector, Arrow arrow) |
||
1339 | { |
||
1340 | bool result = false; |
||
1341 | |||
1342 | DependencyObject dependency = application.ActiveDocument.ActiveSheet.DrawingObjects[targetConnector.get_GraphicOID().ToString()] as DependencyObject; |
||
1343 | SlopeType mainSlope = GetLineSlopeType(dependency); |
||
1344 | |||
1345 | if (mainSlope == SlopeType.HORIZONTAL || mainSlope == SlopeType.VERTICAL) |
||
1346 | { |
||
1347 | List<SlopeType> types = new List<SlopeType>(); |
||
1348 | |||
1349 | foreach (LMConnector connector in branchSymbol.Connect1Connectors) |
||
1350 | { |
||
1351 | if (connector.get_ItemStatus() == "Active" && |
||
1352 | connector.Id != targetConnector.Id && |
||
1353 | !Convert.ToBoolean(connector.get_IsZeroLength())) |
||
1354 | types.Add(GetLineSlopeType(application.ActiveDocument.ActiveSheet.DrawingObjects[connector.get_GraphicOID().ToString()] as DependencyObject)); |
||
1355 | } |
||
1356 | |||
1357 | foreach (LMConnector connector in branchSymbol.Connect2Connectors) |
||
1358 | { |
||
1359 | if (connector.get_ItemStatus() == "Active" && |
||
1360 | connector.Id != targetConnector.Id && |
||
1361 | !Convert.ToBoolean(connector.get_IsZeroLength())) |
||
1362 | types.Add(GetLineSlopeType(application.ActiveDocument.ActiveSheet.DrawingObjects[connector.get_GraphicOID().ToString()] as DependencyObject)); |
||
1363 | } |
||
1364 | |||
1365 | foreach (var type in types) |
||
1366 | { |
||
1367 | if (type == mainSlope) |
||
1368 | { |
||
1369 | if (type == SlopeType.HORIZONTAL && (arrow == Arrow.Up || arrow == Arrow.Down)) |
||
1370 | result = true; |
||
1371 | else if (type == SlopeType.VERTICAL && (arrow == Arrow.Left || arrow == Arrow.Right)) |
||
1372 | result = true; |
||
1373 | else |
||
1374 | { |
||
1375 | result = false; |
||
1376 | break; |
||
1377 | } |
||
1378 | } |
||
1379 | else |
||
1380 | result = true; |
||
1381 | } |
||
1382 | |||
1383 | if (result) |
||
1384 | { |
||
1385 | if ((arrow == Arrow.Down || arrow == Arrow.Up) && mainSlope == SlopeType.VERTICAL) |
||
1386 | result = false; |
||
1387 | else if ((arrow == Arrow.Left || arrow == Arrow.Right) && mainSlope == SlopeType.HORIZONTAL) |
||
1388 | result = false; |
||
1389 | } |
||
1390 | } |
||
1391 | |||
1392 | return result; |
||
1393 | } |
||
1394 | private SlopeType GetLineSlopeType(DependencyObject dependency) |
||
1395 | { |
||
1396 | if (dependency != null && dependency.DrawingObjects.Count == 1 && dependency.DrawingObjects[0].GetType() == typeof(LineString2d)) |
||
1397 | { |
||
1398 | LineString2d line = dependency.DrawingObjects[0] as LineString2d; |
||
1399 | double x1 = 0, y1 = 0, x2 = double.MaxValue, y2 = double.MaxValue; |
||
1400 | for (int i = 0; i < line.KeyPointCount; i++) |
||
1401 | { |
||
1402 | double x, y, z; |
||
1403 | KeyPointType keyPointType; |
||
1404 | HandleType handleType; |
||
1405 | line.GetKeyPoint(i, out x, out y, out z, out keyPointType, out handleType); |
||
1406 | if (keyPointType == KeyPointType.igKeyPointStart) |
||
1407 | { |
||
1408 | x1 = x; |
||
1409 | y1 = y; |
||
1410 | } |
||
1411 | else if (keyPointType == KeyPointType.igKeyPointEnd) |
||
1412 | { |
||
1413 | x2 = x; |
||
1414 | y2 = y; |
||
1415 | } |
||
1416 | } |
||
1417 | return SPPIDUtil.CalcSlope(x1, y1, x2, y2, 0.5); |
||
1418 | } |
||
1419 | |||
1420 | return SlopeType.None; |
||
1421 | } |
||
1422 | private void MoveSymbol(DrawingObjectBaseEx drawingObjectBase, Arrow arrow) |
||
1423 | { |
||
1424 | if (drawingObjectBase == null) |
||
1425 | return; |
||
1426 | |||
1427 | GridSetting gridSetting = GridSetting.GetInstance(); |
||
1428 | switch (arrow) |
||
1429 | { |
||
1430 | case Arrow.Left: |
||
1431 | drawingObjectBase.Move(0, 0, -gridSetting.Length, 0); |
||
1432 | break; |
||
1433 | case Arrow.Up: |
||
1434 | drawingObjectBase.Move(0, 0, 0, gridSetting.Length); |
||
1435 | break; |
||
1436 | case Arrow.Right: |
||
1437 | drawingObjectBase.Move(0, 0, gridSetting.Length, 0); |
||
1438 | break; |
||
1439 | case Arrow.Down: |
||
1440 | drawingObjectBase.Move(0, 0, 0, -gridSetting.Length); |
||
1441 | break; |
||
1442 | default: |
||
1443 | break; |
||
1444 | } |
||
1445 | } |
||
1446 | private void SetTransform(Transform transform, Arrow arrow) |
||
1447 | { |
||
1448 | 404a7c7b | gaqhf | if (transform == null) |
1449 | return; |
||
1450 | |||
1451 | 5a47c65c | gaqhf | GridSetting gridSetting = GridSetting.GetInstance(); |
1452 | switch (arrow) |
||
1453 | { |
||
1454 | case Arrow.Left: |
||
1455 | transform.DefineByMove2d(-gridSetting.Length, 0); |
||
1456 | break; |
||
1457 | case Arrow.Up: |
||
1458 | transform.DefineByMove2d(0, gridSetting.Length); |
||
1459 | break; |
||
1460 | case Arrow.Right: |
||
1461 | transform.DefineByMove2d(gridSetting.Length, 0); |
||
1462 | break; |
||
1463 | case Arrow.Down: |
||
1464 | transform.DefineByMove2d(0, -gridSetting.Length); |
||
1465 | break; |
||
1466 | default: |
||
1467 | break; |
||
1468 | } |
||
1469 | } |
||
1470 | #endregion |
||
1471 | |||
1472 | 82c7f66d | gaqhf | #endregion |
1473 | 70b0b5d7 | gaqhf | |
1474 | 1b09fe17 | gaqhf | #region TEST |
1475 | f14b4e3b | gaqhf | |
1476 | 6a7573b0 | gaqhf | private void simpleButton1_Click(object sender, EventArgs e) |
1477 | { |
||
1478 | 54311b41 | gaqhf | //Placement placement = new Placement(); |
1479 | //LMADataSource dataSource = placement.PIDDataSource; |
||
1480 | //string a = "0A509911F33441A2AF088BFBA78B770D"; |
||
1481 | //LMLabelPersist label = dataSource.GetLabelPersist(a); |
||
1482 | //label.set_XCoordinate(0.4); |
||
1483 | |||
1484 | 519902b7 | gaqhf | Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
1485 | double minX = double.MaxValue; |
||
1486 | int index = 0; |
||
1487 | bool start = false; |
||
1488 | Line2d tar = null; |
||
1489 | double rx1 = 0, ry1 = 0, rx2 = 0, ry2 = 0; |
||
1490 | if (symbol != null) |
||
1491 | d9fc7084 | gaqhf | { |
1492 | 519902b7 | gaqhf | for (int i = 0; i < symbol.DrawingObjects.Count; i++) |
1493 | { |
||
1494 | DrawingObjectBase drawingObj = symbol.DrawingObjects[i]; |
||
1495 | |||
1496 | if (drawingObj.GetType() == typeof(Line2d)) |
||
1497 | { |
||
1498 | Line2d line = drawingObj as Line2d; |
||
1499 | double x1, y1, x2, y2; |
||
1500 | line.GetStartPoint(out x1, out y1); |
||
1501 | line.GetEndPoint(out x2, out y2); |
||
1502 | if (x1 < minX) |
||
1503 | { |
||
1504 | minX = x1; |
||
1505 | index = i; |
||
1506 | start = true; |
||
1507 | tar = line; |
||
1508 | |||
1509 | rx1 = x1; |
||
1510 | rx2 = x2; |
||
1511 | ry1 = y1; |
||
1512 | ry2 = y2; |
||
1513 | } |
||
1514 | |||
1515 | if (x2 < minX) |
||
1516 | { |
||
1517 | minX = x2; |
||
1518 | index = i; |
||
1519 | start = false; |
||
1520 | tar = line; |
||
1521 | |||
1522 | rx1 = x1; |
||
1523 | rx2 = x2; |
||
1524 | ry1 = y1; |
||
1525 | ry2 = y2; |
||
1526 | } |
||
1527 | } |
||
1528 | } |
||
1529 | } |
||
1530 | |||
1531 | if (start) |
||
1532 | { |
||
1533 | symbol.Symbol2dParameters[0].Value = 0.02; |
||
1534 | //Ingr.RAD2D.Group group = symbol.Convert(); |
||
1535 | //group. |
||
1536 | } |
||
1537 | else |
||
1538 | { |
||
1539 | |||
1540 | d9fc7084 | gaqhf | } |
1541 | ca6e0f51 | gaqhf | } |
1542 | 4941f5fe | gaqhf | |
1543 | ca6e0f51 | gaqhf | private void AutoJoinPipeRun() |
1544 | { |
||
1545 | d4c3e39f | gaqhf | dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
1546 | WrapperApplication wApp = new WrapperApplication(application.Application); |
||
1547 | Ingr.RAD2D.Application radApp = wApp.RADApplication; |
||
1548 | |||
1549 | ca6e0f51 | gaqhf | string modelItemId = null; |
1550 | List<double[]> vertices = new List<double[]>(); |
||
1551 | a31a512e | gaqhf | if (radApp.ActiveSelectSet.Count == 0) |
1552 | { |
||
1553 | return; |
||
1554 | } |
||
1555 | ca6e0f51 | gaqhf | dynamic OID = radApp.ActiveSelectSet[0].Key(); |
1556 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
1557 | foreach (var attributes in drawingObject.AttributeSets) |
||
1558 | 4ba01591 | gaqhf | { |
1559 | ca6e0f51 | gaqhf | foreach (var attribute in attributes) |
1560 | 4ba01591 | gaqhf | { |
1561 | ca6e0f51 | gaqhf | if (attribute.Name == "ModelID") |
1562 | modelItemId = attribute.GetValue().ToString(); |
||
1563 | } |
||
1564 | } |
||
1565 | radApp.ActiveSelectSet.RemoveAll(); |
||
1566 | 32205389 | gaqhf | |
1567 | 7e4a64a3 | gaqhf | } |
1568 | #endregion |
||
1569 | |||
1570 | 7aee331b | gaqhf | |
1571 | 9628f54b | gaqhf | [DllImport("user32.dll")] |
1572 | public static extern int FindWindow(string lpClassName, string lpWindowName); |
||
1573 | 3734dcc5 | gaqhf | |
1574 | [DllImport("user32.dll", SetLastError = true)] |
||
1575 | static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
||
1576 | |||
1577 | b427ebf9 | humkyung | private void ConverterDocking_Load(object sender, EventArgs e) |
1578 | { |
||
1579 | #if DEBUG |
||
1580 | this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
||
1581 | #else |
||
1582 | this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
||
1583 | #endif |
||
1584 | |||
1585 | } |
||
1586 | 65881d60 | gaqhf | } |
1587 | } |