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