]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update constraints defined by parameters (issue #976)
authorazv <azv@opencascade.com>
Tue, 15 Sep 2015 10:31:37 +0000 (13:31 +0300)
committerazv <azv@opencascade.com>
Tue, 15 Sep 2015 10:32:20 +0000 (13:32 +0300)
src/SketchSolver/SketchSolver_ConstraintParametric.cpp
src/SketchSolver/SketchSolver_ConstraintParametric.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 29147d76ffcbf212c3fb7a2e8192ce1773c65d46..d730429660ad215a68a0b83dc6b5e484b83ed49b 100644 (file)
@@ -35,47 +35,33 @@ void SketchSolver_ConstraintParametric::process()
     return;
   if (!aPoint->textX().empty()) {
     // Create vertical line with fixed boundary point
-    Slvs_Param aParX = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), aPoint->x());
-    Slvs_Param aParY = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), -10000.0);
-    aParX.h = myStorage->addParameter(aParX);
-    aParY.h = myStorage->addParameter(aParY);
-    Slvs_Entity aStartPoint = Slvs_MakePoint2d(SLVS_E_UNKNOWN, myGroup->getId(),
-        myGroup->getWorkplaneId(), aParX.h, aParY.h);
-    aStartPoint.h = myStorage->addEntity(aStartPoint);
-    Slvs_Entity aLine = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroup->getId(),
-        myGroup->getWorkplaneId(), aStartPoint.h, anAttrID);
-    aLine.h = myStorage->addEntity(aLine);
-
-    // Fix start point
-    fixPoint(aStartPoint.h);
-    // Add vertical constraint
-    Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
+    Slvs_Entity aLine = createLine(aPoint->x(), -100.0, aPoint->x(), 100.0);
+    fixPoint(aLine.point[0]);
+    Slvs_Constraint aVertConstr = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
         SLVS_C_VERTICAL, myGroup->getWorkplaneId(), 0.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN,
         aLine.h, SLVS_E_UNKNOWN);
+    myStorage->addConstraint(aVertConstr);
+    // Place point on line
+    Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
+        SLVS_C_PT_ON_LINE, myGroup->getWorkplaneId(), 0.0, anAttrID, SLVS_E_UNKNOWN,
+        aLine.h, SLVS_E_UNKNOWN);
     aConstraint.h = myStorage->addConstraint(aConstraint);
     mySlvsConstraints.push_back(aConstraint.h);
     myVertLineID = aLine.h;
     myX = aPoint->x();
   }
   if (!aPoint->textY().empty()) {
-    // Create horizontal line with fixed boundary point
-    Slvs_Param aParX = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), -10000.0);
-    Slvs_Param aParY = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), aPoint->y());
-    aParX.h = myStorage->addParameter(aParX);
-    aParY.h = myStorage->addParameter(aParY);
-    Slvs_Entity aStartPoint = Slvs_MakePoint2d(SLVS_E_UNKNOWN, myGroup->getId(),
-        myGroup->getWorkplaneId(), aParX.h, aParY.h);
-    aStartPoint.h = myStorage->addEntity(aStartPoint);
-    Slvs_Entity aLine = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroup->getId(),
-        myGroup->getWorkplaneId(), aStartPoint.h, anAttrID);
-    aLine.h = myStorage->addEntity(aLine);
-
-    // Fix start point
-    fixPoint(aStartPoint.h);
-    // Add horizontal constraint
-    Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
+    // Create horizontal line with fixed boundary points
+    Slvs_Entity aLine = createLine(-100.0, aPoint->y(), 100.0, aPoint->y());
+    fixPoint(aLine.point[0]);
+    Slvs_Constraint aHorizConstr = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
         SLVS_C_HORIZONTAL, myGroup->getWorkplaneId(), 0.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN,
         aLine.h, SLVS_E_UNKNOWN);
+    myStorage->addConstraint(aHorizConstr);
+    // Place point on line
+    Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
+        SLVS_C_PT_ON_LINE, myGroup->getWorkplaneId(), 0.0, anAttrID, SLVS_E_UNKNOWN,
+        aLine.h, SLVS_E_UNKNOWN);
     aConstraint.h = myStorage->addConstraint(aConstraint);
     mySlvsConstraints.push_back(aConstraint.h);
     myHorizLineID = aLine.h;
@@ -164,3 +150,32 @@ void SketchSolver_ConstraintParametric::adjustConstraint()
     myY = aParY.val;
   }
 }
+
+
+Slvs_Entity SketchSolver_ConstraintParametric::createLine(
+    double theStartX, double theStartY, double theEndX, double theEndY)
+{
+  // Start point
+  Slvs_Param aParX = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), theStartX);
+  Slvs_Param aParY = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), theStartY);
+  aParX.h = myStorage->addParameter(aParX);
+  aParY.h = myStorage->addParameter(aParY);
+  Slvs_Entity aStartPoint = Slvs_MakePoint2d(SLVS_E_UNKNOWN, myGroup->getId(),
+    myGroup->getWorkplaneId(), aParX.h, aParY.h);
+  aStartPoint.h = myStorage->addEntity(aStartPoint);
+
+  // End point
+  aParX = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), theEndX);
+  aParY = Slvs_MakeParam(SLVS_E_UNKNOWN, myGroup->getId(), theEndY);
+  aParX.h = myStorage->addParameter(aParX);
+  aParY.h = myStorage->addParameter(aParY);
+  Slvs_Entity aEndPoint = Slvs_MakePoint2d(SLVS_E_UNKNOWN, myGroup->getId(),
+    myGroup->getWorkplaneId(), aParX.h, aParY.h);
+  aEndPoint.h = myStorage->addEntity(aEndPoint);
+
+  // Line
+  Slvs_Entity aLine = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroup->getId(),
+    myGroup->getWorkplaneId(), aStartPoint.h, aEndPoint.h);
+  aLine.h = myStorage->addEntity(aLine);
+  return aLine;
+}
index 61eb3e72e3e101dc8c0b6499cf8fabb9e440a923..3a25d96ff779623a286882437e64c8aa26124216 100644 (file)
@@ -44,6 +44,11 @@ protected:
   /// \brief This method is used in derived objects to check consistence of constraint.
   virtual void adjustConstraint();
 
