hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 901feb22
이력 | 보기 | 이력해설 | 다운로드 (72.4 KB)
1 |
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 |
using System.IO; |
12 |
using Microsoft.VisualBasic; |
13 |
using Ingr.RAD2D; |
14 |
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 |
using Plaice; |
21 |
using Llama; |
22 |
using DevExpress.XtraSplashScreen; |
23 |
using Newtonsoft.Json; |
24 |
using System.Runtime.InteropServices; |
25 |
using System.Reflection; |
26 |
using Converter.SPPID.OPC; |
27 |
|
28 |
namespace Converter.SPPID.Wrapper |
29 |
{ |
30 |
public partial class ConverterDocking : UserControl |
31 |
{ |
32 |
Ingr.RAD2D.Application application; |
33 |
static bool addEvent = false; |
34 |
public ConverterDocking() |
35 |
{ |
36 |
InitializeComponent(); |
37 |
spinEditSymmetry.Properties.Mask.EditMask = "f0"; |
38 |
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
39 |
WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
40 |
application = wApp.RADApplication; |
41 |
|
42 |
ReleaseCOMObjects(dApplication); |
43 |
dApplication = null; |
44 |
try |
45 |
{ |
46 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
47 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
48 |
|
49 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
50 |
_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 |
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 |
|
76 |
if (!addEvent) |
77 |
{ |
78 |
application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit; |
79 |
addEvent = true; |
80 |
} |
81 |
} |
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 |
} |
90 |
private void ApplicationEvents_ApplicationExit(out bool cancel) |
91 |
{ |
92 |
cancel = false; |
93 |
} |
94 |
/// <summary> |
95 |
/// 선택한 도면들을 읽어서 SPPID로 변환한다. |
96 |
/// </summary> |
97 |
/// <param name="sender"></param> |
98 |
/// <param name="e"></param> |
99 |
private void btnConverter_Click(object sender, EventArgs e) |
100 |
{ |
101 |
ConverterForm converterForm = new ConverterForm(); |
102 |
if (converterForm.ShowDialog() == DialogResult.OK) |
103 |
{ |
104 |
//Ingr.RAD2D.Document doc = application.Documents.Add(); |
105 |
|
106 |
try |
107 |
{ |
108 |
CloseOPCForm.Run(); |
109 |
|
110 |
for (int i = 0; i < converterForm.Documents.Count; i++) |
111 |
{ |
112 |
SPPID_Document document = converterForm.Documents[i]; |
113 |
if (document.SetSPPIDMapping() && document.Enable) |
114 |
{ |
115 |
using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked)) |
116 |
{ |
117 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
118 |
modeling.Run(); |
119 |
} |
120 |
} |
121 |
} |
122 |
} |
123 |
catch (Exception ex) |
124 |
{ |
125 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
126 |
} |
127 |
finally |
128 |
{ |
129 |
CloseOPCForm.Stop(); |
130 |
|
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 |
} |
139 |
|
140 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
141 |
} |
142 |
} |
143 |
|
144 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
145 |
{ |
146 |
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 |
|
159 |
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 |
DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1)); |
173 |
DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1)); |
174 |
|
175 |
if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1) |
176 |
{ |
177 |
DataRow fromOPCInfoRow = fromOPCInfoRows[0]; |
178 |
DataRow toOPCInfoRow = toOPCInfoRows[0]; |
179 |
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 |
List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString()); |
183 |
AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes); |
184 |
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 |
|
203 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
204 |
} |
205 |
|
206 |
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 |
private void btnGetDrawingSize_Click(object sender, EventArgs e) |
217 |
{ |
218 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
219 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
220 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
221 |
|
222 |
if (radApp.ActiveSelectSet.Count > 0) |
223 |
{ |
224 |
DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
225 |
if (line2D != null) |
226 |
{ |
227 |
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 |
} |
240 |
else |
241 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
242 |
} |
243 |
else |
244 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
245 |
} |
246 |
|
247 |
#region SPPID Utils |
248 |
|
249 |
#region Symmetry |
250 |
private void btnSymmetry_Click(object sender, EventArgs e) |
251 |
{ |
252 |
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 |
string symbol1RepID; |
416 |
string symbol2RepID; |
417 |
List<Point2d> point2ds; |
418 |
if (i == 0) |
419 |
{ |
420 |
symbol1RepID = centerRepID; |
421 |
symbol2RepID = item.Value[i]; |
422 |
} |
423 |
else |
424 |
{ |
425 |
symbol1RepID = item.Value[i - 1]; |
426 |
symbol2RepID = item.Value[i]; |
427 |
} |
428 |
point2ds = FindAllPoint2d(dataSource, symbol1RepID, symbol2RepID); |
429 |
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 |
{ |
445 |
LMSymbol branch = dataSource.GetSymbol(GetRepresentationId(point)); |
446 |
LMSymbol connSymbol = GetFirstSymbolBySlope(dataSource, branch, symbol1RepID, symbol2RepID); |
447 |
point.Move(0, 0, moveX, moveY); |
448 |
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 |
} |
458 |
} |
459 |
} |
460 |
} |
461 |
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 |
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 |
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 |
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 |
|
638 |
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 |
} |
659 |
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 |
#endregion |
818 |
|
819 |
#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 |
|
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 |
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 |
|
849 |
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 |
else if (angle > -3.15 && angle < -3.13) |
874 |
degree = 180; |
875 |
else |
876 |
throw new Exception("Check Angle"); |
877 |
|
878 |
|
879 |
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 |
SpecBreakRelocation(degree, originX, originY, crossX, crossY, topX, topY, dependency1, dependency2, dependency3); |
971 |
} |
972 |
else |
973 |
{ |
974 |
MessageBox.Show("Check Rule!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
975 |
} |
976 |
} |
977 |
private void SpecBreakRelocation(double degree, double originX, double originY, double crossX, double crossY, double topX, double topY, DependencyObject dependency1, DependencyObject dependency2, DependencyObject dependency3) |
978 |
{ |
979 |
double d1X1, d1Y1, d1X2, d1Y2, d2X1, d2Y1, d2X2, d2Y2, d3X1 = 0, d3Y1 = 0, d3X2 = 0, d3Y2 = 0; |
980 |
|
981 |
FindRangeWithOutLineString2d(dependency1, out d1X1, out d1Y1, out d1X2, out d1Y2); |
982 |
FindRangeWithOutLineString2d(dependency2, out d2X1, out d2Y1, out d2X2, out d2Y2); |
983 |
if (dependency3 != null) |
984 |
FindRangeWithOutLineString2dAndTextBox(dependency3, out d3X1, out d3Y1, out d3X2, out d3Y2); |
985 |
|
986 |
GridSetting gridSetting = GridSetting.GetInstance(); |
987 |
double move = gridSetting.Length / 2; |
988 |
switch (degree) |
989 |
{ |
990 |
case 0: |
991 |
MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY); |
992 |
MoveDependency(dependency2, d2X1, d2Y2, crossX + move, crossY); |
993 |
if (dependency3 != null) |
994 |
MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y1, topX, topY); |
995 |
break; |
996 |
case 90: |
997 |
MoveDependency(dependency1, d1X1, d1Y2, crossX + move, crossY); |
998 |
MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY); |
999 |
if (dependency3 != null) |
1000 |
MoveDependency(dependency3, d3X1, (d3Y1 + d3Y2) / 2, originX, originY); |
1001 |
break; |
1002 |
case 180: |
1003 |
MoveDependency(dependency1, d1X2, d1Y1, crossX - move, crossY); |
1004 |
MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY); |
1005 |
if (dependency3 != null) |
1006 |
MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y2, topX, topY); |
1007 |
break; |
1008 |
case 270: |
1009 |
MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY); |
1010 |
MoveDependency(dependency2, d2X2, d2Y1, crossX - move, crossY); |
1011 |
if (dependency3 != null) |
1012 |
MoveDependency(dependency3, d3X2, (d3Y1 + d3Y2) / 2, originX, originY); |
1013 |
break; |
1014 |
default: |
1015 |
break; |
1016 |
} |
1017 |
} |
1018 |
private void MoveDependency(DependencyObject dependency, double xFrom, double yFrom, double xTo, double yTo) |
1019 |
{ |
1020 |
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 |
} |
1028 |
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 |
private void FindRangeWithOutLineString2d(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2) |
1044 |
{ |
1045 |
x1 = double.MaxValue; |
1046 |
y1 = double.MaxValue; |
1047 |
x2 = double.MinValue; |
1048 |
y2 = double.MinValue; |
1049 |
foreach (DrawingObjectBase item in dependency.DrawingObjects) |
1050 |
{ |
1051 |
if (item.GetType() != typeof(LineString2d)) |
1052 |
{ |
1053 |
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 |
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 |
if (x2 < maxX) |
1084 |
x2 = maxX; |
1085 |
if (y2 < maxY) |
1086 |
y2 = maxY; |
1087 |
} |
1088 |
} |
1089 |
|
1090 |
} |
1091 |
#endregion |
1092 |
|
1093 |
#region Hot Key |
1094 |
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 |
[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 |
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 |
} |
1178 |
|
1179 |
} |
1180 |
#endregion |
1181 |
|
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 |
if (drawingObject.GetType() == typeof(Symbol2d)) |
1201 |
{ |
1202 |
Symbol2d symbol2D = drawingObject as Symbol2d; |
1203 |
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 |
else if (drawingObject.GetType() == typeof(Point2d)) |
1313 |
{ |
1314 |
Point2d point2D = drawingObject as Point2d; |
1315 |
if (!drawingObjectBases.Contains(point2D)) |
1316 |
drawingObjectBases.Add(point2D); |
1317 |
} |
1318 |
} |
1319 |
|
1320 |
application.ActiveSelectSet.RemoveAll(); |
1321 |
if (drawingObjectBases.Count > 0) |
1322 |
{ |
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 |
GridSetting gridSetting = GridSetting.GetInstance(); |
1449 |
switch (arrow) |
1450 |
{ |
1451 |
case Arrow.Left: |
1452 |
transform.DefineByMove2d(-gridSetting.Length, 0); |
1453 |
break; |
1454 |
case Arrow.Up: |
1455 |
transform.DefineByMove2d(0, gridSetting.Length); |
1456 |
break; |
1457 |
case Arrow.Right: |
1458 |
transform.DefineByMove2d(gridSetting.Length, 0); |
1459 |
break; |
1460 |
case Arrow.Down: |
1461 |
transform.DefineByMove2d(0, -gridSetting.Length); |
1462 |
break; |
1463 |
default: |
1464 |
break; |
1465 |
} |
1466 |
} |
1467 |
#endregion |
1468 |
|
1469 |
#endregion |
1470 |
|
1471 |
#region TEST |
1472 |
|
1473 |
private void simpleButton1_Click(object sender, EventArgs e) |
1474 |
{ |
1475 |
//Placement placement = new Placement(); |
1476 |
//LMADataSource dataSource = placement.PIDDataSource; |
1477 |
//string a = "0A509911F33441A2AF088BFBA78B770D"; |
1478 |
//LMLabelPersist label = dataSource.GetLabelPersist(a); |
1479 |
//label.set_XCoordinate(0.4); |
1480 |
|
1481 |
Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
1482 |
double minX = double.MaxValue; |
1483 |
int index = 0; |
1484 |
bool start = false; |
1485 |
Line2d tar = null; |
1486 |
double rx1 = 0, ry1 = 0, rx2 = 0, ry2 = 0; |
1487 |
if (symbol != null) |
1488 |
{ |
1489 |
for (int i = 0; i < symbol.DrawingObjects.Count; i++) |
1490 |
{ |
1491 |
DrawingObjectBase drawingObj = symbol.DrawingObjects[i]; |
1492 |
|
1493 |
if (drawingObj.GetType() == typeof(Line2d)) |
1494 |
{ |
1495 |
Line2d line = drawingObj as Line2d; |
1496 |
double x1, y1, x2, y2; |
1497 |
line.GetStartPoint(out x1, out y1); |
1498 |
line.GetEndPoint(out x2, out y2); |
1499 |
if (x1 < minX) |
1500 |
{ |
1501 |
minX = x1; |
1502 |
index = i; |
1503 |
start = true; |
1504 |
tar = line; |
1505 |
|
1506 |
rx1 = x1; |
1507 |
rx2 = x2; |
1508 |
ry1 = y1; |
1509 |
ry2 = y2; |
1510 |
} |
1511 |
|
1512 |
if (x2 < minX) |
1513 |
{ |
1514 |
minX = x2; |
1515 |
index = i; |
1516 |
start = false; |
1517 |
tar = line; |
1518 |
|
1519 |
rx1 = x1; |
1520 |
rx2 = x2; |
1521 |
ry1 = y1; |
1522 |
ry2 = y2; |
1523 |
} |
1524 |
} |
1525 |
} |
1526 |
} |
1527 |
|
1528 |
if (start) |
1529 |
{ |
1530 |
symbol.Symbol2dParameters[0].Value = 0.02; |
1531 |
//Ingr.RAD2D.Group group = symbol.Convert(); |
1532 |
//group. |
1533 |
} |
1534 |
else |
1535 |
{ |
1536 |
|
1537 |
} |
1538 |
} |
1539 |
|
1540 |
private void AutoJoinPipeRun() |
1541 |
{ |
1542 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
1543 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
1544 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
1545 |
|
1546 |
string modelItemId = null; |
1547 |
List<double[]> vertices = new List<double[]>(); |
1548 |
if (radApp.ActiveSelectSet.Count == 0) |
1549 |
{ |
1550 |
return; |
1551 |
} |
1552 |
dynamic OID = radApp.ActiveSelectSet[0].Key(); |
1553 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1554 |
foreach (var attributes in drawingObject.AttributeSets) |
1555 |
{ |
1556 |
foreach (var attribute in attributes) |
1557 |
{ |
1558 |
if (attribute.Name == "ModelID") |
1559 |
modelItemId = attribute.GetValue().ToString(); |
1560 |
} |
1561 |
} |
1562 |
radApp.ActiveSelectSet.RemoveAll(); |
1563 |
|
1564 |
} |
1565 |
#endregion |
1566 |
|
1567 |
|
1568 |
[DllImport("user32.dll")] |
1569 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
1570 |
|
1571 |
[DllImport("user32.dll", SetLastError = true)] |
1572 |
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
1573 |
|
1574 |
private void ConverterDocking_Load(object sender, EventArgs e) |
1575 |
{ |
1576 |
#if DEBUG |
1577 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
1578 |
#else |
1579 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
1580 |
#endif |
1581 |
|
1582 |
} |
1583 |
|
1584 |
|
1585 |
} |
1586 |
} |