]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
PlaneGCSSolver: workaround for wrong redundant constraints available on arc-line...
authorazv <azv@opencascade.com>
Tue, 7 Jun 2016 15:29:50 +0000 (18:29 +0300)
committerazv <azv@opencascade.com>
Tue, 7 Jun 2016 15:53:02 +0000 (18:53 +0300)
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h

index 9aa18c59211b69bdfe0414f548a6eaf3dc9d18ef..37e58bf828c85ceec0b4a69590c87056446d4716 100644 (file)
@@ -40,6 +40,17 @@ void PlaneGCSSolver_Solver::removeConstraint(GCSConstraintPtr theConstraint)
   myConstraints.erase(aConstraint);
 }
 
+static void removeTangent(GCS::VEC_I& theRedundant, const GCS::SET_I& theTangent)
+{
+  int i = 0;
+  while (i < theRedundant.size()) {
+    if (theTangent.find(theRedundant[i]) == theTangent.end())
+      ++i;
+    else
+      theRedundant.erase(theRedundant.begin() + i);
+  }
+}
+
 SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve()
 {
   // clear list of conflicting constraints
@@ -76,6 +87,8 @@ SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve()
     // additionally check redundant constraints
     GCS::VEC_I aRedundantID;
     myEquationSystem.getRedundant(aRedundantID);
+    // remove redundant constraints relative to tangency
+    removeTangent(aRedundantID, myTangent);
     if (!aRedundantID.empty())
       aResult = GCS::Failed;
   }
index 35920bca0627aa0ed44d510968a8034db622efa6..a3c266346a19ea0a2d53775a8a834a84aad8f8df 100644 (file)
@@ -34,6 +34,13 @@ public:
   void setParameters(const GCS::VEC_pD& theParams)
   { myParameters = theParams; }
 
+  /// \brief Set list of IDs of tangent constraints
+  ///
+  /// Workaround to avoid incorrect report about redundant constraints
+  /// if an arc is already smoothly connected to a line.
+  void setTangent(const GCS::SET_I& theTangentIDs)
+  { myTangent = theTangentIDs; }
+
   /** \brief Solve the set of equations
    *  \return identifier whether solution succeeded
    */
@@ -62,6 +69,8 @@ private:
 
   GCS::VEC_I                 myConflictingIDs; ///< list of IDs of conflicting constraints
   bool                       myConfCollected;  ///< specifies the conflicting constraints are already collected
+
+  GCS::SET_I                 myTangent;        ///< list of tangent IDs to check incorrect redundant constraints
 };
 
 #endif
index aa011cc4f6181db19a70eb832f9f0c7a6c83c8e4..35973564de988b05f8f16e1ef8e33ecacf9df07b 100644 (file)
@@ -19,6 +19,7 @@
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 #include <SketchPlugin_Arc.h>
+#include <SketchPlugin_ConstraintTangent.h>
 
 #include <cmath>
 
@@ -556,6 +557,7 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver)
   // initialize constraints
   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
       aCIt = myConstraintMap.begin();
+  GCS::SET_I aTangentIDs;
   for (; aCIt != myConstraintMap.end(); ++aCIt) {
     std::list<ConstraintWrapperPtr>::const_iterator aCWIt = aCIt->second.begin();
     for (; aCWIt != aCIt->second.end(); ++ aCWIt) {
@@ -566,6 +568,14 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver)
         if (!isRedundant(*anIt, aGCS))
           aSolver->addConstraint(*anIt);
     }
+    // store IDs of tangent constraints to avoid incorrect report of redundant constraints
+    if (aCIt->first && aCIt->first->getKind() == SketchPlugin_ConstraintTangent::ID())
+      for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++ aCWIt) {
+        std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aGCS =
+            std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(*aCWIt);
+        if (aGCS->constraints().front()->getTypeId() == GCS::P2LDistance)
+          aTangentIDs.insert((int)(*aCWIt)->id());
+      }
   }
   // additional constraints for arcs
   std::map<EntityWrapperPtr, std::vector<GCSConstraintPtr> >::const_iterator
@@ -580,6 +590,8 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver)
   for (; aRemIt != myRemovedConstraints.end(); ++aRemIt)
     aSolver->removeConstraint(*aRemIt);
   myRemovedConstraints.clear();
+  // set list of tangent constraints
+  aSolver->setTangent(aTangentIDs);
   // initialize unknowns
   aSolver->setParameters(myParameters);
 }
index de3fbe301a629b89b7e9abd6dc35877bfbdc06e3..dd71f9eedbc3a4449dcbde3ca4eb9c34988ddeb4 100644 (file)
@@ -116,7 +116,7 @@ private:
   ConstraintID                     myConstraintLastID;   ///< identifier of last added constraint
 
   std::map<EntityWrapperPtr, std::vector<GCSConstraintPtr> >
-                                  myArcConstraintMap;    ///< additional constraints for correct processing of the arcs
+                                   myArcConstraintMap;   ///< additional constraints for correct processing of the arcs
 
   std::list<GCSConstraintPtr>      myRemovedConstraints; ///< list of removed constraints to notify solver
 };