// directors
%feature("director") ModelHighAPI_Dumper;
+// renamed methods
+%rename(__print__) ModelHighAPI_Dumper::operator<<;
+
// shared pointers
%shared_ptr(ModelHighAPI_Interface)
%shared_ptr(ModelHighAPI_Folder)
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity)
{
- *myDumpStorage << "\n### Create "<< theEntity->getKind() << "\n";
*myDumpStorage << name(theEntity);
if (!myNames[theEntity].myIsDumped) {
const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList)
{
static const int aThreshold = 2;
- static bool aDumpAsIs = false;
+ static int aNbSpaces = 0;
// if number of elements in the list if greater than a threshold,
// dump it in a separate line with specific name
- if (aDumpAsIs || theAttrSelList->size() <= aThreshold) {
+ if (aNbSpaces > 0 || theAttrSelList->size() <= aThreshold) {
*myDumpStorage << "[";
GeomShapePtr aShape;
if(isAdded) {
*myDumpStorage << ", ";
+ // print each attribute on separate line with the appropriate shift
+ if (aNbSpaces > 0) {
+ std::string aSpaces(aNbSpaces + 1, ' ');
+ *myDumpStorage << "\n" << aSpaces;
+ }
} else {
isAdded = true;
}
}
// reserve dumped buffer and store list "as is"
myDumpStorage->reserveBuffer();
- aDumpAsIs = true;
+ aNbSpaces = (int)aListName.size() + 3;
*this << aListName << " = " << theAttrSelList << "\n";
- aDumpAsIs = false;
+ aNbSpaces = 0;
// append reserved data to the end of the current buffer
myDumpStorage->restoreReservedBuffer();
*myDumpStorage << aListName;
return *this;
}
+void ModelHighAPI_Dumper::newline()
+{
+ *this << std::endl;
+}
+
/// Dump std::endl
ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&))
ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&));
+ /// Print std::endl from Python
+ MODELHIGHAPI_EXPORT void newline();
+
/// Dump GeomAPI_Pnt in the following form:
/// "GeomAPI_Pnt(X, Y, Z)"
MODELHIGHAPI_EXPORT
## Create wrapper for a given feature and dump it
def dumpFeature(self, theFeature, theForce):
+ aDumper = None
aFeatureKind = theFeature.getKind()
if aFeatureKind in self.myFeatures:
# Dump only feature created by user (in history).
# Also dump Export and RemoveResults features (hard-coded here in order not to change the data model).
# For all other features, just keep their name.
if theForce or theFeature.isInHistory() or aFeatureKind=="Export" or aFeatureKind=="RemoveResults":
- self.myFeatures[aFeatureKind](theFeature).dump(self)
+ aDumper = self.myFeatures[aFeatureKind](theFeature)
+ # Dump comment for the operation before the dumping of the feature to improve the readability of a script.
+ self.__print__("\n### Create " + theFeature.getKind())
+ self.newline()
else:
self.name(theFeature)
self.clearNotDumped()
else:
# Probably the feature is a constraint, try to dump it with SketchAPI_Constraint.
# In case of theFeature is not a constraint, it will not be dumped.
- self.myFeatures[SketchAPI.SketchAPI_Constraint.ID()](theFeature).dump(self)
+ self.name(theFeature, False, True, True)
+ aDumper = self.myFeatures[SketchAPI.SketchAPI_Constraint.ID()](theFeature)
+ if aDumper is not None:
+ aDumper.dump(self)
## Create wrapper for a folder and dump it
def dumpFolder(self, theFolder):
return;
const std::string& aSketchName = theDumper.parentName(aBase);
- theDumper.name(aBase, false, true, true);
theDumper << aSketchName << "." << aSetter << "(";
bool isFirstAttr = true;
FeaturePtr aBase = feature();
const std::string& aSketchName = theDumper.parentName(aBase);
- //theDumper << aBase << " = " << aSketchName << "." << "setAngle(";
- theDumper.name(aBase, false, true, true);
theDumper << aSketchName << "." << "setAngle(";
bool isFirstAttr = true;