Hide menu
Loading...
Searching...
No Matches
molding/dfm_analyzer/dfm_analyzer.py

Refer to the Molding DFM Analyzer Example

feature_group.py

1# $Id$
2#
3# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
4# Copyright (C) 2014-2025, CADEX. All rights reserved.
5#
6# This file is part of the Manufacturing Toolkit software.
7#
8# You may use this file under the terms of the BSD license as follows:
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions are met:
12# * Redistributions of source code must retain the above copyright notice,
13# this list of conditions and the following disclaimer.
14# * Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29
30from functools import cmp_to_key
31
32import manufacturingtoolkit.CadExMTK as mtk
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 #find or create
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 #update
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)

shape_processor.py

1# $Id$
2#
3# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
4# Copyright (C) 2014-2025, CADEX. All rights reserved.
5#
6# This file is part of the Manufacturing Toolkit software.
7#
8# You may use this file under the terms of the BSD license as follows:
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions are met:
12# * Redistributions of source code must retain the above copyright notice,
13# this list of conditions and the following disclaimer.
14# * Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29
30from abc import abstractmethod
31
32import manufacturingtoolkit.CadExMTK as mtk
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

dfm_analyzer.py

1# $Id$
2#
3# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
4# Copyright (C) 2014-2025, CADEX. All rights reserved.
5#
6# This file is part of the Manufacturing Toolkit software.
7#
8# You may use this file under the terms of the BSD license as follows:
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions are met:
12# * Redistributions of source code must retain the above copyright notice,
13# this list of conditions and the following disclaimer.
14# * Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29
30import math
31import os
32import sys
33
34from pathlib import Path
35
36import manufacturingtoolkit.CadExMTK as mtk
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 if mtk.DFMMolding_IrregularCoreDepthScrewBossIssue.CompareType(theIssue):
51 aICDSBIssue = mtk.DFMMolding_IrregularCoreDepthScrewBossIssue.Cast(theIssue)
52 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual height", aICDSBIssue.ActualHeight(), "mm")
53 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual core depth", aICDSBIssue.ActualCoreDepth(), "mm")
54 elif mtk.DFMMolding_IrregularCoreDiameterScrewBossIssue.CompareType(theIssue):
55 aICDSBIssue = mtk.DFMMolding_IrregularCoreDiameterScrewBossIssue.Cast(theIssue)
56 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min core diameter", aICDSBIssue.ExpectedMinCoreDiameter(), "mm")
57 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected max core diameter", aICDSBIssue.ExpectedMaxCoreDiameter(), "mm")
58 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual core diameter", aICDSBIssue.ActualCoreDiameter(), "mm")
59 elif mtk.DFMMolding_IrregularWallThicknessScrewBossIssue.CompareType(theIssue):
60 aIWTSBIssue = mtk.DFMMolding_IrregularWallThicknessScrewBossIssue.Cast(theIssue)
61 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected max thickness", aIWTSBIssue.ExpectedMaxThickness(), "mm")
62 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min thickness", aIWTSBIssue.ExpectedMinThickness(), "mm")
63 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual thickness", aIWTSBIssue.ActualThickness(), "mm")
64 elif mtk.DFMMolding_HighScrewBossIssue.CompareType(theIssue):
65 aHSBIssue = mtk.DFMMolding_HighScrewBossIssue.Cast(theIssue)
66 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected max height", aHSBIssue.ExpectedMaxHeight(), "mm")
67 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual height", aHSBIssue.ActualHeight(), "mm")
68 elif mtk.DFMMolding_SmallBaseRadiusRibIssue.CompareType(theIssue):
69 aSBRRIssue = mtk.DFMMolding_SmallBaseRadiusRibIssue.Cast(theIssue)
70 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min base radius", aSBRRIssue.ExpectedMinBaseRadius(), "mm")
71 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual base radius", aSBRRIssue.ActualBaseRadius(), "mm")
72 elif mtk.DFMMolding_SmallBaseRadiusScrewBossIssue.CompareType(theIssue):
73 aSBRSBIssue = mtk.DFMMolding_SmallBaseRadiusScrewBossIssue.Cast(theIssue)
74 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min base radius", aSBRSBIssue.ExpectedMinBaseRadius(), "mm")
75 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual base radius", aSBRSBIssue.ActualBaseRadius(), "mm")
76 elif mtk.DFMMolding_SmallDraftAngleScrewBossIssue.CompareType(theIssue):
77 aSDASBIssue = mtk.DFMMolding_SmallDraftAngleScrewBossIssue.Cast(theIssue)
78 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min draft angle", ToDegrees (aSDASBIssue.ExpectedMinDraftAngle()), "deg")
79 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual draft angle", ToDegrees (aSDASBIssue.ActualDraftAngle()), "deg")
80 elif mtk.DFMMolding_SmallHoleBaseRadiusScrewBossIssue.CompareType(theIssue):
81 aSHBRSBIssue = mtk.DFMMolding_SmallHoleBaseRadiusScrewBossIssue.Cast(theIssue)
82 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min hole base radius", aSHBRSBIssue.ExpectedMinHoleBaseRadius(), "mm")
83 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual hole base radius", aSHBRSBIssue.ActualHoleBaseRadius(), "mm")
84 elif mtk.DFMMolding_NonChamferedScrewBossIssue.CompareType(theIssue):
85 #no parameters
86 pass
87 elif mtk.DFMMolding_HighRibIssue.CompareType(theIssue):
88 aHRIssue = mtk.DFMMolding_HighRibIssue.Cast(theIssue)
89 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected max height", aHRIssue.ExpectedMaxHeight(), "mm")
90 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual height", aHRIssue.ActualHeight(), "mm")
91 elif mtk.DFMMolding_IrregularThicknessRibIssue.CompareType(theIssue):
92 aITRIssue = mtk.DFMMolding_IrregularThicknessRibIssue.Cast(theIssue)
93 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min thickness", aITRIssue.ExpectedMinThickness(), "mm")
94 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected max thickness", aITRIssue.ExpectedMaxThickness(), "mm")
95 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual thickness", aITRIssue.ActualThickness(), "mm")
96 elif mtk.DFMMolding_SmallDraftAngleRibIssue.CompareType(theIssue):
97 aSDARIssue = mtk.DFMMolding_SmallDraftAngleRibIssue.Cast(theIssue)
98 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min draft angle", ToDegrees (aSDARIssue.ExpectedMinDraftAngle()), "deg")
99 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual draft angle", ToDegrees (aSDARIssue.ActualDraftAngle()), "deg")
100 elif mtk.DFMMolding_SmallDistanceBetweenRibsIssue.CompareType(theIssue):
101 aSDBRIssue = mtk.DFMMolding_SmallDistanceBetweenRibsIssue.Cast(theIssue)
102 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min distance", aSDBRIssue.ExpectedMinDistanceBetweenRibs(), "mm")
103 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual distance", aSDBRIssue.ActualDistanceBetweenRibs(), "mm")
104
105 elif mtk.DFMMolding_IrregularWallThicknessIssue.CompareType(theIssue):
106 aIWTIIssue = mtk.DFMMolding_IrregularWallThicknessIssue.Cast(theIssue)
107 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected max thickness", aIWTIIssue.ExpectedMaxThickness(), "mm")
108 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min thickness", aIWTIIssue.ExpectedMinThickness(), "mm")
109 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual thickness", aIWTIIssue.ActualThickness(), "mm")
110 elif mtk.DFMMolding_LargeWallThicknessIssue.CompareType(theIssue):
111 aLWTIIssue = mtk.DFMMolding_LargeWallThicknessIssue.Cast(theIssue)
112 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected max thickness", aLWTIIssue.ExpectedMaxThickness(), "mm")
113 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual thickness", aLWTIIssue.ActualThickness(), "mm")
114 elif mtk.DFMMolding_SmallWallThicknessIssue.CompareType(theIssue):
115 aSWTIIssue = mtk.DFMMolding_SmallWallThicknessIssue.Cast(theIssue)
116 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min thickness", aSWTIIssue.ExpectedMinThickness(), "mm")
117 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual thickness", aSWTIIssue.ActualThickness(), "mm")
118 elif mtk.DFMMolding_SmallDraftAngleWallIssue.CompareType(theIssue):
119 aSDAWIssue = mtk.DFMMolding_SmallDraftAngleWallIssue.Cast(theIssue)
120 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min draft angle", ToDegrees (aSDAWIssue.ExpectedMinDraftAngle()), "deg")
121 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual draft angle", ToDegrees (aSDAWIssue.ActualDraftAngle()), "deg")
122 elif mtk.DFMMolding_SmallDistanceBetweenBossesIssue.CompareType(theIssue):
123 aSDBBIssue = mtk.DFMMolding_SmallDistanceBetweenBossesIssue.Cast(theIssue)
124 feature_group.FeatureGroupManager.PrintFeatureParameter ("expected min distance", aSDBBIssue.ExpectedMinDistanceBetweenBosses(), "mm")
125 feature_group.FeatureGroupManager.PrintFeatureParameter ("actual distance", aSDBBIssue.ActualDistanceBetweenBosses(), "mm")
126
127def PrintIssues(theIssueList: mtk.MTKBase_FeatureList):
128 aManager = feature_group.FeatureGroupManager()
129
130 #group by parameters to provide more compact information about features
131 for anIssue in theIssueList:
132 if mtk.DFMMolding_IrregularCoreDepthScrewBossIssue.CompareType(anIssue):
133 aManager.AddFeature("Irregular Core Depth Screw Boss Issue(s)", "Screw Boss(es)", True, anIssue)
134 elif mtk.DFMMolding_IrregularCoreDiameterScrewBossIssue.CompareType(anIssue):
135 aManager.AddFeature("Irregular Core Diameter Screw Boss Issue(s)", "Screw Boss(es)", True, anIssue)
136 elif mtk.DFMMolding_IrregularWallThicknessScrewBossIssue.CompareType(anIssue):
137 aManager.AddFeature("Irregular Wall Thickness Screw Boss Issue(s)", "Screw Boss(es)", True, anIssue)
138 elif mtk.DFMMolding_HighScrewBossIssue.CompareType(anIssue):
139 aManager.AddFeature("High Screw Boss Issue(s)", "Screw Boss(es)", True, anIssue)
140 elif mtk.DFMMolding_SmallBaseRadiusScrewBossIssue.CompareType(anIssue):
141 aManager.AddFeature("Small Base Radius Screw Boss Issue(s)", "Screw Boss(es)", True, anIssue)
142 elif mtk.DFMMolding_SmallDraftAngleScrewBossIssue.CompareType(anIssue):
143 aManager.AddFeature("Small Draft Angle Screw Boss Issue(s)", "Screw Boss(es)", True, anIssue)
144 elif mtk.DFMMolding_SmallHoleBaseRadiusScrewBossIssue.CompareType(anIssue):
145 aManager.AddFeature("Small Hole Base Radius Screw Boss Issue(s)", "Screw Boss(es)", True, anIssue)
146 elif mtk.DFMMolding_NonChamferedScrewBossIssue.CompareType(anIssue):
147 aManager.AddFeature("Non Chamfered Screw Boss Issue(s)", "Screw Boss(es)", False, anIssue)
148 elif mtk.DFMMolding_HighRibIssue.CompareType(anIssue):
149 aManager.AddFeature("High Rib Issue(s)", "Rib(s)", True, anIssue)
150 elif mtk.DFMMolding_IrregularThicknessRibIssue.CompareType(anIssue):
151 aManager.AddFeature("Irregular Thickness Rib Issue(s)", "Rib(s)", True, anIssue)
152 elif mtk.DFMMolding_SmallBaseRadiusRibIssue.CompareType(anIssue):
153 aManager.AddFeature("Small Base Radius Rib Issue(s)", "Rib(s)", True, anIssue)
154 elif mtk.DFMMolding_SmallDraftAngleRibIssue.CompareType(anIssue):
155 aManager.AddFeature("Small Draft Angle Rib Issue(s)", "Rib(s)", True, anIssue)
156 elif mtk.DFMMolding_SmallDistanceBetweenRibsIssue.CompareType(anIssue):
157 aManager.AddFeature("Small Distance Between Ribs Issue(s)", "Rib(s)", True, anIssue)
158 elif mtk.DFMMolding_IrregularWallThicknessIssue.CompareType(anIssue):
159 aManager.AddFeature("Irregular Wall Thickness Issue(s)", "Wall(s)", True, anIssue)
160 elif mtk.DFMMolding_LargeWallThicknessIssue.CompareType(anIssue):
161 aManager.AddFeature("Large Wall Thickness Issue(s)", "Wall(s)", True, anIssue)
162 elif mtk.DFMMolding_SmallWallThicknessIssue.CompareType(anIssue):
163 aManager.AddFeature("Small Wall Thickness Issue(s)", "Wall(s)", True, anIssue)
164 elif mtk.DFMMolding_SmallDraftAngleWallIssue.CompareType(anIssue):
165 aManager.AddFeature("Small Draft Angle Wall Thickness Issue(s)", "Wall(s)", True, anIssue)
166 elif mtk.DFMMolding_SmallDistanceBetweenBossesIssue.CompareType(anIssue):
167 aManager.AddFeature("Small Distance Between Bosses Issue(s)", "Boss(es)", True, anIssue)
168
169 aManager.Print ("issues", PrintFeatureParameters)
170
171class PartProcessor(shape_processor.SolidProcessor):
172 def __init__(self):
173 super().__init__()
174
175 def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
176 # Set up recognizer
177 aRecognizerParameters = mtk.Molding_FeatureRecognizerParameters()
178 aRecognizerParameters.SetMaxRibThickness (30.0)
179 aRecognizerParameters.SetMaxRibDraftAngle (0.2)
180 aRecognizerParameters.SetMaxRibTaperAngle (0.1)
181
182 aRecognizer = mtk.Molding_FeatureRecognizer(aRecognizerParameters)
183
184 # Set up analyzer
185 anAnalyzer = mtk.Molding_Analyzer()
186 anAnalyzer.AddTool(aRecognizer)
187
188 # Fill molding data
189 aData = anAnalyzer.Perform (theSolid)
190
191 # Run dfm analyzer for found features
192 aParameters = mtk.DFMMolding_AnalyzerParameters()
193 aDFMAnalyzer = mtk.DFMMolding_Analyzer(aParameters)
194 anIssueList = aDFMAnalyzer.Perform(aData)
195
196 PrintIssues(anIssueList)
197
198def main(theSource: str):
199 aKey = license.Value()
200
201 if not mtk.LicenseManager.Activate(aKey):
202 print("Failed to activate Manufacturing Toolkit license.")
203 return 1
204 aModel = mtk.ModelData_Model()
205 aReader = mtk.ModelData_ModelReader()
206
207 # Reading the file
208 if not aReader.Read(mtk.UTF16String(theSource), aModel):
209 print("Failed to open and convert the file " + theSource)
210 return 1
211
212 print("Model: ", aModel.Name(), "\n", sep="")
213
214 # Processing
215 aPartProcessor = PartProcessor()
216 aVisitor = mtk.ModelData_ModelElementUniqueVisitor(aPartProcessor)
217 aModel.Accept(aVisitor)
218
219 return 0
220
221if __name__ == "__main__":
222 if len(sys.argv) != 2:
223 print("Usage: <input_file>, where:")
224 print(" <input_file> is a name of the file to be read")
225 sys.exit()
226
227 aSource = os.path.abspath(sys.argv[1])
228
229 sys.exit(main(aSource))