]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1578: arc problems
authorazv <azv@opencascade.com>
Tue, 21 Jun 2016 14:14:16 +0000 (17:14 +0300)
committerazv <azv@opencascade.com>
Tue, 21 Jun 2016 14:15:20 +0000 (17:15 +0300)
* Do not treat as a redundant the PlaneGCS's Equal constraint
* Do not put into SketchSolver_Storage features, which are copies in Multi-Rotation or Multi-Translation constraint (performance optimization)

src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_Storage.cpp
src/SketchSolver/SketchSolver_Storage.h

index 6cb6f40764c1fb6783d38bba736fe2b542c3f1e3..ff8d151505007369c73cda968a2d676cbf6cfca9 100644 (file)
@@ -83,6 +83,18 @@ SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve()
     // additionally check redundant constraints
     GCS::VEC_I aRedundantID;
     myEquationSystem.getRedundant(aRedundantID);
+    // Workaround: remove all constraints "Equal"
+    if (!aRedundantID.empty()) {
+      std::set<GCS::Constraint*>::const_iterator aCIt = myConstraints.begin();
+      for (; aCIt != myConstraints.end(); ++aCIt) {
+        GCS::VEC_I::iterator aRIt = aRedundantID.begin();
+        for (; aRIt != aRedundantID.end(); ++aRIt)
+          if ((*aCIt)->getTag() == *aRIt) {
+            aRedundantID.erase(aRIt);
+            break;
+          }
+      }
+    }
     // The system with tangent constraints may show redundant constraints if the entities are coupled smoothly.
     // Sometimes tangent constraints are fall to both conflicting and redundant constraints.
     // Need to check if there are redundant constraints without these tangencies.
