]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #424: Mirror is done wrong
authorazv <azv@opencascade.com>
Wed, 1 Apr 2015 09:40:16 +0000 (12:40 +0300)
committerazv <azv@opencascade.com>
Wed, 1 Apr 2015 09:40:57 +0000 (12:40 +0300)
Additional verification of arcs in mirror constraint is implemented

src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintManager.cpp

index 9b0ae4325756fb0ae42fef3ff50a45b56a89aeb7..49437e464f62542e834d443e3fee74ec5e001600 100644 (file)
@@ -745,6 +745,7 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint(
           Slvs_hParam v = changeParameter(y, aParamIter);
           Slvs_Entity aPoint = Slvs_MakePoint2d(++myEntityMaxID, myID, myWorkplane.h, u, v);
           myEntities.push_back(aPoint);
+          myEntOfConstr.push_back(true);
           aBothMiddlePoints[i] = aPoint.h;
           // additional constraint point-on-curve
           Slvs_Constraint aPonCircConstr = Slvs_MakeConstraint(
@@ -752,6 +753,7 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint(
               aPoint.h, SLVS_E_UNKNOWN, aBothArcs[i], SLVS_E_UNKNOWN);
           myConstraints.push_back(aPonCircConstr);
           myConstraintMap[theConstraint].push_back(aPonCircConstr.h);
+          aNewConstraints.push_back(aPonCircConstr.h);
         }
 
         aBaseArcPoints[2] = aBothMiddlePoints[0];
@@ -809,13 +811,48 @@ bool SketchSolver_ConstraintGroup::changeMirrorConstraint(
           std::dynamic_pointer_cast<SketchPlugin_Feature>(*aBaseIter);
       if (!aBaseFeature) continue;
       std::list<AttributePtr> aPoints = aBaseFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
-      std::list<AttributePtr>::iterator anIt = aPoints.begin();
-      for ( ; anIt != aPoints.end(); anIt++) {
+      if (aBaseFeature->getKind() != SketchPlugin_Arc::ID()) {
+        std::list<AttributePtr>::iterator anIt = aPoints.begin();
+        for ( ; anIt != aPoints.end(); anIt++) {
+          addTemporaryConstraintWhereDragged(*anIt);
+        }
+      } else {
         // Arcs are fixed by center and start points only (to avoid solving errors in SolveSpace)
-        if (aBaseFeature->getKind() == SketchPlugin_Arc::ID() &&
-            (*anIt)->id() == SketchPlugin_Arc::END_ID())
-          continue;
-        addTemporaryConstraintWhereDragged(*anIt);
+        AttributePtr aCenterAttr = aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID());
+        std::map<AttributePtr, Slvs_hEntity>::iterator aFound = myEntityAttrMap.find(aCenterAttr);
+        Slvs_hEntity anArcPoints[3] = {aFound->second, 0, 0};
+        AttributePtr aStartAttr = aBaseFeature->attribute(SketchPlugin_Arc::START_ID());
+        aFound = myEntityAttrMap.find(aStartAttr);
+        anArcPoints[1] = aFound->second;
+        AttributePtr aEndAttr = aBaseFeature->attribute(SketchPlugin_Arc::END_ID());
+        aFound = myEntityAttrMap.find(aEndAttr);
+        anArcPoints[2] = aFound->second;
+
+        bool isFixed[3] = {false, false, false};
+        int aNbFixed = 0; // number of already fixed points on the arc
+        for (int i = 0; i < 3; i++) {
+          std::vector<std::set<Slvs_hEntity> >::iterator aCoPtIter = myCoincidentPoints.begin();
+          for (; aCoPtIter != myCoincidentPoints.end() && !isFixed[i]; aCoPtIter++) {
+            if (aCoPtIter->find(anArcPoints[i]) == aCoPtIter->end())
+              continue;  // the entity was not found in current set
+
+            // Find one of already created SLVS_C_WHERE_DRAGGED constraints in current set of coincident points
+            std::vector<Slvs_Constraint>::iterator aConstrIter = myConstraints.begin();
+            for (; aConstrIter != myConstraints.end(); aConstrIter++)
+              if (aConstrIter->type == SLVS_C_WHERE_DRAGGED && 
+                  aCoPtIter->find(aConstrIter->ptA) != aCoPtIter->end()) {
+                isFixed[i] = true;
+                aNbFixed++;
+                break;  // the SLVS_C_WHERE_DRAGGED constraint already exists
+              }
+          }
+        }
+        if (aNbFixed < 2) { // append constraints
+          if (!isFixed[0])
+            addTemporaryConstraintWhereDragged(aCenterAttr);
+          if (!isFixed[1] && (isFixed[0] || aNbFixed == 0))
+            addTemporaryConstraintWhereDragged(aStartAttr);
+        }
       }
     }
   }
@@ -2143,9 +2180,16 @@ void SketchSolver_ConstraintGroup::makeMirrorEntity(const Slvs_hEntity& theBase,
   Slvs_Entity aBase = myEntities[Search(theBase, myEntities)];
   Slvs_Entity aMirror = myEntities[Search(theMirror, myEntities)];
   int i = 0;
-  while (aBase.point[i] != 0 && aMirror.point[i] != 0) {
-    makeMirrorEntity(aBase.point[i], aMirror.point[i], theMirrorLine);
-    i++;
+  if (aBase.type != SLVS_E_ARC_OF_CIRCLE) {
+    while (aBase.point[i] != 0 && aMirror.point[i] != 0) {
+      makeMirrorEntity(aBase.point[i], aMirror.point[i], theMirrorLine);
+      i++;
+    }
+  } else {
+    // swap mirroring first and last points of an arc
+    makeMirrorEntity(aBase.point[0], aMirror.point[0], theMirrorLine);
+    makeMirrorEntity(aBase.point[1], aMirror.point[2], theMirrorLine);
+    makeMirrorEntity(aBase.point[2], aMirror.point[1], theMirrorLine);
   }
   if (aBase.param[0] != 0 && aMirror.param[0] != 0) { // this is a point, copy it
     Slvs_Entity aMirrorLine = myEntities[Search(theMirrorLine, myEntities)];
index 1fafcf506b8e03cc5c2f5068d7e7f9febda211d1..bd346fb35fe35fac2343b7ff27b2600dae9c9544 100644 (file)
@@ -117,7 +117,7 @@ void SketchSolver_ConstraintManager::processEvent(
       for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
         std::shared_ptr<SketchPlugin_Feature> aFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
-        if (!aFeature || aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+        if (!aFeature /*|| aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()*/)
           continue;
         changeConstraintOrEntity(aFeature);
       }