]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Avoid conflicting constraint while mirroring the arc in PlaneGCS (issue #1280)
authorazv <azv@opencascade.com>
Tue, 9 Feb 2016 10:47:13 +0000 (13:47 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:40 +0000 (17:04 +0300)
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h
src/SketchSolver/SketchSolver_Group.cpp

index 23933b232d6ee48c19872ca21ea23b4be62bc350..e5002f1306e8f5070ddd5489c270575a5978bd16 100644 (file)
@@ -462,6 +462,8 @@ void PlaneGCSSolver_Builder::adjustConstraint(ConstraintWrapperPtr theConstraint
     adjustAngle(theConstraint);
   else if (aType == CONSTRAINT_PT_LINE_DISTANCE)
     adjustPtLineDistance(theConstraint);
+  else if (aType == CONSTRAINT_SYMMETRIC)
+    adjustMirror(theConstraint);
 }
 
 EntityWrapperPtr PlaneGCSSolver_Builder::createFeature(
@@ -1239,3 +1241,20 @@ void adjustPtLineDistance(ConstraintWrapperPtr theConstraint)
     theConstraint->setValue(theConstraint->value() * (-1.0));
 }
 
+void adjustMirror(ConstraintWrapperPtr theConstraint)
+{
+  std::vector<EntityWrapperPtr> aPoints;
+  EntityWrapperPtr aMirrorLine;
+
+  const std::list<EntityWrapperPtr>& aSubs = theConstraint->entities();
+  std::list<EntityWrapperPtr>::const_iterator anIt = aSubs.begin();
+  for (; anIt != aSubs.end(); ++anIt) {
+    if ((*anIt)->type() == ENTITY_POINT)
+      aPoints.push_back(*anIt);
+    else if ((*anIt)->type() == ENTITY_LINE)
+      aMirrorLine = *anIt;
+  }
+
+  makeMirrorPoints(aPoints[0], aPoints[1], aMirrorLine);
+}
+
index eb96bceff1145e6d70110c62769b424a4c03b1f1..b79fd0dc8f031435bfd698ecdaa92802fb24e852 100644 (file)
@@ -467,6 +467,24 @@ void PlaneGCSSolver_Storage::updateCoincident(const EntityWrapperPtr& thePoint)
 }
 
 
+bool PlaneGCSSolver_Storage::isRedundant(
+    GCSConstraintPtr theCheckedConstraint,
+    ConstraintWrapperPtr theParentConstraint) const
+{
+  if (theParentConstraint->type() == CONSTRAINT_SYMMETRIC) {
+    if (theCheckedConstraint->getTypeId() == GCS::Perpendicular) {
+      BuilderPtr aBuilder = PlaneGCSSolver_Builder::getInstance();
+      // check the initial point is placed on the mirror line
+      std::list<EntityWrapperPtr> aSubs = theParentConstraint->entities();
+      std::shared_ptr<GeomAPI_Pnt2d> aPoint = aBuilder->point(aSubs.front());
+      std::shared_ptr<GeomAPI_Lin2d> aLine = aBuilder->line(aSubs.back());
+      return aLine->distance(aPoint) < tolerance;
+    }
+  }
+
+  return false;
+}
+
 void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver)
 {
   std::shared_ptr<PlaneGCSSolver_Solver> aSolver =
@@ -487,7 +505,8 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver)
           std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(*aCWIt);
       std::list<GCSConstraintPtr>::const_iterator anIt = aGCS->constraints().begin();
       for (; anIt != aGCS->constraints().end(); ++anIt)
-        aSolver->addConstraint(*anIt);
+        if (!isRedundant(*anIt, aGCS))
+          aSolver->addConstraint(*anIt);
     }
   }
   // additional constraints for arcs
index 45d8d0c5b39e19b194ee81f666b75ce9e2cf2296..de3fbe301a629b89b7e9abd6dc35877bfbdc06e3 100644 (file)
@@ -103,6 +103,12 @@ private:
   /// \brief Adjust parameters of points coincident with the given
   void updateCoincident(const EntityWrapperPtr& thePoint);
 
+  /// \brief Verifies the constraint should not be added into the solver
+  ///
+  /// This is a workaround method to avoid some kinds of conflicting constraints:
+  ///   * symmetric of two points placed on the mirror line (do not add perpendicular constraint)
+  bool isRedundant(GCSConstraintPtr theCheckedConstraint, ConstraintWrapperPtr theParentConstraint) const;
+
 private:
   GCS::VEC_pD                      myParameters;         ///< list of parameters
   GCS::VEC_pD                      myConst;              ///< list of constants
index 1da845930f9b433fe7eec9afc982b1c0141d01f4..d6c8b0218cd86e6547b1cc33d9cad5c8e98115fd 100644 (file)
@@ -186,11 +186,13 @@ static void updateMultiConstraints(ConstraintConstraintMap& theConstraints, Feat
 {
   ConstraintConstraintMap::iterator aCIt = theConstraints.begin();
   for (; aCIt != theConstraints.end(); ++aCIt) {
-    if ((aCIt->second->getType() == CONSTRAINT_MULTI_ROTATION ||
-         aCIt->second->getType() == CONSTRAINT_MULTI_TRANSLATION)
+    SketchSolver_ConstraintType aType = aCIt->second->getType();
+    if ((aType == CONSTRAINT_MULTI_ROTATION ||
+         aType == CONSTRAINT_MULTI_TRANSLATION)
         && aCIt->second->isUsed(theFeature))
       std::dynamic_pointer_cast<SketchSolver_ConstraintMulti>(aCIt->second)->update(true);
-    else if (aCIt->second->getType() == CONSTRAINT_TANGENT_CIRCLE_LINE
+    else if ((aType == CONSTRAINT_TANGENT_CIRCLE_LINE ||
+              aType == CONSTRAINT_SYMMETRIC)
              && aCIt->second->isUsed(theFeature))
       aCIt->second->update();
   }