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
30from functools import cmp_to_key
31
33
34class Pair:
35 def __init__(self, theFirst: float, theSecond: float):
36 self.First = theFirst
37 self.Second = theSecond
38
39 def __repr__(self):
40 return f"Pair({self.First}, {self.Second})"
41
42 def __str__(self):
43 return f"{self.First:.5f} x {self.Second:.5f}"
44
45class Dimension:
46 def __init__(self, theX: float, theY: float, theZ: float):
47 self.X = theX
48 self.Y = theY
49 self.Z = theZ
50
51 def __repr__(self):
52 return f"Dimension({self.X}, {self.Y}, {self.Z})"
53
54 def __str__(self):
55 return f"{self.X:.5f} x {self.Y:.5f} x {self.Z:.5f}"
56
57class Direction:
58 def __init__(self, theX: float, theY: float, theZ: float):
59 self.X = theX
60 self.Y = theY
61 self.Z = theZ
62
63 def __repr__(self):
64 return f"Direction({self.X}, {self.Y}, {self.Z})"
65
66 def __str__(self):
67 return f"({self.X:.2f}, {self.Y:.2f}, {self.Z:.2f})"
68
69def CompareFeatures(theA: mtk.MTKBase_Feature, theB: mtk.MTKBase_Feature):
70 aComparator = mtk.MTKBase_FeatureComparator()
71 anALessThanB = aComparator(theA, theB)
72 if anALessThanB:
73 return -1
74
75 aBLessThanA = aComparator(theB, theA)
76 if aBLessThanA:
77 return 1
78
79 return 0
80
81class FeatureGroupManager:
82 def __init__(self):
83 self.__myGroups = []
84
85 def AddFeature(self, theGroupName: str, theSubgroupName: str, theHasParameters: bool, theFeature: mtk.MTKBase_Feature):
86
87 aRes = -1
88 for i in range(len(self.__myGroups)):
89 aGroup = self.__myGroups[i]
90 if aGroup.myName == theGroupName:
91 aRes = i
92 break
93
94 if aRes == -1:
95 self.__myGroups.append(self.FeatureGroup(theGroupName, theSubgroupName, theHasParameters))
96 aRes = len(self.__myGroups) - 1
97
98
99 aGroup = self.__myGroups[aRes]
100 aSubgroups = aGroup.myFeatureSubgroups
101 aSubgroups.Append(theFeature)
102
103 def Print(self, theFeatureType: str, thePrintFeatureParameters):
104 self.__myGroups.sort(key=cmp_to_key(self.__compare))
105
106 aTotalCount = 0
107 for i in self.__myGroups:
108 aFeatureCount = i.FeatureCount()
109 aTotalCount += aFeatureCount
110
111 print(" ", i.myName, ": ", aFeatureCount, sep="")
112
113 if not i.myHasParameters:
114 continue
115
116 aSubgroupName = i.mySubgroupName
117 for j in range(i.myFeatureSubgroups.Size()):
118 print(" ", i.myFeatureSubgroups.GetFeatureCount(j), " ", aSubgroupName, " with", sep="")
119 thePrintFeatureParameters(i.myFeatureSubgroups.GetFeature(j))
120
121 print("\n Total ", theFeatureType, ": ", aTotalCount, "\n", sep="")
122
123 @staticmethod
124 def PrintFeatureParameter(theName: str, theValue, theUnits: str):
125 print(" ", theName, ": ", theValue, " ", theUnits, sep = "")
126
127 class OrderedFeatureList:
128 def __init__(self):
129 self.__myList = []
130
131 def Append(self, theFeature: mtk.MTKBase_Feature):
132 anInsertIndex = 0
133 for i in self.__myList:
134 aRes = CompareFeatures(theFeature, i.Feature)
135 if aRes == 0:
136 i.Count += 1
137 anInsertIndex = -1
138 break
139 elif aRes < 0:
140 break
141
142 anInsertIndex += 1
143
144 if anInsertIndex >= 0:
145 self.__myList.insert(anInsertIndex, self.FeatureAndCountPair(theFeature))
146
147 def Size(self):
148 return len(self.__myList)
149
150 def GetFeature(self, theIndex: int):
151 return self.__GetFeatureAndCountPair(theIndex).Feature
152
153 def GetFeatureCount(self, theIndex: int):
154 return self.__GetFeatureAndCountPair(theIndex).Count
155
156 def __GetFeatureAndCountPair(self, theIndex: int):
157 return self.__myList[theIndex]
158
159 class FeatureAndCountPair:
160 def __init__(self, theFeature: mtk.MTKBase_Feature):
161 self.Feature = theFeature
162 self.Count = 1
163
164 class FeatureGroup:
165 def __init__(self, theName: str, theSubgroupName: str, theHasParameters: bool):
166 self.myName = theName
167 self.mySubgroupName = theSubgroupName
168 self.myHasParameters = theHasParameters
169 self.myFeatureSubgroups = FeatureGroupManager.OrderedFeatureList()
170
171 def FeatureCount(self):
172 aCount = 0
173 for i in range(self.myFeatureSubgroups.Size()):
174 aCount += self.myFeatureSubgroups.GetFeatureCount(i)
175 return aCount
176
177 @staticmethod
178 def __compare(theA: FeatureGroup, theB: FeatureGroup):
179 anAName = theA.myName
180 aBName = theB.myName
181 if anAName == aBName:
182 return 0
183
184 anAFeatureSubgroups = theA.myFeatureSubgroups
185 aBFeatureSubgroups = theB.myFeatureSubgroups
186 if (not anAFeatureSubgroups) or (not aBFeatureSubgroups):
187 if anAName < aBName:
188 return -1
189 else:
190 return 1
191
192 anAFeature = anAFeatureSubgroups.GetFeature(0)
193 aBFeature = aBFeatureSubgroups.GetFeature(0)
194 return CompareFeatures(anAFeature, aBFeature)
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
30import math
31import os
32import sys
33
34from pathlib import Path
35
37
38sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + "/../../"))
39sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + "/../../helpers/"))
40
41import mtk_license as license
42
43import feature_group
44import shape_processor
45
46def ToDegrees(theAngleRad: float):
47 return theAngleRad * 180.0 / math.pi
48
49def PrintFeatureParameters(theIssue: mtk.MTKBase_Feature):
50
51 if mtk.DFMMachining_SmallDiameterHoleIssue.CompareType(theIssue):
52 aSDHIssue = mtk.DFMMachining_SmallDiameterHoleIssue.Cast(theIssue)
53 feature_group.FeatureGroupManager.PrintFeatureParameter("expected min diameter", aSDHIssue.ExpectedMinDiameter(), "mm")
54 feature_group.FeatureGroupManager.PrintFeatureParameter("actual diameter", aSDHIssue.ActualDiameter(), "mm")
55 elif mtk.DFMMachining_DeepHoleIssue.CompareType(theIssue):
56 aDHIssue = mtk.DFMMachining_DeepHoleIssue.Cast(theIssue)
57 feature_group.FeatureGroupManager.PrintFeatureParameter("expected max depth", aDHIssue.ExpectedMaxDepth(), "mm")
58 feature_group.FeatureGroupManager.PrintFeatureParameter("actual depth", aDHIssue.ActualDepth(), "mm")
59 elif mtk.DFMMachining_NonStandardDiameterHoleIssue.CompareType(theIssue):
60 aNSDHIssue = mtk.DFMMachining_NonStandardDiameterHoleIssue.Cast(theIssue)
61 feature_group.FeatureGroupManager.PrintFeatureParameter("nearest standard diameter", aNSDHIssue.NearestStandardDiameter(), "mm")
62 feature_group.FeatureGroupManager.PrintFeatureParameter("actual diameter", aNSDHIssue.ActualDiameter(), "mm")
63 elif mtk.DFMMachining_NonStandardDrillPointAngleBlindHoleIssue.CompareType(theIssue):
64 aNSDPABHIssue = mtk.DFMMachining_NonStandardDrillPointAngleBlindHoleIssue.Cast(theIssue)
65 feature_group.FeatureGroupManager.PrintFeatureParameter("nearest standard angle", ToDegrees(aNSDPABHIssue.NearestStandardAngle()), "deg")
66 feature_group.FeatureGroupManager.PrintFeatureParameter("actual angle", ToDegrees(aNSDPABHIssue.ActualAngle()), "deg")
67 elif mtk.DFMMachining_FlatBottomHoleIssue.CompareType(theIssue):
68 pass
69 elif mtk.DFMMachining_NonPerpendicularHoleIssue.CompareType(theIssue):
70 pass
71 elif mtk.DFMMachining_IntersectingCavityHoleIssue.CompareType(theIssue):
72 pass
73 elif mtk.DFMMachining_PartialHoleIssue.CompareType(theIssue):
74 aPHIssue = mtk.DFMMachining_PartialHoleIssue.Cast(theIssue)
75 feature_group.FeatureGroupManager.PrintFeatureParameter(
76 "expected min material percent", aPHIssue.ExpectedMinMaterialPercent(), "")
77 feature_group.FeatureGroupManager.PrintFeatureParameter(
78 "actual material percent", aPHIssue.ActualMaterialPercent(), "")
79
80 elif mtk.DFMMachining_NonStandardRadiusMilledPartFloorFilletIssue.CompareType(theIssue):
81 aNSRMPFFIssue = mtk.DFMMachining_NonStandardRadiusMilledPartFloorFilletIssue.Cast(theIssue)
82 feature_group.FeatureGroupManager.PrintFeatureParameter("nearest standard radius", aNSRMPFFIssue.NearestStandardRadius(), "mm")
83 feature_group.FeatureGroupManager.PrintFeatureParameter("actual radius", aNSRMPFFIssue.ActualRadius(), "mm")
84 elif mtk.DFMMachining_DeepPocketIssue.CompareType(theIssue):
85 aDPIssue = mtk.DFMMachining_DeepPocketIssue.Cast(theIssue)
86 feature_group.FeatureGroupManager.PrintFeatureParameter("expected max depth", aDPIssue.ExpectedMaxDepth(), "mm")
87 feature_group.FeatureGroupManager.PrintFeatureParameter("actual depth", aDPIssue.ActualDepth(), "mm")
88 elif mtk.DFMMachining_HighBossIssue.CompareType(theIssue):
89 aHBIssue = mtk.DFMMachining_HighBossIssue.Cast(theIssue)
90 feature_group.FeatureGroupManager.PrintFeatureParameter("expected max height", aHBIssue.ExpectedMaxHeight(), "mm")
91 feature_group.FeatureGroupManager.PrintFeatureParameter("actual height", aHBIssue.ActualHeight(), "mm")
92 elif mtk.DFMMachining_LargeMilledPartIssue.CompareType(theIssue):
93 aLMPIssue = mtk.DFMMachining_LargeMilledPartIssue.Cast(theIssue)
94 anExpectedSize = aLMPIssue.ExpectedMaxMilledPartSize()
95 anActualSize = aLMPIssue.ActualMilledPartSize()
96 feature_group.FeatureGroupManager.PrintFeatureParameter(
97 "expected max size (LxWxH)",
98 feature_group.Dimension(anExpectedSize.Length(), anExpectedSize.Width(), anExpectedSize.Height()),
99 "mm")
100 feature_group.FeatureGroupManager.PrintFeatureParameter(
101 "actual size (LxWxH)",
102 feature_group.Dimension(anActualSize.Length(), anActualSize.Width(), anActualSize.Height()),
103 "mm")
104 elif mtk.DFMMachining_SmallRadiusMilledPartInternalCornerIssue.CompareType(theIssue):
105 aSRMPICIssue = mtk.DFMMachining_SmallRadiusMilledPartInternalCornerIssue.Cast(theIssue)
106 feature_group.FeatureGroupManager.PrintFeatureParameter("expected min radius", aSRMPICIssue.ExpectedMinRadius(), "mm")
107 feature_group.FeatureGroupManager.PrintFeatureParameter("actual radius", aSRMPICIssue.ActualRadius(), "mm")
108 elif mtk.DFMMachining_NonPerpendicularMilledPartShapeIssue.CompareType(theIssue):
109 aNPMPSIssue = mtk.DFMMachining_NonPerpendicularMilledPartShapeIssue.Cast(theIssue)
110 feature_group.FeatureGroupManager.PrintFeatureParameter("actual angle", ToDegrees (aNPMPSIssue.ActualAngle()), "deg")
111 elif mtk.DFMMachining_MilledPartExternalEdgeFilletIssue.CompareType(theIssue):
112 pass
113 elif mtk.DFMMachining_InconsistentRadiusMilledPartFloorFilletIssue.CompareType(theIssue):
114 aIRMPFFIssue = mtk.DFMMachining_InconsistentRadiusMilledPartFloorFilletIssue.Cast(theIssue)
115 feature_group.FeatureGroupManager.PrintFeatureParameter("expected radius", aIRMPFFIssue.ExpectedRadius(), "mm")
116 feature_group.FeatureGroupManager.PrintFeatureParameter("actual radius", aIRMPFFIssue.ActualRadius(), "mm")
117 elif mtk.DFMMachining_NarrowRegionInPocketIssue.CompareType(theIssue):
118 aSMNRDIssue = mtk.DFMMachining_NarrowRegionInPocketIssue.Cast(theIssue)
119 feature_group.FeatureGroupManager.PrintFeatureParameter("expected minimum region size", aSMNRDIssue.ExpectedMinRegionSize(), "mm")
120 feature_group.FeatureGroupManager.PrintFeatureParameter("actual region size", aSMNRDIssue.ActualRegionSize(), "mm")
121 elif mtk.DFMMachining_LargeDifferenceRegionsSizeInPocketIssue.CompareType(theIssue):
122 aLMNRRIssue = mtk.DFMMachining_LargeDifferenceRegionsSizeInPocketIssue.Cast(theIssue)
123 feature_group.FeatureGroupManager.PrintFeatureParameter("expected regions maximum to minimum size ratio", aLMNRRIssue.ExpectedMaxRegionsMaxToMinSizeRatio(), "")
124 feature_group.FeatureGroupManager.PrintFeatureParameter("actual regions maximum to minimum size ratio", aLMNRRIssue.ActualMaxRegionsMaxToMinSizeRatio(), "")
125 elif mtk.DFMMachining_SmallWallThicknessIssue.CompareType(theIssue):
126 aSWTIssue = mtk.DFMMachining_SmallWallThicknessIssue.Cast(theIssue)
127 feature_group.FeatureGroupManager.PrintFeatureParameter("expected min wall thickness", aSWTIssue.ExpectedMinThickness(), "mm")
128 feature_group.FeatureGroupManager.PrintFeatureParameter("actual wall thickness", aSWTIssue.ActualThickness(), "mm")
129 elif mtk.DFMMachining_SmallDistanceBetweenThreadedHoleAndEdgeIssue.CompareType(theIssue):
130 anIssue = mtk.DFMMachining_SmallDistanceBetweenThreadedHoleAndEdgeIssue.Cast(theIssue)
131 feature_group.FeatureGroupManager.PrintFeatureParameter("expected min distance", anIssue.ExpectedMinDistance(), "mm")
132 feature_group.FeatureGroupManager.PrintFeatureParameter("actual distance", anIssue.ActualDistance(), "mm")
133
134 elif mtk.DFMMachining_IrregularTurnedPartOuterDiameterProfileReliefIssue.CompareType(theIssue):
135 anITPODPRIssue = mtk.DFMMachining_IrregularTurnedPartOuterDiameterProfileReliefIssue.Cast(theIssue)
136 feature_group.FeatureGroupManager.PrintFeatureParameter(
137 "expected max incline angle", ToDegrees (anITPODPRIssue.ExpectedMaxFaceInclineAngle()), "deg")
138 feature_group.FeatureGroupManager.PrintFeatureParameter(
139 "actual incline angle", ToDegrees (anITPODPRIssue.ActualFaceInclineAngle()), "deg")
140 elif mtk.DFMMachining_SmallRadiusTurnedPartInternalCornerIssue.CompareType(theIssue):
141 aSRTPICIssue = mtk.DFMMachining_SmallRadiusTurnedPartInternalCornerIssue.Cast(theIssue)
142 feature_group.FeatureGroupManager.PrintFeatureParameter("expected min radius", aSRTPICIssue.ExpectedMinRadius(), "mm")
143 feature_group.FeatureGroupManager.PrintFeatureParameter("actual radius", aSRTPICIssue.ActualRadius(), "mm")
144 elif mtk.DFMMachining_LargeTurnedPartIssue.CompareType(theIssue):
145 aLTPIssue = mtk.DFMMachining_LargeTurnedPartIssue.Cast(theIssue)
146 anExpectedSize = aLMPIssue.ExpectedMaxTurnedPartSize()
147 anActualSize = aLMPIssue.ActualTurnedPartSize()
148 feature_group.FeatureGroupManager.PrintFeatureParameter(
149 "expected max size (LxR)",
150 feature_group.Pair(anExpectedSize.Length(), anExpectedSize.Radius()),
151 "mm")
152 feature_group.FeatureGroupManager.PrintFeatureParameter(
153 "actual size (LxR)",
154 feature_group.Pair(anActualSize.Length(), anActualSize.Radius()),
155 "mm")
156 elif mtk.DFMMachining_LongSlenderTurnedPartIssue.CompareType(theIssue):
157 aLSTPIssue = mtk.DFMMachining_LongSlenderTurnedPartIssue.Cast(theIssue)
158 feature_group.FeatureGroupManager.PrintFeatureParameter("expected min length", aLSTPIssue.ExpectedMaxLength(), "mm")
159 feature_group.FeatureGroupManager.PrintFeatureParameter("actual length", aLSTPIssue.ActualLength(), "mm")
160 feature_group.FeatureGroupManager.PrintFeatureParameter("actual min diameter", aLSTPIssue.ActualMinDiameter(), "mm")
161 elif mtk.DFMMachining_SmallDepthBlindBoredHoleReliefIssue.CompareType(theIssue):
162 aSDBBHRIssue = mtk.DFMMachining_SmallDepthBlindBoredHoleReliefIssue.Cast(theIssue)
163 feature_group.FeatureGroupManager.PrintFeatureParameter(
164 "expected min relief depth", aSDBBHRIssue.ExpectedMinReliefDepth(), "mm")
165 feature_group.FeatureGroupManager.PrintFeatureParameter(
166 "actual relief depth", aSDBBHRIssue.ActualReliefDepth(), "mm")
167 feature_group.FeatureGroupManager.PrintFeatureParameter(
168 "actual diameter", aSDBBHRIssue.ActualDiameter(), "mm")
169 elif mtk.DFMMachining_DeepBoredHoleIssue.CompareType(theIssue):
170 aDBHIssue = mtk.DFMMachining_DeepBoredHoleIssue.Cast(theIssue)
171 feature_group.FeatureGroupManager.PrintFeatureParameter("expected max depth", aDBHIssue.ExpectedMaxDepth(), "mm")
172 feature_group.FeatureGroupManager.PrintFeatureParameter("actual depth", aDBHIssue.ActualDepth(), "mm")
173 feature_group.FeatureGroupManager.PrintFeatureParameter("actual diameter", aDBHIssue.ActualDiameter(), "mm")
174 elif mtk.DFMMachining_SquareEndKeywayIssue.CompareType(theIssue):
175 pass
176 elif mtk.DFMMachining_NonSymmetricalAxialSlotIssue.CompareType(theIssue):
177 pass
178
179def PrintIssues(theIssueList: mtk.MTKBase_FeatureList):
180 aManager = feature_group.FeatureGroupManager()
181
182
183 for anIssue in theIssueList:
184
185 if mtk.DFMMachining_SmallDiameterHoleIssue.CompareType(anIssue):
186 aManager.AddFeature("Small Diameter Hole Issue(s)", "Hole(s)", True, anIssue)
187 elif mtk.DFMMachining_DeepHoleIssue.CompareType(anIssue):
188 aManager.AddFeature("Deep Hole Issue(s)", "Hole(s)", True, anIssue)
189 elif mtk.DFMMachining_NonStandardDiameterHoleIssue.CompareType(anIssue):
190 aManager.AddFeature("Non Standard Diameter Hole Issue(s)", "Hole(s)", True, anIssue)
191 elif mtk.DFMMachining_NonStandardDrillPointAngleBlindHoleIssue.CompareType(anIssue):
192 aManager.AddFeature("Non Standard Drill Point Angle Blind Hole Issue(s)", "Hole(s)", True, anIssue)
193 elif mtk.DFMMachining_FlatBottomHoleIssue.CompareType(anIssue):
194 aManager.AddFeature("Flat Bottom Hole Issue(s)", "", False, anIssue)
195 elif mtk.DFMMachining_NonPerpendicularHoleIssue.CompareType(anIssue):
196 aManager.AddFeature("Non Perpendicular Hole Issue(s)", "", False, anIssue)
197 elif mtk.DFMMachining_IntersectingCavityHoleIssue.CompareType(anIssue):
198 aManager.AddFeature("Intersecting Cavity Hole Issue(s)", "", False, anIssue)
199 elif mtk.DFMMachining_PartialHoleIssue.CompareType(anIssue):
200 aManager.AddFeature("Partial Hole Issue(s)", "Hole(s)", True, anIssue)
201
202 elif mtk.DFMMachining_NonStandardRadiusMilledPartFloorFilletIssue.CompareType(anIssue):
203 aManager.AddFeature("Non Standard Radius Milled Part Floor Fillet Issue(s)", "Floor Fillet(s)", True, anIssue)
204 elif mtk.DFMMachining_DeepPocketIssue.CompareType(anIssue):
205 aManager.AddFeature("Deep Pocket Issue(s)", "Pocket(s)", True, anIssue)
206 elif mtk.DFMMachining_DeepPocketIssue.CompareType(anIssue):
207 aManager.AddFeature("High Boss Issue(s)", "Boss(es)", True, anIssue)
208 elif mtk.DFMMachining_LargeMilledPartIssue.CompareType(anIssue):
209 aManager.AddFeature("Large Milled Part Issue(s)", "Part(s)", True, anIssue)
210 elif mtk.DFMMachining_SmallRadiusMilledPartInternalCornerIssue.CompareType(anIssue):
211 aManager.AddFeature("Small Radius Milled Part Internal Corner Issue(s)", "Internal Corner(s)", True, anIssue)
212 elif mtk.DFMMachining_NonPerpendicularMilledPartShapeIssue.CompareType(anIssue):
213 aManager.AddFeature("Non Perpendicular Milled Part Shape Issue(s)", "Shape(s)", True, anIssue)
214 elif mtk.DFMMachining_MilledPartExternalEdgeFilletIssue.CompareType(anIssue):
215 aManager.AddFeature("Milled Part External Edge Fillet Issue(s)", "", False, anIssue)
216 elif mtk.DFMMachining_InconsistentRadiusMilledPartFloorFilletIssue.CompareType(anIssue):
217 aManager.AddFeature("Inconsistent Radius Milled Part Floor Fillet Issue(s)", "Floor Fillet(s)", True, anIssue)
218 elif mtk.DFMMachining_NarrowRegionInPocketIssue.CompareType(anIssue):
219 aManager.AddFeature("Narrow Region In Pocket Issue(s)", "Region(s)", True, anIssue)
220 elif mtk.DFMMachining_LargeDifferenceRegionsSizeInPocketIssue.CompareType(anIssue):
221 aManager.AddFeature("Large Difference Regions Size In Pocket Issue(s)", "Region Size(s)", True, anIssue)
222 elif mtk.DFMMachining_SmallWallThicknessIssue.CompareType(anIssue):
223 aManager.AddFeature("Small Wall Thickness Issue(s)", "Wall(s)", True, anIssue)
224 elif mtk.DFMMachining_SmallDistanceBetweenThreadedHoleAndEdgeIssue.CompareType(anIssue):
225 aManager.AddFeature("Small Distance Between Threaded Hole And Edge Issue(s)", "Threaded Hole(s)", True, anIssue)
226
227 elif mtk.DFMMachining_IrregularTurnedPartOuterDiameterProfileReliefIssue.CompareType(anIssue):
228 aManager.AddFeature("Irregular Turned Part Outer Diameter Profile Relief Issue(s)", "Outer Diameter Profile Relief(s)", True, anIssue)
229 elif mtk.DFMMachining_SmallRadiusTurnedPartInternalCornerIssue.CompareType(anIssue):
230 aManager.AddFeature("Small Radius Turned Part Internal Corner Issue(s)", "Internal Corner(s)", True, anIssue)
231 elif mtk.DFMMachining_LargeTurnedPartIssue.CompareType(anIssue):
232 aManager.AddFeature("Large Turned Part Issue(s)", "Part(s)", True, anIssue)
233 elif mtk.DFMMachining_LongSlenderTurnedPartIssue.CompareType(anIssue):
234 aManager.AddFeature("Long Slender Turned Part Issue(s)", "Part(s)", True, anIssue)
235 elif mtk.DFMMachining_SmallDepthBlindBoredHoleReliefIssue.CompareType(anIssue):
236 aManager.AddFeature("Small Depth Blind Bored Hole Relief Issue(s)", "Blind Bored Hole(s)", True, anIssue)
237 elif mtk.DFMMachining_DeepBoredHoleIssue.CompareType(anIssue):
238 aManager.AddFeature("Deep Bored Hole Issue(s)", "Bored Hole(s)", True, anIssue)
239 elif mtk.DFMMachining_SquareEndKeywayIssue.CompareType(anIssue):
240 aManager.AddFeature("Square End Keyway Issue(s)", "", False, anIssue)
241 elif mtk.DFMMachining_NonSymmetricalAxialSlotIssue.CompareType(anIssue):
242 aManager.AddFeature("Non Symmetrical Axial Slot Issue(s)", "", False, anIssue)
243
244 aManager.Print ("issues", PrintFeatureParameters)
245
246class PartProcessor(shape_processor.SolidProcessor):
247 def __init__(self, theOperation):
248 super().__init__()
249 self.myOperation = theOperation
250
251 def CombineFeatureLists(self, theFirst: mtk.MTKBase_FeatureList, theSecond: mtk.MTKBase_FeatureList):
252 for anElement in theSecond:
253 if (self.myOperation == mtk.Machining_OT_LatheMilling
254 and mtk.DFMMachining_MillingIssue.CompareType(anElement)
255 and not mtk.DFMMachining_DeepPocketIssue.CompareType(anElement)):
256 continue
257 theFirst.Append(anElement)
258
259 def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
260
261 aData = mtk.Machining_Data()
262 aRecognizer = mtk.Machining_FeatureRecognizer()
263 aRecognizer.Parameters().SetOperation(self.myOperation)
264 aRecognizer.Perform (theSolid, aData)
265
266
267 aDrillingParameters = mtk.DFMMachining_DrillingAnalyzerParameters()
268 aDrillingAnalyzer = mtk.DFMMachining_Analyzer(aDrillingParameters)
269 anIssueList = aDrillingAnalyzer.Perform(theSolid, aData)
270
271
272 aMillingParameters = mtk.DFMMachining_MillingAnalyzerParameters()
273 aMillingAnalyzer = mtk.DFMMachining_Analyzer(aMillingParameters)
274 aMillingIssueList = aMillingAnalyzer.Perform(theSolid, aData)
275
276 self.CombineFeatureLists(anIssueList, aMillingIssueList)
277
278 aTurningIssueList = mtk.MTKBase_FeatureList()
279 if self.myOperation == mtk.Machining_OT_LatheMilling:
280
281 aTurninigParameters = mtk.DFMMachining_TurningAnalyzerParameters()
282 aTurningAnalyzer = mtk.DFMMachining_Analyzer(aTurninigParameters)
283 aTurningIssueList = aTurningAnalyzer.Perform(theSolid, aData)
284
285
286 self.CombineFeatureLists(anIssueList, aTurningIssueList)
287
288 PrintIssues(anIssueList)
289
290def PrintSupportedOperations():
291 print("Supported operations:")
292 print(" milling:\t CNC Machining Milling feature recognition")
293 print(" turning:\t CNC Machining Lathe+Milling feature recognition")
294
295def OperationType(theOperationStr: str):
296 aProcessMap = {
297 "milling": mtk.Machining_OT_Milling,
298 "turning": mtk.Machining_OT_LatheMilling
299 }
300
301 if theOperationStr in aProcessMap:
302 return aProcessMap[theOperationStr]
303 else:
304 return mtk.Machining_OT_Undefined
305
306def main(theSource: str, theOperationStr: str):
307 aKey = license.Value()
308
309 if not mtk.LicenseManager.Activate(aKey):
310 print("Failed to activate Manufacturing Toolkit license.")
311 return 1
312
313 aModel = mtk.ModelData_Model()
314 aReader = mtk.ModelData_ModelReader()
315
316
317 if not aReader.Read(mtk.UTF16String(theSource), aModel):
318 print("Failed to open and convert the file " + theSource)
319 return 1
320
321 print("Model: ", aModel.Name(), "\n", sep="")
322
323 anOperation = OperationType(theOperationStr)
324 if anOperation == mtk.Machining_OT_Undefined:
325 print("Unsupported operation - " , theOperationStr)
326 print("Please use one of the following.")
327 PrintSupportedOperations()
328 return 1
329
330
331 aPartProcessor = PartProcessor(anOperation)
332 aVisitor = mtk.ModelData_ModelElementUniqueVisitor(aPartProcessor)
333 aModel.Accept(aVisitor)
334
335 return 0
336
337if __name__ == "__main__":
338 if len(sys.argv) != 3:
339 print("Usage: <input_file> <operation>, where:")
340 print(" <input_file> is a name of the file to be read")
341 print(" <operation> is a name of desired machining operation")
342 PrintSupportedOperations()
343 sys.exit()
344
345 aSource = os.path.abspath(sys.argv[1])
346 anOperation = sys.argv[2]
347
348 sys.exit(main(aSource, anOperation))