+private:
+  /// \brief Create SolveSpace line with given coordinates
+  /// \return created line
+  Slvs_Entity createLine(double theStartX, double theStartY, double theEndX, double theEndY);
+
 private:
   AttributePtr myBaseAttribute; ///< attribute given by expression
   Slvs_hEntity myHorizLineID;   ///< identifier of horizontal line, containing the point
index 0e636f7df22c5f1e761327ced6cb5a71b9edf8d2..35f90dc7464da1d81e8f74aa9d4a26a4113556e8 100644 (file)
@@ -179,8 +179,6 @@ Slvs_hEntity SketchSolver_Group::getAttributeId(AttributePtr theAttribute) const
     return aResult;
   // Obtain regular constraints interacting with the attribute and find its ID
   std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(theAttribute);
-  if (aConstraints.empty())
-    return aResult;
   std::set<ConstraintPtr>::iterator aConstrIter = aConstraints.begin();
   for (; aConstrIter != aConstraints.end(); aConstrIter++) {
     ConstraintConstraintMap::const_iterator aCIter = myConstraints.find(*aConstrIter);
@@ -191,9 +189,14 @@ Slvs_hEntity SketchSolver_Group::getAttributeId(AttributePtr theAttribute) const
       return aResult;
   }
   // The attribute is not found, check it in the temporary constraints
-  std::set<SolverConstraintPtr>::iterator aTmpCIter = myTempConstraints.begin();
+  std::set<SolverConstraintPtr>::const_iterator aTmpCIter = myTempConstraints.begin();
   for (; aTmpCIter != myTempConstraints.end() && aResult == SLVS_E_UNKNOWN; ++aTmpCIter)
     aResult = (*aTmpCIter)->getId(theAttribute);
+  // Last chance to find attribute in parametric constraints
+  std::map<AttributePtr, SolverConstraintPtr>::const_iterator aParIter =
+      myParametricConstraints.find(theAttribute);
+  if (aParIter != myParametricConstraints.end())
+    aResult = aParIter->second->getId(theAttribute);
   return aResult;
 }
 
@@ -376,16 +379,27 @@ bool SketchSolver_Group::updateFeature(std::shared_ptr<SketchPlugin_Feature> the
 
   // Search attributes of the feature in the set of parametric constraints and update them
   std::list<AttributePtr> anAttrList =
-      theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+      theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
   std::list<AttributePtr>::iterator anAttrIt = anAttrList.begin();
   for (; anAttrIt != anAttrList.end(); ++anAttrIt) {
-    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIt);
-    if (!aRefAttr || aRefAttr->isObject())
-      continue;
     std::map<AttributePtr, SolverConstraintPtr>::iterator aFound =
-        myParametricConstraints.find(aRefAttr->attr());
+        myParametricConstraints.find(*anAttrIt);
     if (aFound != myParametricConstraints.end())
       aFound->second->update();
+    else {
+      std::shared_ptr<GeomDataAPI_Point2D> aPoint =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anAttrIt);
+      if (aPoint && (!aPoint->textX().empty() || !aPoint->textY().empty())) {
+        // Create new parametric constraint
+        SolverConstraintPtr aConstraint =
+            SketchSolver_Builder::getInstance()->createParametricConstraint(*anAttrIt);
+        if (!aConstraint)
+          continue;
+        aConstraint->setGroup(this);
+        aConstraint->setStorage(myStorage);
+        myParametricConstraints[*anAttrIt] = aConstraint;
+      }
+    }
   }
   return true;
 }
@@ -714,7 +728,11 @@ bool SketchSolver_Group::isConsistent()
 // ============================================================================
 void SketchSolver_Group::removeTemporaryConstraints()
 {
+  std::set<SolverConstraintPtr>::iterator aTmpIt = myTempConstraints.begin();
+  for (; aTmpIt != myTempConstraints.end(); ++aTmpIt)
+    (*aTmpIt)->remove();
   myTempConstraints.clear();
+
   while (myStorage->numberTemporary())
     myStorage->deleteTemporaryConstraint();
   // Clean lists of removed entities in the storage
index c599c3fbba771667a9f06f28fb18be0afc3ade55..485b81565d8b36e2a9be596183def9c678c0c357 100644 (file)
@@ -718,7 +718,7 @@ void SketchSolver_Storage::initializeSolver(SketchSolver_Solver& theSolver)
     for (; anIt != aConstraints.end(); anIt++)
       if (anIt->h == myFixed) {
         aFixedPoint = anIt->ptA;
-        aConstraints.erase(anIt);
+//        aConstraints.erase(anIt);
         break;
       }
     // set dragged parameters