]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp
Salome HOME
Tangency constraint between circle and linear segment
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Builder.cpp
index dd1d542fbdb80acf6478c9d32df7ebd2b6e4889a..95e01be607b8598a7a2b81e7642bb3f3e08283d8 100644 (file)
@@ -135,6 +135,8 @@ static ConstraintWrapperPtr
 static void adjustAngle(ConstraintWrapperPtr theConstraint);
 /// \brief Update mirror points
 static void adjustMirror(ConstraintWrapperPtr theConstraint);
+/// \brief Update a sign of the point-line distance constraint
+static void adjustPtLineDistance(ConstraintWrapperPtr theConstraint);
 
 /// \brief Transform points to be symmetric regarding to the mirror line
 static void makeMirrorPoints(EntityWrapperPtr theOriginal,
@@ -240,6 +242,7 @@ std::list<ConstraintWrapperPtr> PlaneGCSSolver_Builder::createConstraint(
                   GCS_PARAMETER_WRAPPER(anIntermediate));
     break;
   case CONSTRAINT_TANGENT_ARC_LINE:
+  case CONSTRAINT_TANGENT_CIRCLE_LINE:
   case CONSTRAINT_TANGENT_ARC_ARC:
     aResult = createConstraintTangent(theConstraint, theGroupID, theType,
                   GCS_ENTITY_WRAPPER(theEntity1), GCS_ENTITY_WRAPPER(theEntity2));
@@ -439,6 +442,8 @@ void PlaneGCSSolver_Builder::adjustConstraint(ConstraintWrapperPtr theConstraint
   // Update flags and parameters in constraints
   if (aType == CONSTRAINT_ANGLE)
     adjustAngle(theConstraint);
+  else if (aType == CONSTRAINT_PT_LINE_DISTANCE)
+    adjustPtLineDistance(theConstraint);
 }
 
 EntityWrapperPtr PlaneGCSSolver_Builder::createFeature(
@@ -990,7 +995,7 @@ ConstraintWrapperPtr createConstraintTangent(
     std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
 {
   GCSConstraintPtr aNewConstr;
-  if (theType == CONSTRAINT_TANGENT_ARC_LINE) {
+  if (theType == CONSTRAINT_TANGENT_ARC_LINE || theType == CONSTRAINT_TANGENT_CIRCLE_LINE) {
     std::shared_ptr<GCS::Circle> aCirc = std::dynamic_pointer_cast<GCS::Circle>(theEntity1->entity());
     std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
 
@@ -1113,3 +1118,24 @@ void makeMirrorPoints(EntityWrapperPtr theOriginal,
   }
 }
 
+void adjustPtLineDistance(ConstraintWrapperPtr theConstraint)
+{
+  BuilderPtr aBuilder = PlaneGCSSolver_Builder::getInstance();
+
+  std::shared_ptr<GeomAPI_Pnt2d> aPoint;
+  std::shared_ptr<GeomAPI_Lin2d> aLine;
+  std::list<EntityWrapperPtr> aSubs = theConstraint->entities();
+  std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
+  for (; aSIt != aSubs.end(); ++aSIt) {
+    if ((*aSIt)->type() == ENTITY_POINT)
+      aPoint = aBuilder->point(*aSIt);
+    else if ((*aSIt)->type() == ENTITY_LINE)
+      aLine = aBuilder->line(*aSIt);
+  }
+
+  std::shared_ptr<GeomAPI_XY> aLineVec = aLine->direction()->xy();
+  std::shared_ptr<GeomAPI_XY> aPtLineVec = aPoint->xy()->decreased(aLine->location()->xy());
+  if (aPtLineVec->cross(aLineVec) * theConstraint->value() < 0.0)
+    theConstraint->setValue(theConstraint->value() * (-1.0));
+}
+