1 """Package for dumping purposes.
14 instance.__call__ = lambda: instance
18 ## @ingroup CPPHighAPI
19 # Collect information about features that may be dumped and stores the model as a Python script
21 class DumpAssistant(ModelHighAPI.ModelHighAPI_Dumper):
25 ModelHighAPI.ModelHighAPI_Dumper.__init__(self)
26 ModelHighAPI.ModelHighAPI_Dumper.setInstance(self)
27 self.collectFeatures()
29 ## Collect feature wrappers, which allow dumping (have method dump)
30 def collectFeatures(self):
32 self.myWrapperNames = {}
33 for aModule in sys.modules:
34 for aName, anObj in inspect.getmembers(sys.modules[aModule], inspect.isclass):
35 if issubclass(anObj, ModelHighAPI.ModelHighAPI_Interface) and hasattr(anObj, "ID") and anObj.dump != ModelHighAPI.ModelHighAPI_Interface.dump:
36 self.myFeatures[anObj.ID()] = anObj
37 self.myWrapperNames[anObj.ID()] = aName
39 ## Create wrapper for a given feature and dump it
40 def dumpFeature(self, theFeature, theForce):
41 aFeatureKind = theFeature.getKind()
42 if aFeatureKind in self.myFeatures:
43 # Dump only feature created by user (in history).
44 # For all other features, just keep their name.
45 if theForce or theFeature.isInHistory():
46 self.myFeatures[aFeatureKind](theFeature).dump(self)
51 # Probably the feature is a constraint, try to dump it with SketchAPI_Constraint.
52 # In case of theFeature is not a constraint, it will not be dumped.
53 self.myFeatures[SketchAPI.SketchAPI_Constraint.ID()](theFeature).dump(self)
55 ## Dump all parameters
56 def dumpParameter(self, theFeature):
57 aFeatureKind = theFeature.getKind()
58 if aFeatureKind == "Parameter" and aFeatureKind in self.myFeatures:
59 self.myFeatures[aFeatureKind](theFeature).dump(self)
61 ## Return getter for specified attribute
62 def attributeGetter(self, theFeature, theAttrName):
63 aFeatureKind = theFeature.getKind()
64 if aFeatureKind in self.myFeatures:
65 return self.myFeatures[aFeatureKind](theFeature).attributeGetter(theAttrName)
68 ## Return name of wrapper feature
69 def featureWrapper(self, theFeature):
70 aFeatureKind = theFeature.getKind()
71 if aFeatureKind in self.myWrapperNames:
72 return self.myWrapperNames[aFeatureKind]
76 dumper = DumpAssistant