bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theDoc)
{
bool isOk = true;
+ CompositeFeaturePtr aLastComposite;
// dump all features
std::list<FeaturePtr> aFeatures = theDoc->allFeatures();
std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
for (; aFeatIt != aFeatures.end(); ++aFeatIt) {
- dumpFeature(*aFeatIt);
+ // dump feature if and only if it is not a sub-feature of last composite feature
+ // (all subs of composite are dumped in special method)
+ if (!aLastComposite || !aLastComposite->isSub(*aFeatIt))
+ dumpFeature(*aFeatIt);
+
// iteratively process composite features
CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFeatIt);
if (!aCompFeat)
myNames[aSubDoc] = myNames[*aFeatIt];
isOk = process(aSubDoc) && isOk;
- } else
+ } else {
isOk = process(aCompFeat) && isOk;
+ aLastComposite = aCompFeat;
+ }
}
return isOk;
}
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr)
{
- if (theRefAttr->isObject())
- myDumpBuffer << name(theRefAttr->object());
- else {
+ if (theRefAttr->isObject()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theRefAttr->object());
+ myDumpBuffer << name(aFeature);
+ } else {
AttributePtr anAttr = theRefAttr->attr();
FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, anAttr->id()) << "()";
--- /dev/null
+// Name : SketchAPI_Constraint.cpp
+// Purpose:
+//
+// History:
+// 08/08/16 - Artem ZHIDKOV - Creation of the file
+
+#include "SketchAPI_Constraint.h"
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_ConstraintAngle.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCollinear.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintEqual.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintMiddle.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintTangent.h>
+#include <SketchPlugin_ConstraintVertical.h>
+
+SketchAPI_Constraint::SketchAPI_Constraint(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+ ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
+ if (aConstraint)
+ initialize();
+}
+
+SketchAPI_Constraint::~SketchAPI_Constraint()
+{
+}
+
+bool SketchAPI_Constraint::initialize()
+{
+ if (!feature()) {
+ throwException("Constraint exception: The feature is NULL.");
+ return false;
+ }
+ return true;
+}
+
+static const std::string& constraintTypeToSetter(const std::string& theType)
+{
+ if (theType == SketchPlugin_ConstraintCoincidence::ID()) {
+ static const std::string COINCIDENCE_SETTER("setCoincident");
+ return COINCIDENCE_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintAngle::ID()) {
+ static const std::string ANGLE_SETTER("setAngle");
+ return ANGLE_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintCollinear::ID()) {
+ static const std::string COLLINEAR_SETTER("setCollinear");
+ return COLLINEAR_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintDistance::ID()) {
+ static const std::string DISTANCE_SETTER("setDistance");
+ return DISTANCE_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintEqual::ID()) {
+ static const std::string EQUAL_SETTER("setEqual");
+ return EQUAL_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintHorizontal::ID()) {
+ static const std::string HORIZONTAL_SETTER("setHorizontal");
+ return HORIZONTAL_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintLength::ID()) {
+ static const std::string LENGTH_SETTER("setLength");
+ return LENGTH_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintMiddle::ID()) {
+ static const std::string MIDDLE_SETTER("setMiddlePoint");
+ return MIDDLE_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintParallel::ID()) {
+ static const std::string PARALLEL_SETTER("setParallel");
+ return PARALLEL_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintPerpendicular::ID()) {
+ static const std::string PERPENDICULAR_SETTER("setPerpendicular");
+ return PERPENDICULAR_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintRadius::ID()) {
+ static const std::string RADIUS_SETTER("setRadius");
+ return RADIUS_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintRigid::ID()) {
+ static const std::string FIXED_SETTER("setFixed");
+ return FIXED_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintTangent::ID()) {
+ static const std::string TANGENT_SETTER("setTangent");
+ return TANGENT_SETTER;
+ }
+ if (theType == SketchPlugin_ConstraintVertical::ID()) {
+ static const std::string VERTICAL_SETTER("setVertical");
+ return VERTICAL_SETTER;
+ }
+
+ static const std::string DUMMY;
+ return DUMMY;
+}
+
+void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(feature());
+ if (!aConstraint)
+ return; // dump constraints only
+
+ const std::string& aSetter = constraintTypeToSetter(aConstraint->getKind());
+ if (aSetter.empty())
+ return; // incorrect constraint type
+
+ const std::string& aSketchName = theDumper.parentName(aConstraint);
+ theDumper << aConstraint << " = " << aSketchName << "." << aSetter << "(";
+
+ bool isFirstAttr = true;
+ for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
+ AttributeRefAttrPtr aRefAttr = aConstraint->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
+ if (aRefAttr && aRefAttr->isInitialized()) {
+ theDumper << (isFirstAttr ? "" : ", ") << aRefAttr;
+ isFirstAttr = false;
+ }
+ }
+
+ AttributeDoublePtr aValueAttr = aConstraint->real(SketchPlugin_Constraint::VALUE());
+ if (aValueAttr && aValueAttr->isInitialized())
+ theDumper << ", " << aValueAttr;
+
+ theDumper << ")" << std::endl;
+}
--- /dev/null
+// Name : SketchAPI_Constraint.h
+// Purpose:
+//
+// History:
+// 08/08/16 - Artem ZHIDKOV - Creation of the file
+
+#ifndef SRC_SKETCHAPI_SKETCHAPI_CONSTRAINT_H_
+#define SRC_SKETCHAPI_SKETCHAPI_CONSTRAINT_H_
+
+#include "SketchAPI.h"
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+#include <ModelHighAPI_RefAttr.h>
+
+#include <SketchPlugin_Constraint.h>
+
+/**\class SketchAPI_Constraint
+ * \ingroup CPPHighAPI
+ * \brief Interface for Constraint feature
+ */
+class SketchAPI_Constraint : public ModelHighAPI_Interface
+{
+public:
+ /// Constructor without values
+ SKETCHAPI_EXPORT
+ explicit SketchAPI_Constraint(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+
+ /// Destructor
+ SKETCHAPI_EXPORT
+ virtual ~SketchAPI_Constraint();
+
+ static std::string ID()
+ {
+ static const std::string DUMMY;
+ return DUMMY;
+ }
+ virtual std::string getID() { return ID(); }
+
+ SKETCHAPI_EXPORT
+ bool initialize();
+
+ /// Dump wrapped feature
+ SKETCHAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+#endif