hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 29ac1959
이력 | 보기 | 이력해설 | 다운로드 (52.7 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 |
|
57 |
if (!addEvent) |
58 |
{ |
59 |
application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit; |
60 |
addEvent = true; |
61 |
} |
62 |
RegisterHotKey(this.Handle, 0, (int)KeyModifier.Shift, Keys.A.GetHashCode()); |
63 |
} |
64 |
catch (Exception ex) |
65 |
{ |
66 |
StringBuilder sb = new StringBuilder(); |
67 |
sb.AppendLine(ex.Message); |
68 |
sb.AppendLine(ex.StackTrace); |
69 |
MessageBox.Show(sb.ToString()); |
70 |
} |
71 |
} |
72 |
private void ApplicationEvents_ApplicationExit(out bool cancel) |
73 |
{ |
74 |
cancel = false; |
75 |
} |
76 |
/// <summary> |
77 |
/// 선택한 도면들을 읽어서 SPPID로 변환한다. |
78 |
/// </summary> |
79 |
/// <param name="sender"></param> |
80 |
/// <param name="e"></param> |
81 |
private void btnConverter_Click(object sender, EventArgs e) |
82 |
{ |
83 |
ConverterForm converterForm = new ConverterForm(); |
84 |
if (converterForm.ShowDialog() == DialogResult.OK) |
85 |
{ |
86 |
//Ingr.RAD2D.Document doc = application.Documents.Add(); |
87 |
|
88 |
try |
89 |
{ |
90 |
CloseOPCForm.Run(); |
91 |
|
92 |
for (int i = 0; i < converterForm.Documents.Count; i++) |
93 |
{ |
94 |
SPPID_Document document = converterForm.Documents[i]; |
95 |
if (document.SetSPPIDMapping() && document.Enable) |
96 |
{ |
97 |
using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked)) |
98 |
{ |
99 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
100 |
modeling.Run(); |
101 |
} |
102 |
} |
103 |
} |
104 |
} |
105 |
catch (Exception ex) |
106 |
{ |
107 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
108 |
} |
109 |
finally |
110 |
{ |
111 |
CloseOPCForm.Stop(); |
112 |
|
113 |
//doc.SaveOnClose = false; |
114 |
//doc.Close(false); |
115 |
|
116 |
//dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
117 |
//dApplication.Drawings[1].CloseDrawing(false); |
118 |
//ReleaseCOMObjects(dApplication); |
119 |
//dApplication = null; |
120 |
} |
121 |
|
122 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
123 |
} |
124 |
} |
125 |
|
126 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
127 |
{ |
128 |
DataTable tOPCInfo = Project_DB.SelectOPCInfo(); |
129 |
DataTable tOPCRelations = Project_DB.SelectOPCRelations(); |
130 |
DataTable tDrawingInfo = Project_DB.SelectDrawingInfo(); |
131 |
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
132 |
|
133 |
foreach (DataRow row in tOPCInfo.Rows) |
134 |
{ |
135 |
if (!Convert.ToBoolean(row["PAIRED"])) |
136 |
{ |
137 |
string drawingUID = row["ID2_DRAWING_UID"].ToString(); |
138 |
string OPCUID = row["ID2_OPC_UID"].ToString(); |
139 |
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)); |
140 |
|
141 |
if (rows.Length == 2) |
142 |
{ |
143 |
string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString(); |
144 |
string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString(); |
145 |
string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString(); |
146 |
string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString(); |
147 |
string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString(); |
148 |
string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString(); |
149 |
string toOPCUID1 = rows[0]["To_OPC_UID"].ToString(); |
150 |
string toOPCUID2 = rows[1]["To_OPC_UID"].ToString(); |
151 |
|
152 |
DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1)); |
153 |
DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1)); |
154 |
DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1)); |
155 |
DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1)); |
156 |
|
157 |
if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1) |
158 |
{ |
159 |
DataRow fromOPCInfoRow = fromOPCInfoRows[0]; |
160 |
DataRow toOPCInfoRow = toOPCInfoRows[0]; |
161 |
string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
162 |
string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
163 |
string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString(); |
164 |
List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString()); |
165 |
AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes); |
166 |
if (opc.Run()) |
167 |
{ |
168 |
fromOPCInfoRow["PAIRED"] = true; |
169 |
toOPCInfoRow["PAIRED"] = true; |
170 |
|
171 |
Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
172 |
Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
173 |
} |
174 |
} |
175 |
} |
176 |
} |
177 |
} |
178 |
|
179 |
tOPCInfo.Dispose(); |
180 |
tOPCRelations.Dispose(); |
181 |
tDrawingInfo.Dispose(); |
182 |
ReleaseCOMObjects(dApplication); |
183 |
dApplication = null; |
184 |
|
185 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
186 |
} |
187 |
|
188 |
public void ReleaseCOMObjects(params object[] objVars) |
189 |
{ |
190 |
int intNewRefCount = 0; |
191 |
foreach (object obj in objVars) |
192 |
{ |
193 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
194 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
195 |
} |
196 |
} |
197 |
|
198 |
private void btnGetDrawingSize_Click(object sender, EventArgs e) |
199 |
{ |
200 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
201 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
202 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
203 |
|
204 |
if (radApp.ActiveSelectSet.Count > 0) |
205 |
{ |
206 |
DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
207 |
if (line2D != null) |
208 |
{ |
209 |
double minX = 0; |
210 |
double minY = 0; |
211 |
double maxX = 0; |
212 |
double maxY = 0; |
213 |
line2D.Range(out minX, out minY, out maxX, out maxY); |
214 |
|
215 |
Settings.Default.DrawingX = maxX - minX; |
216 |
Settings.Default.DrawingY = maxY - minY; |
217 |
Settings.Default.Save(); |
218 |
|
219 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
220 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
221 |
} |
222 |
else |
223 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
224 |
} |
225 |
else |
226 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
227 |
} |
228 |
|
229 |
#region SPPID Utils |
230 |
#region Symmetry |
231 |
private void btnSymmetry_Click(object sender, EventArgs e) |
232 |
{ |
233 |
if (application.ActiveSelectSet.Count == 1 && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d)) |
234 |
{ |
235 |
int symCount = (int)spinEditSymmetry.Value; |
236 |
Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
237 |
double x, y; |
238 |
symbol.GetOrigin(out x, out y); |
239 |
string rep = GetRepresentationId(symbol); |
240 |
List<string> verticalRepID = new List<string>(); |
241 |
List<string> horizontalRepID = new List<string>(); |
242 |
|
243 |
if ((symbol.LinearName.Contains("Piping") || |
244 |
symbol.LinearName.Contains("Instrument")) && |
245 |
!string.IsNullOrEmpty(rep)) |
246 |
{ |
247 |
Placement placement = new Placement(); |
248 |
LMADataSource dataSource = placement.PIDDataSource; |
249 |
List<List<string>> datas = SetSymbol(dataSource, rep, x, y, symCount); |
250 |
Dictionary<SymmetryArrow, List<string>> resultDatas = new Dictionary<SymmetryArrow, List<string>>(); |
251 |
if (datas.Count >= 2 && datas.Find(loop => loop.Count != symCount) == null) |
252 |
{ |
253 |
SymmetryArrow arrow = SymmetryArrow.None; |
254 |
foreach (var data in datas) |
255 |
{ |
256 |
LMSymbol firstSymbol = dataSource.GetSymbol(data[0]); |
257 |
double fX = firstSymbol.get_XCoordinate(); |
258 |
double fY = firstSymbol.get_YCoordinate(); |
259 |
|
260 |
SlopeType type = SPPIDUtil.CalcSlope(x, y, fX, fY, 1); |
261 |
if (type == SlopeType.HORIZONTAL) |
262 |
{ |
263 |
if (fX < x) |
264 |
{ |
265 |
arrow |= SymmetryArrow.Left; |
266 |
resultDatas.Add(SymmetryArrow.Left, data); |
267 |
} |
268 |
else |
269 |
{ |
270 |
arrow |= SymmetryArrow.Right; |
271 |
resultDatas.Add(SymmetryArrow.Right, data); |
272 |
} |
273 |
|
274 |
} |
275 |
else if (type == SlopeType.VERTICAL) |
276 |
{ |
277 |
if (fY < y) |
278 |
{ |
279 |
arrow |= SymmetryArrow.Down; |
280 |
resultDatas.Add(SymmetryArrow.Down, data); |
281 |
} |
282 |
else |
283 |
{ |
284 |
arrow |= SymmetryArrow.Up; |
285 |
resultDatas.Add(SymmetryArrow.Up, data); |
286 |
} |
287 |
} |
288 |
|
289 |
ReleaseCOMObjects(firstSymbol); |
290 |
} |
291 |
|
292 |
SymmetryForm form = new SymmetryForm(arrow); |
293 |
if (form.ShowDialog() == DialogResult.OK) |
294 |
{ |
295 |
MoveByResult(dataSource, resultDatas, x, y, form.Result, rep); |
296 |
} |
297 |
} |
298 |
else |
299 |
MessageBox.Show("Check Symmetry Rules", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
300 |
ReleaseCOMObjects(dataSource); |
301 |
ReleaseCOMObjects(placement); |
302 |
} |
303 |
} |
304 |
|
305 |
return; |
306 |
|
307 |
List<Symbol2d> symbols = new List<Symbol2d>(); |
308 |
foreach (var item in application.ActiveSelectSet) |
309 |
{ |
310 |
Type type = item.GetType(); |
311 |
if (type == typeof(Symbol2d)) |
312 |
{ |
313 |
Symbol2d symbol = item as Symbol2d; |
314 |
if (symbol.LinearName.Contains("Piping") || |
315 |
symbol.LinearName.Contains("Instrument")) |
316 |
symbols.Add(symbol); |
317 |
} |
318 |
//if (item.GetType() == typeof(Symbol2d) || item.GetType() == typeof(Point2d)) |
319 |
// items.Add(item); |
320 |
} |
321 |
|
322 |
List<Symbol2d> verticalSymbols = new List<Symbol2d>(); |
323 |
List<Symbol2d> horizontalSymbols = new List<Symbol2d>(); |
324 |
Symbol2d mainSymbol = null; |
325 |
for (int i = 0; i < symbols.Count - 1; i++) |
326 |
{ |
327 |
Symbol2d symbol1 = symbols[i]; |
328 |
for (int j = 1; j < symbols.Count; j++) |
329 |
{ |
330 |
Symbol2d symbol2 = symbols[j]; |
331 |
|
332 |
if (symbol1 != symbol2) |
333 |
{ |
334 |
double x1, y1, x2, y2; |
335 |
symbol1.GetOrigin(out x1, out y1); |
336 |
symbol2.GetOrigin(out x2, out y2); |
337 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 1); |
338 |
if (slopeType == SlopeType.HORIZONTAL) |
339 |
{ |
340 |
if (!horizontalSymbols.Contains(symbol1)) |
341 |
horizontalSymbols.Add(symbol1); |
342 |
if (!horizontalSymbols.Contains(symbol2)) |
343 |
horizontalSymbols.Add(symbol2); |
344 |
|
345 |
if (verticalSymbols.Contains(symbol1)) |
346 |
mainSymbol = symbol1; |
347 |
if (verticalSymbols.Contains(symbol2)) |
348 |
mainSymbol = symbol2; |
349 |
} |
350 |
else if (slopeType == SlopeType.VERTICAL) |
351 |
{ |
352 |
if (!verticalSymbols.Contains(symbol1)) |
353 |
verticalSymbols.Add(symbol1); |
354 |
if (!verticalSymbols.Contains(symbol2)) |
355 |
verticalSymbols.Add(symbol2); |
356 |
|
357 |
if (horizontalSymbols.Contains(symbol1)) |
358 |
mainSymbol = symbol1; |
359 |
if (horizontalSymbols.Contains(symbol2)) |
360 |
mainSymbol = symbol2; |
361 |
} |
362 |
} |
363 |
} |
364 |
} |
365 |
|
366 |
application.ActiveSelectSet.RemoveAll(); |
367 |
foreach (var item in verticalSymbols) |
368 |
application.ActiveSelectSet.Add(item); |
369 |
foreach (var item in horizontalSymbols) |
370 |
application.ActiveSelectSet.Add(item); |
371 |
|
372 |
|
373 |
if (MessageBox.Show("Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) |
374 |
{ |
375 |
application.ActiveSelectSet.RemoveAll(); |
376 |
|
377 |
} |
378 |
} |
379 |
private void MoveByResult(LMADataSource dataSource,Dictionary<SymmetryArrow, List<string>> resultDatas, double x, double y, SymmetryArrow arrow, string centerRepID) |
380 |
{ |
381 |
List<string> datas = resultDatas[arrow]; |
382 |
foreach (var item in resultDatas) |
383 |
{ |
384 |
if (item.Key != arrow) |
385 |
{ |
386 |
for (int i = 0; i < item.Value.Count; i++) |
387 |
{ |
388 |
Symbol2d moveSymbol2d = GetSymbol2DByRepID(dataSource, item.Value[i]); |
389 |
Symbol2d symbol2d = GetSymbol2DByRepID(dataSource, datas[i]); |
390 |
|
391 |
double x1, y1, x2, y2; |
392 |
symbol2d.GetOrigin(out x1, out y1); |
393 |
moveSymbol2d.GetOrigin(out x2, out y2); |
394 |
double distance = SPPIDUtil.CalcPointToPointdDistance(x, y, x1, y1); |
395 |
|
396 |
string symbol1RepID; |
397 |
string symbol2RepID; |
398 |
List<Point2d> point2ds; |
399 |
if (i == 0) |
400 |
{ |
401 |
symbol1RepID = centerRepID; |
402 |
symbol2RepID = item.Value[i]; |
403 |
} |
404 |
else |
405 |
{ |
406 |
symbol1RepID = item.Value[i - 1]; |
407 |
symbol2RepID = item.Value[i]; |
408 |
} |
409 |
point2ds = FindAllPoint2d(dataSource, symbol1RepID, symbol2RepID); |
410 |
double moveX = 0; |
411 |
double moveY = 0; |
412 |
|
413 |
if (item.Key == SymmetryArrow.Left) |
414 |
moveX = x - distance - x2; |
415 |
else if (item.Key == SymmetryArrow.Right) |
416 |
moveX = x + distance - x2; |
417 |
else if (item.Key == SymmetryArrow.Down) |
418 |
moveY = y - distance - y2; |
419 |
else if (item.Key == SymmetryArrow.Up) |
420 |
moveY = y + distance - y2; |
421 |
|
422 |
moveSymbol2d.Move(0, 0, moveX, moveY); |
423 |
MovePoint2d(dataSource, item.Value[i], arrow, moveX, moveY); |
424 |
foreach (var point in point2ds) |
425 |
{ |
426 |
LMSymbol branch = dataSource.GetSymbol(GetRepresentationId(point)); |
427 |
LMSymbol connSymbol = GetFirstSymbolBySlope(dataSource, branch, symbol1RepID, symbol2RepID); |
428 |
point.Move(0, 0, moveX, moveY); |
429 |
if (connSymbol != null) |
430 |
{ |
431 |
Symbol2d connSymbol2d = GetSymbol2DByRepID(dataSource, connSymbol.AsLMRepresentation().Id); |
432 |
connSymbol2d.Move(0, 0, moveX, moveY); |
433 |
ReleaseCOMObjects(connSymbol); |
434 |
} |
435 |
ReleaseCOMObjects(branch); |
436 |
} |
437 |
|
438 |
} |
439 |
} |
440 |
} |
441 |
} |
442 |
private LMSymbol GetFirstSymbolBySlope(LMADataSource dataSource, LMSymbol branch, string symbol1RepID, string symbol2RepID) |
443 |
{ |
444 |
LMSymbol result = null; |
445 |
foreach (LMConnector connector in branch.Connect1Connectors) |
446 |
{ |
447 |
if (connector.ConnectItem1SymbolObject != null && |
448 |
connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
449 |
connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
450 |
{ |
451 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
452 |
if (repID != symbol1RepID && repID != symbol2RepID) |
453 |
result = connector.ConnectItem1SymbolObject; |
454 |
} |
455 |
|
456 |
if (connector.ConnectItem2SymbolObject != null && |
457 |
connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
458 |
connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
459 |
{ |
460 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
461 |
if (repID != symbol1RepID && repID != symbol2RepID) |
462 |
result = connector.ConnectItem2SymbolObject; |
463 |
} |
464 |
} |
465 |
|
466 |
foreach (LMConnector connector in branch.Connect2Connectors) |
467 |
{ |
468 |
if (connector.ConnectItem1SymbolObject != null && |
469 |
connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" && |
470 |
connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
471 |
{ |
472 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
473 |
if (repID != symbol1RepID && repID != symbol2RepID) |
474 |
result = connector.ConnectItem1SymbolObject; |
475 |
} |
476 |
|
477 |
if (connector.ConnectItem2SymbolObject != null && |
478 |
connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" && |
479 |
connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
480 |
{ |
481 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
482 |
if (repID != symbol1RepID && repID != symbol2RepID) |
483 |
result = connector.ConnectItem2SymbolObject; |
484 |
} |
485 |
} |
486 |
|
487 |
|
488 |
return result; |
489 |
} |
490 |
private string GetRepresentationId(Symbol2d symbol) |
491 |
{ |
492 |
foreach (var attributes in symbol.AttributeSets) |
493 |
{ |
494 |
foreach (var attribute in attributes) |
495 |
{ |
496 |
string name = attribute.Name; |
497 |
object value = attribute.GetValue(); |
498 |
if (name == "DrawingID") |
499 |
{ |
500 |
return value.ToString(); |
501 |
} |
502 |
} |
503 |
} |
504 |
return null; |
505 |
} |
506 |
private string GetRepresentationId(Point2d point2d) |
507 |
{ |
508 |
foreach (var attributes in point2d.AttributeSets) |
509 |
{ |
510 |
foreach (var attribute in attributes) |
511 |
{ |
512 |
string name = attribute.Name; |
513 |
object value = attribute.GetValue(); |
514 |
if (name == "DrawingID") |
515 |
{ |
516 |
return value.ToString(); |
517 |
} |
518 |
} |
519 |
} |
520 |
return null; |
521 |
} |
522 |
private List<List<string>> SetSymbol(LMADataSource dataSource, string rep, double x, double y, int count) |
523 |
{ |
524 |
LMSymbol _LMSymbol = dataSource.GetSymbol(rep); |
525 |
List<List<string>> result = new List<List<string>>(); |
526 |
List<string> oldIDs = new List<string>() { rep }; |
527 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
528 |
{ |
529 |
if (connector.get_ItemStatus() != "Active") |
530 |
continue; |
531 |
|
532 |
string repID = connector.AsLMRepresentation().Id; |
533 |
string status = connector.get_ItemStatus(); |
534 |
if (status == "Active" && !oldIDs.Contains(repID)) |
535 |
{ |
536 |
List<string> symbols = new List<string>(); |
537 |
oldIDs.Add(repID); |
538 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
539 |
result.Add(symbols); |
540 |
} |
541 |
} |
542 |
|
543 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
544 |
{ |
545 |
if (connector.get_ItemStatus() != "Active") |
546 |
continue; |
547 |
|
548 |
string repID = connector.AsLMRepresentation().Id; |
549 |
string status = connector.get_ItemStatus(); |
550 |
if (status == "Active" && !oldIDs.Contains(repID)) |
551 |
{ |
552 |
List<string> symbols = new List<string>(); |
553 |
oldIDs.Add(repID); |
554 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
555 |
result.Add(symbols); |
556 |
} |
557 |
} |
558 |
|
559 |
ReleaseCOMObjects(_LMSymbol); |
560 |
return result; |
561 |
} |
562 |
private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMConnector connector, double x, double y, int count) |
563 |
{ |
564 |
if (symbols.Count >= count) |
565 |
return; |
566 |
|
567 |
if (connector.ConnectItem1SymbolObject != null && !oldIDs.Contains(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id)) |
568 |
{ |
569 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
570 |
oldIDs.Add(repID); |
571 |
if (connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
572 |
{ |
573 |
double sX = connector.ConnectItem1SymbolObject.get_XCoordinate(), sY = connector.ConnectItem1SymbolObject.get_YCoordinate(); ; |
574 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1); |
575 |
if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL) |
576 |
symbols.Add(repID); |
577 |
} |
578 |
|
579 |
loop(dataSource, oldIDs, symbols, connector.ConnectItem1SymbolObject, x, y, count); |
580 |
} |
581 |
|
582 |
if (symbols.Count >= count) |
583 |
return; |
584 |
|
585 |
if (connector.ConnectItem2SymbolObject != null && !oldIDs.Contains(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id)) |
586 |
{ |
587 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
588 |
oldIDs.Add(repID); |
589 |
if (connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
590 |
{ |
591 |
double sX = connector.ConnectItem2SymbolObject.get_XCoordinate(), sY = connector.ConnectItem2SymbolObject.get_YCoordinate(); ; |
592 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1); |
593 |
if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL) |
594 |
symbols.Add(repID); |
595 |
} |
596 |
|
597 |
loop(dataSource, oldIDs, symbols, connector.ConnectItem2SymbolObject, x, y, count); |
598 |
} |
599 |
} |
600 |
private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMSymbol _LMSymbol, double x, double y, int count) |
601 |
{ |
602 |
if (symbols.Count >= count) |
603 |
return; |
604 |
|
605 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
606 |
{ |
607 |
if (connector.get_ItemStatus() != "Active") |
608 |
continue; |
609 |
|
610 |
string repID = connector.AsLMRepresentation().Id; |
611 |
string status = connector.get_ItemStatus(); |
612 |
if (status == "Active" && !oldIDs.Contains(repID)) |
613 |
{ |
614 |
oldIDs.Add(repID); |
615 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
616 |
} |
617 |
} |
618 |
|
619 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
620 |
{ |
621 |
if (connector.get_ItemStatus() != "Active") |
622 |
continue; |
623 |
|
624 |
string repID = connector.AsLMRepresentation().Id; |
625 |
string status = connector.get_ItemStatus(); |
626 |
if (status == "Active" && !oldIDs.Contains(repID)) |
627 |
{ |
628 |
oldIDs.Add(repID); |
629 |
loop(dataSource, oldIDs, symbols, connector, x, y, count); |
630 |
} |
631 |
} |
632 |
} |
633 |
private Symbol2d GetSymbol2DByRepID(LMADataSource dataSource, string repID) |
634 |
{ |
635 |
LMSymbol _LMSymbol = dataSource.GetSymbol(repID); |
636 |
Symbol2d symbol2D = application.ActiveDocument.ActiveSheet.DrawingObjects[_LMSymbol.get_GraphicOID().ToString()]; |
637 |
ReleaseCOMObjects(_LMSymbol); |
638 |
return symbol2D; |
639 |
} |
640 |
private void MovePoint2d(LMADataSource datasource, string repID, SymmetryArrow arrow, double moveX, double moveY) |
641 |
{ |
642 |
LMSymbol _LMSymbol = datasource.GetSymbol(repID); |
643 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
644 |
{ |
645 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength())) |
646 |
{ |
647 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
648 |
{ |
649 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
650 |
point.X += moveX; |
651 |
point.Y += moveY; |
652 |
} |
653 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
654 |
{ |
655 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
656 |
point.X += moveX; |
657 |
point.Y += moveY; |
658 |
} |
659 |
} |
660 |
} |
661 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
662 |
{ |
663 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength())) |
664 |
{ |
665 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
666 |
{ |
667 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
668 |
point.X += moveX; |
669 |
point.Y += moveY; |
670 |
} |
671 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
672 |
{ |
673 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
674 |
point.X += moveX; |
675 |
point.Y += moveY; |
676 |
} |
677 |
} |
678 |
} |
679 |
ReleaseCOMObjects(_LMSymbol); |
680 |
} |
681 |
private List<Point2d> FindAllPoint2d(LMADataSource dataSource, string repID, string nextRepID) |
682 |
{ |
683 |
LMSymbol _LMSymbol = dataSource.GetSymbol(repID); |
684 |
List<string> endIDs = new List<string>() { repID }; |
685 |
List<string> graphicOIDs = new List<string>(); |
686 |
List<Point2d> result = new List<Point2d>(); |
687 |
FindPointsLoop(dataSource, _LMSymbol, endIDs, nextRepID, graphicOIDs); |
688 |
ReleaseCOMObjects(_LMSymbol); |
689 |
foreach (var item in graphicOIDs) |
690 |
{ |
691 |
Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[item] as Point2d; |
692 |
result.Add(point); |
693 |
} |
694 |
|
695 |
return result; |
696 |
} |
697 |
private bool FindPointsLoop(LMADataSource dataSource, LMSymbol _LMSymbol, List<string> endIDs, string targetRepID, List<string> graphicOIDs) |
698 |
{ |
699 |
foreach (LMConnector connector in _LMSymbol.Connect1Connectors) |
700 |
{ |
701 |
if (connector.get_ItemStatus() != "Active") |
702 |
continue; |
703 |
|
704 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
705 |
{ |
706 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
707 |
if (!endIDs.Contains(repID)) |
708 |
{ |
709 |
endIDs.Add(repID); |
710 |
if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
711 |
{ |
712 |
if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs)) |
713 |
{ |
714 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
715 |
graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()); |
716 |
return true; |
717 |
} |
718 |
} |
719 |
else if (targetRepID == repID) |
720 |
{ |
721 |
return true; |
722 |
} |
723 |
} |
724 |
} |
725 |
if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
726 |
{ |
727 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
728 |
if (!endIDs.Contains(repID)) |
729 |
{ |
730 |
endIDs.Add(repID); |
731 |
if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
732 |
{ |
733 |
if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs)) |
734 |
{ |
735 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
736 |
graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()); |
737 |
return true; |
738 |
} |
739 |
} |
740 |
else if (targetRepID == repID) |
741 |
{ |
742 |
return true; |
743 |
} |
744 |
} |
745 |
} |
746 |
} |
747 |
foreach (LMConnector connector in _LMSymbol.Connect2Connectors) |
748 |
{ |
749 |
if (connector.get_ItemStatus() != "Active") |
750 |
continue; |
751 |
|
752 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
753 |
{ |
754 |
string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id; |
755 |
if (!endIDs.Contains(repID)) |
756 |
{ |
757 |
endIDs.Add(repID); |
758 |
if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
759 |
{ |
760 |
if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs)) |
761 |
{ |
762 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
763 |
graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()); |
764 |
return true; |
765 |
} |
766 |
} |
767 |
else if (targetRepID == repID) |
768 |
{ |
769 |
return true; |
770 |
} |
771 |
} |
772 |
} |
773 |
if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
774 |
{ |
775 |
string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id; |
776 |
if (!endIDs.Contains(repID)) |
777 |
{ |
778 |
endIDs.Add(repID); |
779 |
if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
780 |
{ |
781 |
if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs)) |
782 |
{ |
783 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
784 |
graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()); |
785 |
return true; |
786 |
} |
787 |
} |
788 |
else if (targetRepID == repID) |
789 |
{ |
790 |
return true; |
791 |
} |
792 |
} |
793 |
} |
794 |
} |
795 |
|
796 |
return false; |
797 |
} |
798 |
#endregion |
799 |
#region SpecBreak |
800 |
private void btnSpecBreakRelocation_Click(object sender, EventArgs e) |
801 |
{ |
802 |
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
803 |
WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
804 |
application = wApp.RADApplication; |
805 |
|
806 |
int count = application.ActiveSelectSet.Count; |
807 |
int dependencyCount = 0; |
808 |
foreach (var item in application.ActiveSelectSet) |
809 |
if (item.GetType() == typeof(DependencyObject)) |
810 |
dependencyCount++; |
811 |
|
812 |
if ((count == 3 || count == 4) && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d) && |
813 |
(dependencyCount == 2 || dependencyCount == 3)) |
814 |
{ |
815 |
Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d; |
816 |
|
817 |
if (!symbol.DefinitionName.Contains(@"Design\Annotation\Graphics\")) |
818 |
{ |
819 |
MessageBox.Show("Select SpecBreak!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
820 |
return; |
821 |
} |
822 |
|
823 |
DependencyObject dependency1 = application.ActiveSelectSet[1] as DependencyObject; |
824 |
DependencyObject dependency2 = application.ActiveSelectSet[2] as DependencyObject; |
825 |
DependencyObject dependency3 = null; |
826 |
if (count == 4) |
827 |
dependency3 = application.ActiveSelectSet[3] as DependencyObject; |
828 |
|
829 |
application.ActiveSelectSet.RemoveAll(); |
830 |
double angle = symbol.Angle; |
831 |
if (symbol.GetTransform().HasReflection) |
832 |
angle += Math.PI; |
833 |
|
834 |
double degree = double.NaN; |
835 |
if (angle > -0.1 && angle < 0.1) |
836 |
degree = 0; |
837 |
else if (angle > 1.56 && angle < 1.58) |
838 |
degree = 90; |
839 |
else if (angle > 3.13 && angle < 3.15) |
840 |
degree = 180; |
841 |
else if (angle > 4.7 && angle < 4.72) |
842 |
degree = 270; |
843 |
else if (angle > 6.27 && angle < 6.29) |
844 |
degree = 0; |
845 |
else if (angle > -1.58 && angle < -1.56) |
846 |
degree = 270; |
847 |
else |
848 |
throw new Exception("Error"); |
849 |
|
850 |
|
851 |
double originX, originY; |
852 |
symbol.GetOrigin(out originX, out originY); |
853 |
|
854 |
double crossX = 0; |
855 |
double crossY = 0; |
856 |
double topX = 0; |
857 |
double topY = 0; |
858 |
foreach (var item in symbol.DrawingObjects) |
859 |
{ |
860 |
Line2d line2d = item as Line2d; |
861 |
if (line2d != null) |
862 |
{ |
863 |
double x1, y1, x2, y2; |
864 |
line2d.GetStartPoint(out x1, out y1); |
865 |
line2d.GetEndPoint(out x2, out y2); |
866 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 0.1); |
867 |
|
868 |
if (slopeType == SlopeType.HORIZONTAL) |
869 |
{ |
870 |
if (crossY == 0) |
871 |
crossY = y1; |
872 |
else |
873 |
crossY = (crossY + y1) / 2; |
874 |
|
875 |
switch (degree) |
876 |
{ |
877 |
case 90: |
878 |
if (topX == 0) |
879 |
topX = Math.Min(x1, x2); |
880 |
else |
881 |
topX = Math.Min(topX, Math.Min(x1, x2)); |
882 |
break; |
883 |
case 270: |
884 |
if (topX == 0) |
885 |
topX = Math.Max(x1, x2); |
886 |
else |
887 |
topX = Math.Max(topX, Math.Max(x1, x2)); |
888 |
break; |
889 |
default: |
890 |
break; |
891 |
} |
892 |
} |
893 |
else if (slopeType == SlopeType.VERTICAL) |
894 |
{ |
895 |
if (crossX == 0) |
896 |
crossX = x1; |
897 |
else |
898 |
crossX = (crossX + x1) / 2; |
899 |
|
900 |
switch (degree) |
901 |
{ |
902 |
case 0: |
903 |
if (topY == 0) |
904 |
topY = Math.Max(y1, y2); |
905 |
else |
906 |
topY = Math.Max(topY, Math.Max(y1, y2)); |
907 |
break; |
908 |
case 180: |
909 |
if (topY == 0) |
910 |
topY = Math.Min(y1, y2); |
911 |
else |
912 |
topY = Math.Min(topY, Math.Min(y1, y2)); |
913 |
break; |
914 |
default: |
915 |
break; |
916 |
} |
917 |
} |
918 |
} |
919 |
} |
920 |
switch (degree) |
921 |
{ |
922 |
case 0: |
923 |
crossX = originX; |
924 |
topX = crossX; |
925 |
break; |
926 |
case 90: |
927 |
crossY = originY; |
928 |
topY = crossY; |
929 |
break; |
930 |
case 180: |
931 |
crossX = originX; |
932 |
topX = crossX; |
933 |
break; |
934 |
case 270: |
935 |
crossY = originY; |
936 |
topY = crossY; |
937 |
break; |
938 |
default: |
939 |
break; |
940 |
} |
941 |
|
942 |
SpecBreakRelocation(degree, crossX, crossY, topX, topY, dependency1, dependency2, dependency3); |
943 |
} |
944 |
else |
945 |
{ |
946 |
MessageBox.Show("Check Rule!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
947 |
} |
948 |
} |
949 |
private void SpecBreakRelocation(double degree, double crossX, double crossY, double topX, double topY, DependencyObject dependency1, DependencyObject dependency2, DependencyObject dependency3) |
950 |
{ |
951 |
double d1X1, d1Y1, d1X2, d1Y2, d2X1, d2Y1, d2X2, d2Y2; |
952 |
|
953 |
string type1 = GetDrawingItemType(dependency1); |
954 |
string type2 = GetDrawingItemType(dependency2); |
955 |
|
956 |
if (type1 == "Connector") |
957 |
{ |
958 |
|
959 |
} |
960 |
if (type2 == "Connector") |
961 |
{ |
962 |
|
963 |
} |
964 |
return; |
965 |
|
966 |
Ingr.RAD2D.TextBox textBox1 = FindTextBoxArea(dependency1, out d1X1, out d1Y1, out d1X2, out d1Y2); |
967 |
Ingr.RAD2D.TextBox textBox2 = FindTextBoxArea(dependency2, out d2X1, out d2Y1, out d2X2, out d2Y2); |
968 |
|
969 |
switch (degree) |
970 |
{ |
971 |
case 0: |
972 |
textBox1.Move(d1X2, d1Y2, crossX, crossY); |
973 |
textBox2.Move(d2X1, d2Y2, crossX, crossY); |
974 |
break; |
975 |
case 90: |
976 |
textBox1.Move(d1X1, d1Y2, crossX, crossY); |
977 |
textBox2.Move(d2X1, d2Y1, crossX, crossY); |
978 |
break; |
979 |
case 180: |
980 |
textBox1.Move(d1X2, d1Y1, crossX, crossY); |
981 |
textBox2.Move(d2X1, d2Y1, crossX, crossY); |
982 |
break; |
983 |
case 270: |
984 |
textBox1.Move(d1X2, d1Y2, crossX, crossY); |
985 |
textBox2.Move(d2X2, d2Y1, crossX, crossY); |
986 |
break; |
987 |
default: |
988 |
break; |
989 |
} |
990 |
} |
991 |
private string GetDrawingItemType(DependencyObject dependency) |
992 |
{ |
993 |
string result = string.Empty; |
994 |
|
995 |
foreach (var attributes in dependency.AttributeSets) |
996 |
{ |
997 |
foreach (var attribute in attributes) |
998 |
{ |
999 |
if (attribute.Name == "DrawingItemType") |
1000 |
return attribute.GetValue().ToString(); |
1001 |
} |
1002 |
} |
1003 |
|
1004 |
return result; |
1005 |
} |
1006 |
private Ingr.RAD2D.TextBox FindTextBoxArea(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2) |
1007 |
{ |
1008 |
x1 = 0; |
1009 |
y1 = 0; |
1010 |
x2 = 0; |
1011 |
y2 = 0; |
1012 |
Ingr.RAD2D.TextBox textBox = null; |
1013 |
foreach (var item in dependency.DrawingObjects) |
1014 |
{ |
1015 |
if (item.GetType() == typeof(Ingr.RAD2D.TextBox)) |
1016 |
{ |
1017 |
textBox = item as Ingr.RAD2D.TextBox; |
1018 |
textBox.Range(out x1, out y1, out x2, out y2); |
1019 |
break; |
1020 |
} |
1021 |
} |
1022 |
|
1023 |
return textBox; |
1024 |
} |
1025 |
#endregion |
1026 |
#region Hot Key |
1027 |
[System.Runtime.InteropServices.DllImport("user32.dll")] |
1028 |
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); |
1029 |
[System.Runtime.InteropServices.DllImport("user32.dll")] |
1030 |
private static extern bool UnregisterHotKey(IntPtr hWnd, int id); |
1031 |
enum KeyModifier |
1032 |
{ |
1033 |
None = 0, |
1034 |
Alt = 1, |
1035 |
Control = 2, |
1036 |
Shift = 4, |
1037 |
WinKey = 8 |
1038 |
} |
1039 |
protected override void WndProc(ref Message m) |
1040 |
{ |
1041 |
base.WndProc(ref m); |
1042 |
if (m.Msg == 0x0312) |
1043 |
{ |
1044 |
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); |
1045 |
KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF); |
1046 |
int id = m.WParam.ToInt32(); |
1047 |
application.RunCommand(CommandConstants.igcmdGridSnap); |
1048 |
} |
1049 |
|
1050 |
} |
1051 |
#endregion |
1052 |
#endregion |
1053 |
|
1054 |
#region TEST |
1055 |
|
1056 |
private void simpleButton1_Click(object sender, EventArgs e) |
1057 |
{ |
1058 |
Placement placement = new Placement(); |
1059 |
if (application.ActiveSelectSet.Count > 0) |
1060 |
{ |
1061 |
string modelItemId = null; |
1062 |
Symbol2d symbol2D = application.ActiveSelectSet[0] as Symbol2d; |
1063 |
DependencyObject dependency = application.ActiveSelectSet[0] as DependencyObject; |
1064 |
application.ActiveSelectSet.RemoveAll(); |
1065 |
if (symbol2D != null) |
1066 |
{ |
1067 |
return; |
1068 |
foreach (var attributes in symbol2D.AttributeSets) |
1069 |
{ |
1070 |
foreach (var attribute in attributes) |
1071 |
{ |
1072 |
if (attribute.Name == "ModelID") |
1073 |
modelItemId = attribute.GetValue().ToString(); |
1074 |
} |
1075 |
} |
1076 |
|
1077 |
if (modelItemId!=null) |
1078 |
{ |
1079 |
LMADataSource dataSource = new LMADataSource(); |
1080 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
1081 |
foreach (LMRepresentation item in modelItem.Representations) |
1082 |
{ |
1083 |
if (item.ModelItemID == modelItemId) |
1084 |
{ |
1085 |
dataSource = placement.PIDDataSource; |
1086 |
LMSymbol symbol = dataSource.GetSymbol(item.Id); |
1087 |
double oldx = symbol.get_XCoordinate(); |
1088 |
double oldy = symbol.get_YCoordinate(); |
1089 |
symbol2D.Move(0, 0, 0, GridSetting.GetInstance().Length); |
1090 |
|
1091 |
dataSource = new LMADataSource(); |
1092 |
//dataSource = placement.PIDDataSource; |
1093 |
symbol = dataSource.GetSymbol(item.Id); |
1094 |
double x = symbol.get_XCoordinate(); |
1095 |
double y = symbol.get_YCoordinate(); |
1096 |
} |
1097 |
} |
1098 |
} |
1099 |
} |
1100 |
else if (dependency != null) |
1101 |
{ |
1102 |
foreach (dynamic item in dependency.DrawingObjects) |
1103 |
{ |
1104 |
item.Move(0, 0, 0, GridSetting.GetInstance().Length); |
1105 |
} |
1106 |
} |
1107 |
} |
1108 |
|
1109 |
return; |
1110 |
Thread outThread = new Thread(func2 => |
1111 |
{ |
1112 |
for (int i = 100; i < 120; i++) |
1113 |
{ |
1114 |
Thread thread = new Thread(func => |
1115 |
{ |
1116 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
1117 |
//WrapperApplication wApp = new WrapperApplication(application.Application); |
1118 |
//Ingr.RAD2D.Application radApp = wApp.RADApplication; |
1119 |
dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123"); |
1120 |
|
1121 |
Thread.Sleep(5000); |
1122 |
|
1123 |
drawing.CloseDrawing(true); |
1124 |
|
1125 |
//application.Quit(); |
1126 |
ReleaseCOMObjects(application); |
1127 |
application = null; |
1128 |
ReleaseCOMObjects(drawing); |
1129 |
drawing = null; |
1130 |
Thread.Sleep(5000); |
1131 |
}); |
1132 |
thread.Start(); |
1133 |
thread.Join(); |
1134 |
} |
1135 |
}); |
1136 |
outThread.Start(); |
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
//radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid"); |
1143 |
|
1144 |
//radApp.ActiveDocument.Close(true); |
1145 |
//drawing.CloseDrawing(true); |
1146 |
|
1147 |
//ReleaseCOMObjects(application); |
1148 |
//ReleaseCOMObjects(drawing); |
1149 |
//application = null; |
1150 |
//wApp = null; |
1151 |
//radApp = null; |
1152 |
//drawing = null; |
1153 |
} |
1154 |
|
1155 |
private void AutoJoinPipeRun() |
1156 |
{ |
1157 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
1158 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
1159 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
1160 |
|
1161 |
string modelItemId = null; |
1162 |
List<double[]> vertices = new List<double[]>(); |
1163 |
if (radApp.ActiveSelectSet.Count == 0) |
1164 |
{ |
1165 |
return; |
1166 |
} |
1167 |
dynamic OID = radApp.ActiveSelectSet[0].Key(); |
1168 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1169 |
foreach (var attributes in drawingObject.AttributeSets) |
1170 |
{ |
1171 |
foreach (var attribute in attributes) |
1172 |
{ |
1173 |
if (attribute.Name == "ModelID") |
1174 |
modelItemId = attribute.GetValue().ToString(); |
1175 |
} |
1176 |
} |
1177 |
radApp.ActiveSelectSet.RemoveAll(); |
1178 |
|
1179 |
} |
1180 |
#endregion |
1181 |
|
1182 |
|
1183 |
[DllImport("user32.dll")] |
1184 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
1185 |
|
1186 |
[DllImport("user32.dll", SetLastError = true)] |
1187 |
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
1188 |
|
1189 |
private void ConverterDocking_Load(object sender, EventArgs e) |
1190 |
{ |
1191 |
#if DEBUG |
1192 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
1193 |
#else |
1194 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
1195 |
#endif |
1196 |
|
1197 |
} |
1198 |
|
1199 |
|
1200 |
} |
1201 |
} |