/// Dump given feature
virtual void dumpFeature(const FeaturePtr& theFeature, const bool theForce = false) = 0;
+ /// Set a feature that should not be dumped anyway
+ MODELHIGHAPI_EXPORT
+ void doNotDumpFeature(const FeaturePtr& theFeature)
+ { myFeaturesToSkip.insert(theFeature); }
+
/// Dump sub-feature name and color, without dumping feature creation.
/// Used for features which creates sub-features in their execute method.
/// \param theSubFeatureGet [in] method for getting sub-feature (e.g. "Feature_1.subFeature(0)")
NbFeaturesMap myFeatureCount; ///< number of features of each kind
+ /// features which should not be dumped (like coincidence and tangency created by tangent arc)
+ std::set<FeaturePtr> myFeaturesToSkip;
+
protected:
/// list of entities, used by other features but not dumped yet
std::set<EntityPtr> myNotDumpedEntities;
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintTangent.h>
+
+/// Obtain constraints prepared by tangent arc
+static std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc);
+
//================================================================================================
SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
: SketchAPI_SketchEntity(theFeature)
theDumper << aBase << " = " << aSketchName << ".addArc(" << startPoint() << ", "
<< endPoint() << ", " << passedPoint() << ")" << std::endl;
} else {
+ // do not dump coincidence and tangency constraint built by tangent arc
+ std::list<FeaturePtr> aConstraintsToSkip = tangentArcConstraints(aBase);
+ std::list<FeaturePtr>::iterator anIt = aConstraintsToSkip.begin();
+ for (; anIt != aConstraintsToSkip.end(); ++anIt)
+ theDumper.doNotDumpFeature(*anIt);
+
// tangent arc
AttributeRefAttrPtr aTangentPoint = tangentPoint();
theDumper << aBase << " = " << aSketchName << ".addArc("
// dump "auxiliary" flag if necessary
SketchAPI_SketchEntity::dump(theDumper);
}
+
+
+// ==================== Auxiliary functions ===============================
+std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc)
+{
+ std::list<FeaturePtr> aConstraints;
+
+ std::set<FeaturePtr> aCoincidences;
+ std::set<FeaturePtr> aTangencies;
+
+ const std::set<AttributePtr>& aBaseRefs = theArc->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator anIt = aBaseRefs.begin();
+ for (; anIt != aBaseRefs.end(); ++anIt) {
+ FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner());
+ if (anOwner->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+ aCoincidences.insert(anOwner);
+ }
+ const std::set<AttributePtr>& aBaseResultRefs = theArc->lastResult()->data()->refsToMe();
+ for (anIt = aBaseResultRefs.begin(); anIt != aBaseResultRefs.end(); ++anIt) {
+ FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner());
+ if (anOwner->getKind() == SketchPlugin_ConstraintTangent::ID())
+ aTangencies.insert(anOwner);
+ }
+
+ AttributePtr aTangentPoint = theArc->refattr(SketchPlugin_Arc::TANGENT_POINT_ID())->attr();
+ if (aTangentPoint) {
+ FeaturePtr aTangentFeature = ModelAPI_Feature::feature(aTangentPoint->owner());
+
+ const std::set<AttributePtr>& aTgRefs = aTangentFeature->data()->refsToMe();
+ for (anIt = aTgRefs.begin(); anIt != aTgRefs.end(); ++anIt) {
+ FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner());
+ if (aCoincidences.find(anOwner) != aCoincidences.end()) {
+ // check the coincidence is correct
+ AttributePtr aConstrained1 = anOwner->refattr(SketchPlugin_Constraint::ENTITY_A())->attr();
+ AttributePtr aConstrained2 = anOwner->refattr(SketchPlugin_Constraint::ENTITY_B())->attr();
+ AttributePtr anArcStartPoint = theArc->attribute(SketchPlugin_Arc::START_ID());
+ if ((aConstrained1 == anArcStartPoint && aConstrained2 == aTangentPoint) ||
+ (aConstrained1 == aTangentPoint && aConstrained2 == anArcStartPoint)) {
+ aConstraints.push_back(anOwner);
+ break; // search first applicable coincidence only
+ }
+ }
+ }
+
+ const std::set<AttributePtr>& aTgResultRefs =
+ aTangentFeature->lastResult()->data()->refsToMe();
+ for (anIt = aTgResultRefs.begin(); anIt != aTgResultRefs.end(); ++anIt) {
+ FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner());
+ if (aTangencies.find(anOwner) != aTangencies.end()) {
+ aConstraints.push_back(anOwner);
+ break; // search first tangency only
+ }
+ }
+ }
+
+ return aConstraints;
+}