-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrepChecker.cs
171 lines (153 loc) · 5.7 KB
/
BrepChecker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using devDept.Eyeshot;
using devDept.Eyeshot.Entities;
using devDept.Geometry;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace eyeshot강의
{
internal class BrepChecker
{
public void SelectPlanarFaces(Model model1)
{
foreach (Entity ent in model1.Entities)
{
// 객체를 Brep로 형변환을 시도
Brep b = ent as Brep;
// 변환 실패하면 통과
if (b == null)
{
continue;
}
// brep의 face를 모두 조회
for (int i = 0; i < b.Faces.Length; ++i)
{
Brep.Face face = b.Faces[i];
var surface = face.Surface;
// face가 콘 형태이면 선택
if (surface is PlanarSurf && !surface.GetType().IsSubclassOf(typeof(PlanarSurf)))
{
b.SetFaceSelection(i, true);
}
}
}
model1.Invalidate();
}
public void SelectConeFaces(Model model1)
{
foreach (Entity ent in model1.Entities)
{
// 객체를 Brep로 형변환을 시도
Brep b = ent as Brep;
// 변환 실패하면 통과
if (b == null)
{
continue;
}
// brep의 face를 모두 조회
for (int i = 0; i < b.Faces.Length; ++i)
{
Brep.Face face = b.Faces[i];
var surface = face.Surface;
// face가 콘 형태이면 선택
if (surface is ConicalSurf && !surface.GetType().IsSubclassOf(typeof(ConicalSurf)))
{
b.SetFaceSelection(i, true);
}
}
}
model1.Invalidate();
}
public void SelectCylinderFaces(Model model1)
{
foreach (Entity ent in model1.Entities)
{
// 객체를 Brep로 형변환을 시도
Brep b = ent as Brep;
// 변환 실패하면 통과
if (b == null)
{
continue;
}
// brep의 face를 모두 조회
for (int i = 0; i < b.Faces.Length; ++i)
{
Brep.Face face = b.Faces[i];
var surface = face.Surface;
// face가 실린더 형태이면 선택
if (surface is CylindricalSurf && !surface.GetType().IsSubclassOf(typeof(CylindricalSurf)))
{
b.SetFaceSelection(i, true);
}
}
}
model1.Invalidate();
}
// 화면에 있는 brep의 edge를 모두 추출
public void GetEdges(Model model1)
{
List<Entity> newEntities = new List<Entity>();
foreach (Entity ent in model1.Entities)
{
// 객체를 Brep로 형변환을 시도
Brep b = ent as Brep;
// 변환 실패하면 통과
if (b == null)
{
continue;
}
// brep의 edge를 모두 조회
foreach (Brep.Edge edge in b.Edges)
{
// line이면 line으로 복사
if (edge.Curve is Line)
{
Line line = (Line)edge.Curve;
newEntities.Add((Line)line.Clone());
}
// circle이면 circle로 복사
else if (edge.Curve is Circle)
{
Circle circle = (Circle)edge.Curve;
newEntities.Add((Circle)circle.Clone());
}
}
}
// 복사한 edge curve의 사본들을 x방향으로 50 이동
foreach (Entity ent in newEntities)
{
ent.Translate(50, 0, 0);
}
// edge curve의 사본들을 entities에 추가
model1.Entities.AddRange(newEntities);
model1.Invalidate();
}
// 화면에 표시되고 있는 brep의 체적을 모두 계산
public void CalcVolumes(Model model1)
{
StringBuilder sb = new StringBuilder();
// 모든 객체를 검사
foreach (devDept.Eyeshot.Entities.Entity ent in model1.Entities)
{
// 객체를 Brep로 형변환을 시도
Brep b = ent as Brep;
// 변환 실패하면 통과
if (b == null)
{
continue;
}
// brep의 체적과 center를 가져옴.
Point3D center = new Point3D();
double volume = b.GetVolume(out center);
// 표시할 내용을 string으로 변환
string volumeText = volume.ToString("0.00"); // 소수점 2자리
string xText = center.X.ToString("0.0"); // 소수점 1자리
string yText = center.Y.ToString("0.0"); // 소수점 1자리
string zText = center.Z.ToString("0.0"); // 소수점 1자리
// string builder에 내용 추가
sb.Append($"Volume : {volumeText}, Center : {xText}, {yText}, {zText}\n");
}
MessageBox.Show(sb.ToString());
}
}
}