Implementation of classes that help to group and print information about found features and their parameters in Manufacturing Toolkit examples.
Overview
This helper is used to store, group and print found features after using one or more MTK analysis tools.
Implementation
FeatureGroup
class is used to store and sort MTK features with the same given name. Features are sorted using MTKBase_FeatureComparator class that based on comparison of features' type and parameters.
class FeatureGroup:
def __init__(self, theName: str, theSubgroupName: str, theHasParameters: bool):
self.myName = theName
self.mySubgroupName = theSubgroupName
self.myHasParameters = theHasParameters
self.myFeatureSubgroups = FeatureGroupManager.OrderedFeatureList()
def FeatureCount(self):
aCount = 0
for i in range(self.myFeatureSubgroups.Size()):
aCount += self.myFeatureSubgroups.GetFeatureCount(i)
return aCount
FeatureGroupComparator
class is used to sort FeatureGroup
entities before printing them into console. Sorting is based on group names and MTKBase_FeatureComparator class.
@staticmethod
def __compare(theA: FeatureGroup, theB: FeatureGroup):
anAName = theA.myName
aBName = theB.myName
if anAName == aBName:
return 0
anAFeatureSubgroups = theA.myFeatureSubgroups
aBFeatureSubgroups = theB.myFeatureSubgroups
if (not anAFeatureSubgroups) or (not aBFeatureSubgroups):
if anAName < aBName:
return -1
else:
return 1
anAFeature = anAFeatureSubgroups.GetFeature(0)
aBFeature = aBFeatureSubgroups.GetFeature(0)
return CompareFeatures(anAFeature, aBFeature)
FeatureGroupManager
class is used to create, store and update FeatureGroup
entities and printing them into a console. AddFeature
method is used to add MTKBase_Feature with given name to one of the existing FeatureGroup
entities or create a new one.
def AddFeature(self, theGroupName: str, theSubgroupName: str, theHasParameters: bool, theFeature: mtk.MTKBase_Feature):
#find or create
aRes = -1
for i in range(len(self.__myGroups)):
aGroup = self.__myGroups[i]
if aGroup.myName == theGroupName:
aRes = i
break
if aRes == -1:
self.__myGroups.append(self.FeatureGroup(theGroupName, theSubgroupName, theHasParameters))
aRes = len(self.__myGroups) - 1
#update
aGroup = self.__myGroups[aRes]
aSubgroups = aGroup.myFeatureSubgroups
aSubgroups.Append(theFeature)
Print
method is used to print with specific formatting all stored information. FeatureGroup
entities are additionally sorted before printing into console. User-defined function thePrintFeatureParameters
is used to print parameters of each stored MTKBase_Feature.
def Print(self, theFeatureType: str, thePrintFeatureParameters):
self.__myGroups.sort(key=cmp_to_key(self.__compare))
aTotalCount = 0
for i in self.__myGroups:
aFeatureCount = i.FeatureCount()
aTotalCount += aFeatureCount
print(" ", i.myName, ": ", aFeatureCount, sep="")
if not i.myHasParameters:
continue
aSubgroupName = i.mySubgroupName
for j in range(i.myFeatureSubgroups.Size()):
print(" ", i.myFeatureSubgroups.GetFeatureCount(j), " ", aSubgroupName, " with", sep="")
thePrintFeatureParameters(i.myFeatureSubgroups.GetFeature(j))
print("\n Total ", theFeatureType, ": ", aTotalCount, "\n", sep="")
PrintFeatureParameter
method is used as a help method to print MTKBase_Feature parameters with specific formatting.
@staticmethod
def PrintFeatureParameter(theName: str, theValue, theUnits: str):
print(" ", theName, ": ", theValue, " ", theUnits, sep = "")
Files