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 for aModule in sys.modules:
33 for aName, anObj in inspect.getmembers(sys.modules[aModule], inspect.isclass):
34 if issubclass(anObj, ModelHighAPI.ModelHighAPI_Interface) and hasattr(anObj, "ID") and anObj.dump != ModelHighAPI.ModelHighAPI_Interface.dump:
35 self.myFeatures[anObj.ID()] = anObj
37 ## Create wrapper for a given feature and dump it
38 def dumpFeature(self, theFeature, theForce):
39 aFeatureKind = theFeature.getKind()
40 if aFeatureKind in self.myFeatures:
41 # Dump only feature created by user (in history).
42 # For all other features, just keep their name.
43 if theForce or theFeature.isInHistory():
44 self.myFeatures[aFeatureKind](theFeature).dump(self)
49 # Probably the feature is a constraint, try to dump it with SketchAPI_Constraint.
50 # In case of theFeature is not a constraint, it will not be dumped.
51 self.myFeatures[SketchAPI.SketchAPI_Constraint.ID()](theFeature).dump(self)
53 ## Dump all parameters
54 def dumpParameter(self, theFeature):
55 aFeatureKind = theFeature.getKind()
56 if aFeatureKind == "Parameter" and aFeatureKind in self.myFeatures:
57 self.myFeatures[aFeatureKind](theFeature).dump(self)
59 ## Return getter for specified attribute
60 def attributeGetter(self, theFeature, theAttrName):
61 aFeatureKind = theFeature.getKind()
62 if aFeatureKind in self.myFeatures:
63 return self.myFeatures[aFeatureKind](theFeature).attributeGetter(theAttrName)
67 dumper = DumpAssistant