++gCompositeStackDepth;
// dump composite itself
if (!isDumped(theComposite) || isForce)
- dumpFeature(theComposite, isForce);
+ dumpFeature(FeaturePtr(theComposite), isForce);
// sub-part is processed independently, because it provides separate document
if (theComposite->getKind() == PartSetPlugin_Part::ID()) {
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr)
{
FeaturePtr anOwner = ModelAPI_Feature::feature(theAttr->owner());
- myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, theAttr->id()) << "()";
+
+ std::string aWrapperPrefix, aWrapperSuffix;
+ // Check the attribute belongs to copied (in multi-translation or multi-rotation) feature.
+ // In this case we need to cast explicitly feature to appropriate type.
+ AttributeBooleanPtr isCopy = anOwner->boolean("Copy");
+ if (isCopy.get() && isCopy->value()) {
+ aWrapperPrefix = featureWrapper(anOwner) + "(";
+ aWrapperSuffix = ")";
+ importModule("SketchAPI");
+ }
+
+ myDumpBuffer << aWrapperPrefix << name(anOwner) << aWrapperSuffix
+ << "." << attributeGetter(anOwner, theAttr->id()) << "()";
return *this;
}
virtual std::string attributeGetter(const FeaturePtr& theFeature,
const std::string& theAttrName) const = 0;
+ /// Return name of wrapper feature
+ virtual std::string featureWrapper(const FeaturePtr& theFeature) const = 0;
+
/// Save all dumps into specified file
MODELHIGHAPI_EXPORT
bool exportTo(const std::string& theFileName);
## Collect feature wrappers, which allow dumping (have method dump)
def collectFeatures(self):
self.myFeatures = {}
+ self.myWrapperNames = {}
for aModule in sys.modules:
for aName, anObj in inspect.getmembers(sys.modules[aModule], inspect.isclass):
if issubclass(anObj, ModelHighAPI.ModelHighAPI_Interface) and hasattr(anObj, "ID") and anObj.dump != ModelHighAPI.ModelHighAPI_Interface.dump:
self.myFeatures[anObj.ID()] = anObj
+ self.myWrapperNames[anObj.ID()] = aName
## Create wrapper for a given feature and dump it
def dumpFeature(self, theFeature, theForce):
return self.myFeatures[aFeatureKind](theFeature).attributeGetter(theAttrName)
return std_string()
+ ## Return name of wrapper feature
+ def featureWrapper(self, theFeature):
+ aFeatureKind = theFeature.getKind()
+ if aFeatureKind in self.myWrapperNames:
+ return self.myWrapperNames[aFeatureKind]
+ return std_string()
+
# Instance of dumper
dumper = DumpAssistant
\ No newline at end of file
%{
#include "SketchAPI_swig.h"
+ #include "ModelHighAPI_swig.h"
+
+ // fix for SWIG v2.0.4
+ #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj))
%}
%include "doxyhelp.i"
// import other modules
+%import "ModelAPI.i"
%import "ModelHighAPI.i"
// to avoid error on this
%shared_ptr(SketchAPI_Rotation)
%shared_ptr(SketchAPI_Translation)
+// std::list -> []
+%template(InterfaceList) std::list<std::shared_ptr<ModelHighAPI_Interface> >;
+
+%typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
+ std::shared_ptr<ModelAPI_Feature> * temp_feature;
+ std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+ int newmem = 0;
+ if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (temp_feature) {
+ $1 = 1;
+ } else {
+ $1 = 0;
+ }
+ } else
+ if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (temp_interface) {
+ $1 = 1;
+ } else {
+ $1 = 0;
+ }
+ } else
+ $1 = 0;
+}
+
+%typemap(in) const std::shared_ptr<ModelAPI_Feature> & (std::shared_ptr<ModelAPI_Feature> temp) {
+ std::shared_ptr<ModelAPI_Feature> * temp_feature;
+ std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+ int newmem = 0;
+ if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (!temp_feature) {
+ PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface.");
+ return NULL;
+ }
+ temp = (*temp_feature);
+ if (newmem & SWIG_CAST_NEW_MEMORY) {
+ delete temp_feature;
+ }
+ $1 = &temp;
+ } else
+ if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (!temp_interface) {
+ PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface.");
+ return NULL;
+ }
+ temp = (*temp_interface)->feature();
+ if (newmem & SWIG_CAST_NEW_MEMORY) {
+ delete temp_interface;
+ }
+ $1 = &temp;
+ } else
+ if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
+ } else {
+ PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Interface.");
+ return NULL;
+ }
+}
+
%typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) {
std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
std::shared_ptr<ModelAPI_Object> * temp_object;
//--------------------------------------------------------------------------------------
#include "SketchAPI_Mirror.h"
+#include <SketchAPI_SketchEntity.h>
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Selection.h>
}
+std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Mirror::mirrored() const
+{
+ std::list<ObjectPtr> aList = mirroredObjects()->list();
+ std::list<FeaturePtr> anIntermediate;
+ std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ anIntermediate.push_back(aFeature);
+ }
+ return SketchAPI_SketchEntity::wrap(anIntermediate);
+}
+
//--------------------------------------------------------------------------------------
void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
AttributeRefListPtr aMirrorObjects = mirrorList();
theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
<< aMirrorObjects << ")" << std::endl;
+
+ // Dump variables for a list of mirrored features
+ theDumper << "[";
+ std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = mirrored();
+ std::list<std::shared_ptr<ModelHighAPI_Interface> >::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ if (anIt != aList.begin())
+ theDumper << ", ";
+ theDumper << theDumper.name((*anIt)->feature(), false);
+ }
+ theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
}
mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */
)
+ /// List of mirrored objects
+ SKETCHAPI_EXPORT
+ std::list<std::shared_ptr<ModelHighAPI_Interface> > mirrored() const;
+
/// Dump wrapped feature
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};
//--------------------------------------------------------------------------------------
#include "SketchAPI_Rotation.h"
+#include <SketchAPI_SketchEntity.h>
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_SketchEntity.h>
//--------------------------------------------------------------------------------------
SketchAPI_Rotation::SketchAPI_Rotation(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
}
+std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Rotation::rotated() const
+{
+ std::list<ObjectPtr> aList = rotatedObjects()->list();
+ // remove all initial features
+ std::list<FeaturePtr> anIntermediate;
+ std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+ if (isCopy.get() && isCopy->value())
+ anIntermediate.push_back(aFeature);
+ }
+ return SketchAPI_SketchEntity::wrap(anIntermediate);
+}
+
//--------------------------------------------------------------------------------------
void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
if (isFullValue)
theDumper << ", " << isFullValue;
theDumper << ")" << std::endl;
+
+ // Dump variables for a list of rotated features
+ theDumper << "[";
+ std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = rotated();
+ std::list<std::shared_ptr<ModelHighAPI_Interface> >::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ if (anIt != aList.begin())
+ theDumper << ", ";
+ theDumper << theDumper.name((*anIt)->feature(), false);
+ }
+ theDumper << "] = " << theDumper.name(aBase) << ".rotated()" << std::endl;
}
rotatedObjects, SketchPlugin_MultiRotation::ENTITY_B(), ModelAPI_AttributeRefList, /** Rotated objects */
)
+ /// List of rotated objects
+ SKETCHAPI_EXPORT
+ std::list<std::shared_ptr<ModelHighAPI_Interface> > rotated() const;
+
/// Dump wrapped feature
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};
//--------------------------------------------------------------------------------------
#include "SketchAPI_SketchEntity.h"
+#include <SketchAPI_Arc.h>
+#include <SketchAPI_Circle.h>
+#include <SketchAPI_IntersectionPoint.h>
+#include <SketchAPI_Line.h>
+#include <SketchAPI_Point.h>
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_IntersectionPoint.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
//--------------------------------------------------------------------------------------
SketchAPI_SketchEntity::SketchAPI_SketchEntity(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
AttributeBooleanPtr isCopy = feature()->boolean(SketchPlugin_SketchEntity::COPY_ID());
return isCopy.get() && isCopy->value();
}
+
+std::list<std::shared_ptr<ModelHighAPI_Interface> >
+SketchAPI_SketchEntity::wrap(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures)
+{
+ std::list<std::shared_ptr<ModelHighAPI_Interface> > aResult;
+ std::list<std::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = theFeatures.begin();
+ for (; anIt != theFeatures.end(); ++anIt) {
+ if ((*anIt)->getKind() == SketchPlugin_Line::ID())
+ aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Line(*anIt)));
+ else if ((*anIt)->getKind() == SketchPlugin_Arc::ID())
+ aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Arc(*anIt)));
+ else if ((*anIt)->getKind() == SketchPlugin_Circle::ID())
+ aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Circle(*anIt)));
+ else if ((*anIt)->getKind() == SketchPlugin_Point::ID())
+ aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Point(*anIt)));
+ else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID())
+ aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_IntersectionPoint(*anIt)));
+ }
+ return aResult;
+}
#include <ModelHighAPI_Interface.h>
#include <ModelHighAPI_Macro.h>
+
+class ModelAPI_Feature;
//--------------------------------------------------------------------------------------
/**\class SketchAPI_SketchEntity
* \ingroup CPPHighAPI
/// Dump wrapped feature
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+ /// Convert list of features to list of appropriate wrappers
+ SKETCHAPI_EXPORT
+ static std::list<std::shared_ptr<ModelHighAPI_Interface> >
+ wrap(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures);
+
protected:
std::shared_ptr<ModelAPI_AttributeBoolean> myAuxiliary;
//--------------------------------------------------------------------------------------
#include "SketchAPI_Translation.h"
+#include <SketchAPI_SketchEntity.h>
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_SketchEntity.h>
//--------------------------------------------------------------------------------------
SketchAPI_Translation::SketchAPI_Translation(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
}
+std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Translation::translated() const
+{
+ std::list<ObjectPtr> aList = translatedObjects()->list();
+ // remove all initial features
+ std::list<FeaturePtr> anIntermediate;
+ std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+ if (isCopy.get() && isCopy->value())
+ anIntermediate.push_back(aFeature);
+ }
+ return SketchAPI_SketchEntity::wrap(anIntermediate);
+}
+
//--------------------------------------------------------------------------------------
void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
if (isFullValue)
theDumper << ", " << isFullValue;
theDumper << ")" << std::endl;
+
+ // Dump variables for a list of translated features
+ theDumper << "[";
+ std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = translated();
+ std::list<std::shared_ptr<ModelHighAPI_Interface> >::const_iterator anIt = aList.begin();
+ for (; anIt != aList.end(); ++anIt) {
+ if (anIt != aList.begin())
+ theDumper << ", ";
+ theDumper << theDumper.name((*anIt)->feature(), false);
+ }
+ theDumper << "] = " << theDumper.name(aBase) << ".translated()" << std::endl;
}
translatedObjects, SketchPlugin_MultiTranslation::ENTITY_B(), ModelAPI_AttributeRefList, /** Translationed objects */
)
+ /// List of translated objects
+ SKETCHAPI_EXPORT
+ std::list<std::shared_ptr<ModelHighAPI_Interface> > translated() const;
+
/// Dump wrapped feature
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};