From: azv Date: Wed, 1 Mar 2017 13:48:20 +0000 (+0300) Subject: Fix dumping tangent arc. Do not dump constraints created by tangent arc. X-Git-Tag: V_2.7.0~257 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d78b8cb28bc02e50851f73f3beed410a23778072;p=modules%2Fshaper.git Fix dumping tangent arc. Do not dump constraints created by tangent arc. --- diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index a90cf4c05..6c9fe61b9 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -470,7 +470,8 @@ void ModelHighAPI_Dumper::dumpEntitySetName() bool ModelHighAPI_Dumper::isDumped(const EntityPtr& theEntity) const { EntityNameMap::const_iterator aFound = myNames.find(theEntity); - return aFound != myNames.end(); + FeaturePtr aFeature = std::dynamic_pointer_cast(theEntity); + return aFound != myNames.end() || myFeaturesToSkip.find(aFeature) != myFeaturesToSkip.end(); } bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 2da5ee93e..618e9d5e2 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -103,6 +103,11 @@ public: /// 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)") @@ -304,6 +309,9 @@ private: NbFeaturesMap myFeatureCount; ///< number of features of each kind + /// features which should not be dumped (like coincidence and tangency created by tangent arc) + std::set myFeaturesToSkip; + protected: /// list of entities, used by other features but not dumped yet std::set myNotDumpedEntities; diff --git a/src/SketchAPI/SketchAPI_Arc.cpp b/src/SketchAPI/SketchAPI_Arc.cpp index 63c1aa4f6..d281c3af3 100644 --- a/src/SketchAPI/SketchAPI_Arc.cpp +++ b/src/SketchAPI/SketchAPI_Arc.cpp @@ -13,6 +13,12 @@ #include #include +#include +#include + +/// Obtain constraints prepared by tangent arc +static std::list tangentArcConstraints(const FeaturePtr& theArc); + //================================================================================================ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr & theFeature) : SketchAPI_SketchEntity(theFeature) @@ -259,6 +265,12 @@ void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const theDumper << aBase << " = " << aSketchName << ".addArc(" << startPoint() << ", " << endPoint() << ", " << passedPoint() << ")" << std::endl; } else { + // do not dump coincidence and tangency constraint built by tangent arc + std::list aConstraintsToSkip = tangentArcConstraints(aBase); + std::list::iterator anIt = aConstraintsToSkip.begin(); + for (; anIt != aConstraintsToSkip.end(); ++anIt) + theDumper.doNotDumpFeature(*anIt); + // tangent arc AttributeRefAttrPtr aTangentPoint = tangentPoint(); theDumper << aBase << " = " << aSketchName << ".addArc(" @@ -268,3 +280,60 @@ void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const // dump "auxiliary" flag if necessary SketchAPI_SketchEntity::dump(theDumper); } + + +// ==================== Auxiliary functions =============================== +std::list tangentArcConstraints(const FeaturePtr& theArc) +{ + std::list aConstraints; + + std::set aCoincidences; + std::set aTangencies; + + const std::set& aBaseRefs = theArc->data()->refsToMe(); + std::set::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& 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& 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& 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; +}