index fcb2a1fc138371fb94e349c6886f9cd1b60249a1..c402ec7dd8adf39f515464d760625ba65f64518d 100644 (file)
@@ -226,6 +226,11 @@ void SketchSolver_Constraint::getAttributes(
 
     myStorage->update(*anIter/*, myGroupID*/);
     EntityWrapperPtr anEntity = myStorage->entity(*anIter);
+    if (!anEntity) {
+      // Force creation of an entity
+      myStorage->update(*anIter, GID_UNKNOWN, true);
+      anEntity = myStorage->entity(*anIter);
+    }
     myAttributes.push_back(anEntity);
 
     SketchSolver_EntityType aType = anEntity->type();
index a3b68b0872c4f846313ced95e31a8b17f0e1a190..9c8f3504f8c1c24a9de56d9018e85990b19a53d0 100644 (file)
@@ -149,6 +149,8 @@ void SketchSolver_Storage::addEntity(AttributePtr     theAttribute,
 static bool isCopyInMulti(std::shared_ptr<SketchPlugin_Feature> theFeature,
     const std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >& theConstraints)
 {
+  if (!theFeature)
+    return false;
   bool aResult = theFeature->isCopy();
   if (aResult) {
     std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
@@ -170,11 +172,17 @@ static bool isCopyInMulti(std::shared_ptr<SketchPlugin_Feature> theFeature,
   return aResult;
 }
 
-bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup)
+bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup, bool theForce)
 {
   bool isUpdated = false;
   EntityWrapperPtr aRelated = entity(theFeature);
   if (!aRelated) { // Feature is not exist, create it
+    std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
+        std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
+    bool isCopy = isCopyInMulti(aSketchFeature, myConstraintMap);
+    if (!theForce && isCopy && myFeatureMap.find(theFeature) == myFeatureMap.end())
+      return false; // the feature is a copy in "Multi" constraint and does not used in other constraints
+
     std::list<EntityWrapperPtr> aSubs;
     // Reserve the feature in the map of features (do not want to add several copies of it)
     myFeatureMap[theFeature] = aRelated;
@@ -182,13 +190,13 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup
     std::list<AttributePtr> anAttrs = pointAttributes(theFeature);
     std::list<AttributePtr>::const_iterator anIt = anAttrs.begin();
     for (; anIt != anAttrs.end(); ++anIt) {
-      isUpdated = update(*anIt, theGroup) || isUpdated;
+      isUpdated = update(*anIt, theGroup, theForce) || isUpdated;
       aSubs.push_back(entity(*anIt));
     }
     // If the feature is a circle, add its radius as a sub
     if (theFeature->getKind() == SketchPlugin_Circle::ID()) {
       AttributePtr aRadius = theFeature->attribute(SketchPlugin_Circle::RADIUS_ID());
-      isUpdated = update(aRadius, theGroup) || isUpdated;
+      isUpdated = update(aRadius, theGroup, theForce) || isUpdated;
       aSubs.push_back(entity(aRadius));
     }
     // If the feature if circle or arc, we need to add normal of the sketch to the list of subs
@@ -201,9 +209,7 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup
     BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
     GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
     // Check external feature
-    std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
-        std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
-    if (aSketchFeature && (aSketchFeature->isExternal() || isCopyInMulti(aSketchFeature, myConstraintMap)))
+    if (aSketchFeature && (aSketchFeature->isExternal() || isCopy))
       aGroup = GID_OUTOFGROUP;
     aRelated = aBuilder->createFeature(theFeature, aSubs, aGroup);
     if (!aRelated)
@@ -214,14 +220,14 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup
   return update(aRelated) || isUpdated;
 }
 
-bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup)
+bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup, bool theForce)
 {
   AttributePtr anAttribute = theAttribute;
   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
   if (aRefAttr) {
     if (aRefAttr->isObject()) {
       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
-      return update(aFeature, theGroup);
+      return update(aFeature, theGroup, theForce);
     } else
       anAttribute = aRefAttr->attr();
   }
@@ -237,7 +243,7 @@ bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theG
         if (aFeature->attribute(SketchPlugin_Arc::CENTER_ID())->isInitialized() && 
             aFeature->attribute(SketchPlugin_Arc::START_ID())->isInitialized() && 
             aFeature->attribute(SketchPlugin_Arc::END_ID())->isInitialized()) {
-          return SketchSolver_Storage::update(aFeature);
+          return SketchSolver_Storage::update(aFeature, theGroup, theForce);
         } else {
           myFeatureMap[aFeature] = EntityWrapperPtr();
           myExistArc = true;
index 9e2eae02fbf9f94a4b489bed441941996d744dc9..9bc6aeadc3d5bbcf299004b3bbee015edd02f175 100644 (file)
@@ -60,12 +60,15 @@ public:
   /// \brief Convert feature to the form applicable for specific solver and map it
   /// \param theFeature [in]  feature to convert
   /// \param theGroup   [in]  id of the group where the feature should be placed
+  /// \param theForce   [in]  forced feature creation
   /// \return \c true if the feature has been created or updated
-  SKETCHSOLVER_EXPORT bool update(FeaturePtr theFeature, const GroupID& theGroup = GID_UNKNOWN);
+  SKETCHSOLVER_EXPORT bool update(FeaturePtr theFeature, const GroupID& theGroup = GID_UNKNOWN, bool theForce = false);
   /// \brief Convert attribute to the form applicable for specific solver and map it
-  /// \param theFeature [in]  feature to convert
+  /// \param theAttribute [in]  attribute to convert
+  /// \param theGroup     [in]  id of the group where the feature should be placed
+  /// \param theForce     [in]  forced feature creation
   /// \return \c true if the attribute has been created or updated
-  SKETCHSOLVER_EXPORT bool update(AttributePtr theAttribute, const GroupID& theGroup = GID_UNKNOWN);
+  SKETCHSOLVER_EXPORT bool update(AttributePtr theAttribute, const GroupID& theGroup = GID_UNKNOWN, bool theForce = false);
 
   /// \brief Returns constraint related to corresponding constraint
   SKETCHSOLVER_EXPORT