]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Regression on line movement. Sketch solver was changed to work precisely with tempora...
authorazv <azv@opencascade.com>
Fri, 10 Oct 2014 07:23:07 +0000 (11:23 +0400)
committerazv <azv@opencascade.com>
Fri, 10 Oct 2014 07:23:07 +0000 (11:23 +0400)
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.h

index 53461bb5df161163821a7fd07c77141e89b14ef5..a675349b1d0f7fb7bf46aaa12796316772d2a4c0 100644 (file)
@@ -79,7 +79,10 @@ SketchSolver_ConstraintGroup::SketchSolver_ConstraintGroup(
   myEntities.clear();
   myEntOfConstr.clear();
   myConstraints.clear();
+
   myTempConstraints.clear();
+  myTempPointWhereDragged.clear();
+  myTempPointWDrgdID = 0;
 
   // Initialize workplane
   myWorkplane.h = SLVS_E_UNKNOWN;
@@ -98,6 +101,7 @@ SketchSolver_ConstraintGroup::~SketchSolver_ConstraintGroup()
   myConstraints.clear();
   myConstraintMap.clear();
   myTempConstraints.clear();
+  myTempPointWhereDragged.clear();
 
   // If the group with maximal identifier is deleted, decrease the indexer
   if (myID == myGroupIndexer)
@@ -410,7 +414,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
 
   // If the attribute was changed by the user, we need to fix it before solving
   if (myNeedToSolve && theEntity->isImmutable())
-    addTemporaryConstraintWhereDragged(theEntity);
+    addTemporaryConstraintWhereDragged(theEntity, false);
 
   return aResult;
 }
@@ -647,6 +651,7 @@ bool SketchSolver_ConstraintGroup::resolveConstraints()
   myConstrSolver.setParameters(myParams);
   myConstrSolver.setEntities(myEntities);
   myConstrSolver.setConstraints(myConstraints);
+  myConstrSolver.setDraggedParameters(myTempPointWhereDragged);
 
   int aResult = myConstrSolver.solve();
   if (aResult == SLVS_RESULT_OKAY) {  // solution succeeded, store results into correspondent attributes
@@ -698,6 +703,18 @@ void SketchSolver_ConstraintGroup::mergeGroups(const SketchSolver_ConstraintGrou
       myTempConstraints.push_back(aFind->second);
   }
 
+  if (myTempPointWhereDragged.empty())
+    myTempPointWhereDragged = theGroup.myTempPointWhereDragged;
+  else if (!theGroup.myTempPointWhereDragged.empty()) {  // Need to create additional transient constraint
+    std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator aFeatureIter =
+        theGroup.myEntityAttrMap.begin();
+    for (; aFeatureIter != theGroup.myEntityAttrMap.end(); aFeatureIter++)
+      if (aFeatureIter->second == myTempPointWDrgdID) {
+        addTemporaryConstraintWhereDragged(aFeatureIter->first);
+        break;
+      }
+  }
+
   myNeedToSolve = myNeedToSolve || theGroup.myNeedToSolve;
 }
 
@@ -993,7 +1010,8 @@ void SketchSolver_ConstraintGroup::updateEntityIfPossible(
 //            which was moved by user
 // ============================================================================
 void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
-    boost::shared_ptr<ModelAPI_Attribute> theEntity)
+    boost::shared_ptr<ModelAPI_Attribute> theEntity,
+    bool theAllowToFit)
 {
   // Find identifier of the entity
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator anEntIter =
@@ -1001,8 +1019,21 @@ void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged(
   if (anEntIter == myEntityAttrMap.end())
     return;
 
+  // If this is a first dragged point, its parameters should be placed 
+  // into Slvs_System::dragged field to avoid system inconsistense
+  if (myTempPointWhereDragged.empty() && theAllowToFit) {
+    int anEntPos = Search(anEntIter->second, myEntities);
+    Slvs_hParam* aDraggedParam = myEntities[anEntPos].param;
+    for (int i = 0; i < 4; i++, aDraggedParam++)
+      if (*aDraggedParam != 0)
+        myTempPointWhereDragged.push_back(*aDraggedParam);
+    myTempPointWDrgdID = myEntities[anEntPos].h;
+    return;
+  }
+
   // Get identifiers of all dragged points
   std::set<Slvs_hEntity> aDraggedPntID;
+  aDraggedPntID.insert(myTempPointWDrgdID);
   std::list<Slvs_hConstraint>::iterator aTmpCoIter = myTempConstraints.begin();
   for (; aTmpCoIter != myTempConstraints.end(); aTmpCoIter++) {
     unsigned int aConstrPos = Search(*aTmpCoIter, myConstraints);
@@ -1050,6 +1081,10 @@ void SketchSolver_ConstraintGroup::removeTemporaryConstraints()
       myConstrMaxID--;
   }
   myTempConstraints.clear();
+
+  // Clear basic dragged point
+  myTempPointWhereDragged.clear();
+  myTempPointWDrgdID = SLVS_E_UNKNOWN;
 }
 
 // ============================================================================
index f6f450f26a2c89b6a1aee57a3e612937b52a4249..f8258f90f05095afe792a0f2db35fc65b546acd1 100644 (file)
@@ -165,9 +165,13 @@ protected:
                        const Slvs_hEntity& theEntityID);
 
   /** \brief Adds a constraint for a point which should not be changed during computations
-   *  \param[in] theEntity the base for the constraint
+   *  \param[in] theEntity     the base for the constraint
+   *  \param[in] theAllowToFit this flag shows that the entity may be placed into 
+   *                           the 'dragged' field of SolveSpace solver, so this entity 
+   *                           may be changed a little during solution
    */
-  void addTemporaryConstraintWhereDragged(boost::shared_ptr<ModelAPI_Attribute> theEntity);
+  void addTemporaryConstraintWhereDragged(boost::shared_ptr<ModelAPI_Attribute> theEntity,
+                                          bool theAllowToFit = true);
 
   /** \brief Remove all temporary constraint after computation finished
    */
@@ -209,6 +213,8 @@ protected:
 
   SketchSolver_Solver myConstrSolver;  ///< Solver for set of equations obtained by constraints
 
+  std::vector<Slvs_hParam> myTempPointWhereDragged;  ///< Parameters of one of the points which is moved by user
+  Slvs_hEntity myTempPointWDrgdID;      ///< Identifier of such point
   std::list<Slvs_hConstraint> myTempConstraints;  ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user
 
   // SketchPlugin entities