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