]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #463: Fillet constraint - closed line is destroyed
authorazv <azv@opencascade.com>
Thu, 16 Apr 2015 10:50:23 +0000 (13:50 +0300)
committerazv <azv@opencascade.com>
Thu, 16 Apr 2015 12:17:28 +0000 (15:17 +0300)
1. Avoid conflicting constraints during fixing horizontal segment
2. Change behavior on fixing the base entities of fillet

src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_ConstraintRigid.cpp
src/SketchSolver/SketchSolver_ConstraintRigid.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 737809a985e0cf79be25c1cd1bd01eab79359f18..4db4c4636bfcfa54936257b11bda9c9c28841d63 100644 (file)
@@ -194,7 +194,8 @@ void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
   std::vector<Slvs_hConstraint>::iterator aCIter = mySlvsConstraints.begin();
   for (; aCIter != mySlvsConstraints.end(); aCIter++) {
     Slvs_Constraint aConstraint = myStorage->getConstraint(*aCIter);
-    aConstraint.valA = aValue;
+    if (aValueAttr)
+      aConstraint.valA = aValue;
     Slvs_hEntity* aCoeffs[6] = {
         &aConstraint.ptA, &aConstraint.ptB,
         &aConstraint.entityA, &aConstraint.entityB,
index d13285362b5ced69a2ee013d56a4f4c512f85d98..7247553ae345d4adcf618b0340f43f348f0e2c7d 100644 (file)
@@ -13,6 +13,8 @@
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_AttributeDouble.h>
 
+#include <math.h>
+
 SketchSolver_ConstraintRigid::SketchSolver_ConstraintRigid(FeaturePtr theFeature)
   : SketchSolver_Constraint(),
     myBaseFeature(theFeature)
@@ -184,7 +186,34 @@ void SketchSolver_ConstraintRigid::fixPoint(const Slvs_hEntity& thePointID)
 void SketchSolver_ConstraintRigid::fixLine(const Slvs_Entity& theLine)
 {
   Slvs_Constraint anEqual;
-  if (isUsedInEqual(theLine, anEqual)) {
+  if (isAxisParallel(theLine)) {
+    // Fix one point and a line length
+    Slvs_hConstraint aFixed;
+    if (!myStorage->isPointFixed(theLine.point[0], aFixed, true) &&
+        !myStorage->isPointFixed(theLine.point[1], aFixed, true))
+      fixPoint(theLine.point[0]);
+    if (!isUsedInEqual(theLine, anEqual)) {
+      // Calculate distance between points on the line
+      double aCoords[4];
+      for (int i = 0; i < 2; i++) {
+        Slvs_Entity aPnt = myStorage->getEntity(theLine.point[i]);
+        for (int j = 0; j < 2; j++) {
+          Slvs_Param aParam = myStorage->getParameter(aPnt.param[j]);
+          aCoords[2*i+j] = aParam.val;
+        }
+      }
+      double aLength = sqrt((aCoords[2] - aCoords[0]) * (aCoords[2] - aCoords[0]) + 
+                            (aCoords[3] - aCoords[1]) * (aCoords[3] - aCoords[1]));
+      // fix line length
+      Slvs_Constraint aDistance = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(),
+          SLVS_C_PT_PT_DISTANCE, myGroup->getWorkplaneId(), aLength,
+          theLine.point[0], theLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
+      aDistance.h = myStorage->addConstraint(aDistance);
+      mySlvsConstraints.push_back(aDistance.h);
+    }
+    return;
+  }
+  else if (isUsedInEqual(theLine, anEqual)) {
     // Check another entity of Equal is already fixed
     Slvs_hEntity anOtherEntID = anEqual.entityA == theLine.h ? anEqual.entityB : anEqual.entityA;
     if (myStorage->isEntityFixed(anOtherEntID, true)) {
@@ -352,3 +381,15 @@ bool SketchSolver_ConstraintRigid::isUsedInEqual(
   return false;
 }
 
+bool SketchSolver_ConstraintRigid::isAxisParallel(const Slvs_Entity& theEntity) const
+{
+  std::list<Slvs_Constraint> aConstr = myStorage->getConstraintsByType(SLVS_C_HORIZONTAL);
+  std::list<Slvs_Constraint> aVert = myStorage->getConstraintsByType(SLVS_C_VERTICAL);
+  aConstr.insert(aConstr.end(), aVert.begin(), aVert.end());
+
+  std::list<Slvs_Constraint>::const_iterator anIter = aConstr.begin();
+  for (; anIter != aConstr.end(); anIter++)
+    if (anIter->entityA == theEntity.h)
+      return true;
+  return false;
+}
index 4cde524793f1161767233c140efd1f403a023941..1fcb896e1b6d2d568fe078d8403aa1fc0c43be11 100644 (file)
@@ -67,6 +67,9 @@ private:
   /// \return \c true, if the Equal constrait is found
   bool isUsedInEqual(const Slvs_Entity& theEntity, Slvs_Constraint& theEqual) const;
 
+  /// \brief Check the entity is horizontal of vertical
+  bool isAxisParallel(const Slvs_Entity& theEntity) const;
+
 protected:
   FeaturePtr myBaseFeature; ///< fixed feature (when it is set, myBaseConstraint should be NULL)
 };
index 5479601f9f74e45b9e6b3307a20a2b2ffc37034a..a7f8d5b4801a50a90785797741ac02d5f0a4cc0f 100644 (file)
@@ -180,7 +180,8 @@ bool SketchSolver_Group::changeConstraint(
   if (!theConstraint)
     return false;
 
-  if (myConstraints.find(theConstraint) == myConstraints.end()) {
+  bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end();
+  if (isNewConstraint) {
     // Add constraint to the current group
     SolverConstraintPtr aConstraint =
         SketchSolver_Builder::getInstance()->createConstraint(theConstraint);
@@ -216,7 +217,7 @@ bool SketchSolver_Group::changeConstraint(
     myConstraints[theConstraint]->update();
 
   // Fix base features for fillet
-  if (theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) {
+  if (isNewConstraint && theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) {
     std::list<AttributePtr> anAttrList =
         theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
     std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
index 857c634d4e72bc23a216696fd391c166d2f5b9f7..1d5a8332d882f8a59259e275af2b74e57080e417 100644 (file)
@@ -347,9 +347,11 @@ bool SketchSolver_Storage::isEntityFixed(const Slvs_hEntity& theEntityID, bool t
             return true;
         }
     }
-    // 2. The line is used in Parallel/Perpendicular and Length constraints
+    // 2. The line is used in Parallel/Perpendicular/Vertical/Horizontal and Length constraints
     aList = getConstraintsByType(SLVS_C_PARALLEL);
     aList.splice(aList.end(), getConstraintsByType(SLVS_C_PERPENDICULAR));
+    aList.splice(aList.end(), getConstraintsByType(SLVS_C_VERTICAL));
+    aList.splice(aList.end(), getConstraintsByType(SLVS_C_HORIZONTAL));
     for (anIt = aList.begin(); anIt != aList.end(); anIt++)
       if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
         Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;