]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix dumping tangent arc. Do not dump constraints created by tangent arc.
authorazv <azv@opencascade.com>
Wed, 1 Mar 2017 13:48:20 +0000 (16:48 +0300)
committerazv <azv@opencascade.com>
Wed, 1 Mar 2017 13:48:20 +0000 (16:48 +0300)
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/SketchAPI/SketchAPI_Arc.cpp

index a90cf4c0545d95648561ee6f6013767ae15db57e..6c9fe61b90252255cf3b005b5125f641c1e9234f 100644 (file)
@@ -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<ModelAPI_Feature>(theEntity);
+  return aFound != myNames.end() || myFeaturesToSkip.find(aFeature) != myFeaturesToSkip.end();
 }
 
 bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const
index 2da5ee93e9319827907e4878cc1e276d81ae9fa2..618e9d5e2029f167aba6fd7e96a2ea168ca1d963 100644 (file)
@@ -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<FeaturePtr> myFeaturesToSkip;
+
 protected:
    /// list of entities, used by other features but not dumped yet
   std::set<EntityPtr> myNotDumpedEntities;
index 63c1aa4f6bcfc4ea1dc9bec50b9fc378742f3794..d281c3af35ea006d9a7963af6ef644600bfc4eff 100644 (file)
 #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)
@@ -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<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("
@@ -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<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;
+}