1 |
cfda1fed
|
gaqhf
|
using System;
|
2 |
|
|
using System.Collections.Generic;
|
3 |
|
|
using System.Linq;
|
4 |
|
|
using System.Text;
|
5 |
|
|
using System.Threading.Tasks;
|
6 |
|
|
using Llama;
|
7 |
|
|
using Plaice;
|
8 |
|
|
using Converter.BaseModel;
|
9 |
|
|
using Converter.SPPID.Model;
|
10 |
|
|
using Converter.SPPID.Properties;
|
11 |
|
|
using Converter.SPPID.Util;
|
12 |
|
|
using Converter.SPPID.DB;
|
13 |
|
|
|
14 |
5dfb8a24
|
gaqhf
|
using System.Windows;
|
15 |
cfda1fed
|
gaqhf
|
using System.Threading;
|
16 |
5dfb8a24
|
gaqhf
|
using System.Drawing;
|
17 |
cfda1fed
|
gaqhf
|
using Microsoft.VisualBasic;
|
18 |
|
|
using Newtonsoft.Json;
|
19 |
|
|
|
20 |
|
|
namespace Converter.SPPID
|
21 |
|
|
{
|
22 |
|
|
public class AutoModeling
|
23 |
|
|
{
|
24 |
5dfb8a24
|
gaqhf
|
Placement _placement = new Placement();
|
25 |
cfda1fed
|
gaqhf
|
SPPID_Document document;
|
26 |
|
|
public AutoModeling(SPPID_Document document)
|
27 |
|
|
{
|
28 |
|
|
this.document = document;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
public void Run()
|
32 |
|
|
{
|
33 |
5dfb8a24
|
gaqhf
|
//dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
|
34 |
|
|
//dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName);
|
35 |
|
|
//application.ActiveWindow.Fit();
|
36 |
|
|
//Thread.Sleep(100);
|
37 |
|
|
//application.ActiveWindow.Zoom = 60;
|
38 |
|
|
//Thread.Sleep(100);
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
foreach (LineNumber lineNumber in document.LINENUMBERS)
|
42 |
|
|
{
|
43 |
|
|
foreach (LineNumberRun run in lineNumber.RUNS)
|
44 |
|
|
{
|
45 |
|
|
// Run 별로 Modeling
|
46 |
|
|
Symbol prevSymbol = null;
|
47 |
1b261371
|
gaqhf
|
// Symbol 먼저
|
48 |
|
|
foreach (var item in run.RUNITEMS)
|
49 |
5dfb8a24
|
gaqhf
|
{
|
50 |
|
|
if (item.GetType() == typeof(Symbol))
|
51 |
|
|
{
|
52 |
|
|
Symbol symbol = item as Symbol;
|
53 |
|
|
SymbolModeling(symbol, prevSymbol);
|
54 |
|
|
prevSymbol = symbol;
|
55 |
|
|
}
|
56 |
1b261371
|
gaqhf
|
}
|
57 |
|
|
|
58 |
|
|
object prevItem = null;
|
59 |
|
|
prevSymbol = null;
|
60 |
|
|
foreach (var item in run.RUNITEMS)
|
61 |
|
|
{
|
62 |
|
|
if (item.GetType() == typeof(Line))
|
63 |
5dfb8a24
|
gaqhf
|
{
|
64 |
1b261371
|
gaqhf
|
|
65 |
5dfb8a24
|
gaqhf
|
}
|
66 |
|
|
|
67 |
|
|
prevItem = item;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
ReleaseCOMObjects(_placement);
|
76 |
|
|
System.Windows.Forms.MessageBox.Show("end");
|
77 |
|
|
}
|
78 |
cfda1fed
|
gaqhf
|
|
79 |
1b261371
|
gaqhf
|
|
80 |
5dfb8a24
|
gaqhf
|
private void TestSource()
|
81 |
|
|
{
|
82 |
cfda1fed
|
gaqhf
|
|
83 |
|
|
}
|
84 |
|
|
|
85 |
5dfb8a24
|
gaqhf
|
private void SymbolModeling(Symbol symbol, Symbol prevSymbol)
|
86 |
cfda1fed
|
gaqhf
|
{
|
87 |
5dfb8a24
|
gaqhf
|
LMSymbol _LMSymbol = null;
|
88 |
|
|
|
89 |
|
|
string mappingPath = symbol.SPPID.MAPPINGNAME;
|
90 |
1b261371
|
gaqhf
|
double x = symbol.SPPID.ORIGINAL_X;
|
91 |
|
|
double y = symbol.SPPID.ORIGINAL_Y;
|
92 |
5dfb8a24
|
gaqhf
|
int mirror = 0;
|
93 |
|
|
double angle = symbol.ANGLE;
|
94 |
|
|
LMSymbol _TargetItem = null;
|
95 |
|
|
|
96 |
|
|
if (prevSymbol != null)
|
97 |
|
|
{
|
98 |
1b261371
|
gaqhf
|
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
|
99 |
|
|
LMADataSource dataSource = _placement.PIDDataSource;
|
100 |
|
|
LMSymbol prevLMSymbol = dataSource.GetSymbol(prevSymbol.SPPID.ITEMOBJECT);
|
101 |
|
|
double prevX = prevLMSymbol.get_XCoordinate();
|
102 |
|
|
double prevY = prevLMSymbol.get_YCoordinate();
|
103 |
5dfb8a24
|
gaqhf
|
if (slopeType == SlopeType.HORIZONTAL)
|
104 |
1b261371
|
gaqhf
|
y = prevY;
|
105 |
5dfb8a24
|
gaqhf
|
else if (slopeType == SlopeType.VERTICAL)
|
106 |
1b261371
|
gaqhf
|
x = prevX;
|
107 |
5dfb8a24
|
gaqhf
|
|
108 |
|
|
}
|
109 |
|
|
else
|
110 |
|
|
{
|
111 |
|
|
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
if (_TargetItem == null)
|
115 |
|
|
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
|
116 |
|
|
else
|
117 |
|
|
{
|
118 |
|
|
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
|
119 |
|
|
ReleaseCOMObjects(_TargetItem);
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
if (_LMSymbol != null)
|
123 |
|
|
{
|
124 |
1b261371
|
gaqhf
|
symbol.SPPID.ITEMOBJECT = _LMSymbol.AsLMRepresentation().Id;
|
125 |
5dfb8a24
|
gaqhf
|
}
|
126 |
|
|
|
127 |
|
|
ReleaseCOMObjects(_LMSymbol);
|
128 |
cfda1fed
|
gaqhf
|
}
|
129 |
|
|
|
130 |
|
|
private void LineModeling(Line line)
|
131 |
|
|
{
|
132 |
5dfb8a24
|
gaqhf
|
object DrwingID = "0";
|
133 |
|
|
_LMAItem _LMAItem = _placement.PIDCreateItem(line.SPPID.MAPPINGNAME, ref DrwingID);
|
134 |
|
|
PlaceRunInputs placeRunInputs = new PlaceRunInputs();
|
135 |
|
|
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
|
136 |
|
|
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
|
137 |
|
|
|
138 |
|
|
LMConnector lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
|
139 |
|
|
lMConnector.Commit();
|
140 |
|
|
|
141 |
|
|
ReleaseCOMObjects(lMConnector);
|
142 |
|
|
ReleaseCOMObjects(placeRunInputs);
|
143 |
|
|
ReleaseCOMObjects(_LMAItem);
|
144 |
cfda1fed
|
gaqhf
|
}
|
145 |
|
|
|
146 |
1b261371
|
gaqhf
|
private void LineModeling(List<Line> lines)
|
147 |
|
|
{
|
148 |
|
|
object DrwingID = "0";
|
149 |
|
|
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME, ref DrwingID);
|
150 |
|
|
PlaceRunInputs placeRunInputs = new PlaceRunInputs();
|
151 |
|
|
for (int i = 0; i < lines.Count; i++)
|
152 |
|
|
{
|
153 |
|
|
Line line = lines[i];
|
154 |
|
|
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
|
155 |
|
|
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
LMConnector lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
|
160 |
|
|
lMConnector.Commit();
|
161 |
|
|
|
162 |
|
|
ReleaseCOMObjects(lMConnector);
|
163 |
|
|
ReleaseCOMObjects(placeRunInputs);
|
164 |
|
|
ReleaseCOMObjects(_LMAItem);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
cfda1fed
|
gaqhf
|
private void LineNumberModeling(LineNumber lineNumber)
|
168 |
|
|
{
|
169 |
|
|
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
private void TextModeling(Text text)
|
173 |
|
|
{
|
174 |
|
|
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
private void NoteModeling(Note note)
|
178 |
|
|
{
|
179 |
|
|
|
180 |
|
|
}
|
181 |
|
|
|
182 |
5dfb8a24
|
gaqhf
|
|
183 |
|
|
public void ReleaseCOMObjects(params object[] objVars)
|
184 |
|
|
{
|
185 |
|
|
int intNewRefCount = 0;
|
186 |
|
|
foreach (object obj in objVars)
|
187 |
|
|
{
|
188 |
|
|
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
|
189 |
|
|
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
|
190 |
|
|
}
|
191 |
|
|
}
|
192 |
cfda1fed
|
gaqhf
|
}
|
193 |
|
|
} |