1. Dump Sketch features.
2. Store getter for each attribute in ModelHighAPI_Interface
}
}
+%typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_RefAttr, const ModelHighAPI_RefAttr & {
+ std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
+ std::shared_ptr<ModelAPI_Object> * temp_object;
+ std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+ int newmem = 0;
+ if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (temp_attribute) {
+ $1 = 1;
+ } else {
+ $1 = 0;
+ }
+ } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (temp_object) {
+ $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 ModelHighAPI_Reference & (ModelHighAPI_Reference temp) {
std::shared_ptr<ModelAPI_Object> * temp_object;
std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_CompositeFeature.h>
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool)
{
- myDumpBuffer << theAttrBool->value();
+ myDumpBuffer << (theAttrBool->value() ? "True" : "False");
return *this;
}
return *this;
}
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+ const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr)
+{
+ if (theRefAttr->isObject())
+ myDumpBuffer << name(theRefAttr->object());
+ else {
+ AttributePtr anAttr = theRefAttr->attr();
+ FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
+ myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, anAttr->id()) << "()";
+ }
+ return *this;
+}
+
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect)
{
class ModelAPI_AttributeBoolean;
class ModelAPI_AttributeDouble;
class ModelAPI_AttributeInteger;
+class ModelAPI_AttributeRefAttr;
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeString;
class ModelAPI_CompositeFeature;
/// Dump given feature
virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
+ /// Return name of getter for corresponding attribute
+ virtual std::string attributeGetter(const FeaturePtr& theFeature,
+ const std::string& theAttrName) const = 0;
+
/// Save all dumps into specified file
MODELHIGHAPI_EXPORT
bool exportTo(const std::string& theFileName);
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const EntityPtr& theEntity);
+ /// Dump AttributeRefAttr
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
/// Dump AttributeSelection
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
{
Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
}
+
+const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
+{
+ return myAttrGetter[theAttrName];
+}
#include "ModelHighAPI.h"
#include <list>
+#include <map>
#include <memory>
#include <string>
#include <iostream>
MODELHIGHAPI_EXPORT
void throwException(const std::string & theDescription);
+ /// Return name of getter for specified attribute
+ MODELHIGHAPI_EXPORT
+ const std::string& attributeGetter(const std::string& theAttrName);
+
/// Dump wrapped feature
MODELHIGHAPI_EXPORT
virtual void dump(ModelHighAPI_Dumper& theDumper) const {}
protected:
std::shared_ptr<ModelAPI_Feature> myFeature;
+
+ std::map<std::string, std::string> myAttrGetter; ///< names of attributes and their getters
};
//! Pointer on Interface object
//--------------------------------------------------------------------------------------
#define VAR_NAME(NAME) my##NAME
+//--------------------------------------------------------------------------------------
+#define TO_STRING_(NAME) #NAME
+#define TO_STRING(NAME) TO_STRING_(NAME)
+
//--------------------------------------------------------------------------------------
// Used in INTERFACE_N for create variable and getter
#define DEFINE_ATTRIBUTE(NAME, TYPE, COMMENT) \
#define SET_ATTRIBUTE(NAME, TYPE, ATT_NAME) \
VAR_NAME(NAME) = std::dynamic_pointer_cast<TYPE>(feature()->attribute(ATT_NAME)); \
if (!VAR_NAME(NAME)) \
- return false;
+ return false; \
+ myAttrGetter[ATT_NAME] = TO_STRING(NAME);
//--------------------------------------------------------------------------------------
#define INTERFACE_COMMON(KIND) \
ModelHighAPI.ModelHighAPI_Dumper.__init__(self)
ModelHighAPI.ModelHighAPI_Dumper.setInstance(self)
self.collectFeatures()
-
+
## Collect feature wrappers, which allow dumping (have method dump)
def collectFeatures(self):
self.myFeatures = {}
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
-
+
## Create wrapper for a given feature and dump it
def dumpFeature(self, theFeature, theForce):
aFeatureKind = theFeature.getKind()
else:
self.name(theFeature)
+ ## Return getter for specified attribute
+ def attributeGetter(self, theFeature, theAttrName):
+ aFeatureKind = theFeature.getKind()
+ if aFeatureKind in self.myFeatures:
+ return self.myFeatures[aFeatureKind](theFeature).attributeGetter(theAttrName)
+ return std_string()
# Instance of dumper
dumper = DumpAssistant
\ No newline at end of file
#include <GeomAPI_Pnt2d.h>
#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
execute();
}
+
+//==================================================================================================
+void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aSketchName = theDumper.parentName(aBase);
+
+ AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+ if (anExternal->value()) {
+ // arc is external
+ theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
+ } else {
+ AttributeStringPtr aType = arcType();
+ if (aType->value() == SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()) {
+ // arc given by center and start, end points
+ theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
+ << startPoint() << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
+ } else if (aType->value() == SketchPlugin_Arc::ARC_TYPE_THREE_POINTS()) {
+ // arc given by three points
+ theDumper << aBase << " = " << aSketchName << ".addArc(" << startPoint() << ", "
+ << endPoint() << ", " << passedPoint() << ")" << std::endl;
+ } else {
+ // tangent arc
+ AttributeRefAttrPtr aTangentPoint = tangentPoint();
+ theDumper << aBase << " = " << aSketchName << ".addArc("
+ << aTangentPoint << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
+ }
+ }
+ // dump "auxiliary" flag if necessary
+ SketchAPI_SketchEntity::dump(theDumper);
+}
/// Set angle.
SKETCHAPI_EXPORT
void setAngle(double theAngle);
+
+ /// Dump wrapped feature
+ SKETCHAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};
/// Pointer on Arc object.
#include <GeomAPI_Pnt2d.h>
#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
execute();
}
+
+//==================================================================================================
+void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aSketchName = theDumper.parentName(aBase);
+
+ AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+ if (anExternal->value()) {
+ // circle is external
+ theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
+ } else {
+ AttributeStringPtr aType = circleType();
+ if (aType->value() == SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS()) {
+ // circle given by center and radius
+ theDumper << aBase << " = " << aSketchName << ".addCircle("
+ << center() << ", " << radius() << ")" << std::endl;
+ } else {
+ // circle given by three points
+ theDumper << aBase << " = " << aSketchName << ".addCircle(" << firstPoint() << ", "
+ << secondPoint() << ", " << thirdPoint() << ")" << std::endl;
+ }
+ }
+ // dump "auxiliary" flag if necessary
+ SketchAPI_SketchEntity::dump(theDumper);
+}
/// Set third point.
SKETCHAPI_EXPORT
void setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+ /// Dump wrapped feature
+ SKETCHAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};
/// Pointer on Circle object.
//--------------------------------------------------------------------------------------
#include <GeomAPI_Pnt2d.h>
//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
+void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aSketchName = theDumper.parentName(aBase);
+
+ AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+ if (anExternal->value()) {
+ // line is external
+ theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl;
+ } else {
+ // segment given by its points
+ theDumper << aBase << " = " << aSketchName << ".addLine("
+ << startPoint() << ", " << endPoint() << ")" << std::endl;
+ }
+ // dump "auxiliary" flag if necessary
+ SketchAPI_SketchEntity::dump(theDumper);
+}
/// Set end point
SKETCHAPI_EXPORT
void setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
+
+ /// Dump wrapped feature
+ SKETCHAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
};
//! Pointer on Line object
theDumper << aBase << " = " << aSketchName << ".addPoint(" << anExternal << ")" << std::endl;
} else {
// point given by coordinates
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aBase->attribute(SketchPlugin_Point::COORD_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint = coordinates();
theDumper << aBase << " = " << aSketchName << ".addPoint(" << aPoint << ")" << std::endl;
}
+ // dump "auxiliary" flag if necessary
+ SketchAPI_SketchEntity::dump(theDumper);
}
//--------------------------------------------------------------------------------------
#include "SketchAPI_SketchEntity.h"
//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Tools.h>
//--------------------------------------------------------------------------------------
SketchAPI_SketchEntity::SketchAPI_SketchEntity(
}
//--------------------------------------------------------------------------------------
+void SketchAPI_SketchEntity::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ AttributeBooleanPtr anAux = aBase->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
+ if (anAux->value()) {
+ const std::string& aName = theDumper.name(aBase);
+ theDumper << aName << ".setAuxiliary(" << anAux << ")" <<std::endl;
+ }
+}
SKETCHAPI_EXPORT
void setAuxiliary(bool theAuxiliary);
+ /// Dump wrapped feature
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+
protected:
std::shared_ptr<ModelAPI_AttributeBoolean> myAuxiliary;