]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix conflict on middle-point constraint when the point is already on the line (issue...
authorazv <azv@opencascade.com>
Thu, 3 Mar 2016 11:59:04 +0000 (14:59 +0300)
committerazv <azv@opencascade.com>
Thu, 3 Mar 2016 11:59:51 +0000 (14:59 +0300)
src/SketchSolver/CMakeLists.txt
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.h
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp
src/SketchSolver/SketchSolver_Builder.cpp
src/SketchSolver/SketchSolver_ConstraintMiddle.cpp [new file with mode: 0644]
src/SketchSolver/SketchSolver_ConstraintMiddle.h [new file with mode: 0644]
src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp

index b2eb5473852d5c464dc5cd6f91822e05421a5bbe..ac4117627f2fa573e001bc6f34558a5b52675edd 100644 (file)
@@ -12,6 +12,7 @@ SET(PROJECT_HEADERS
     SketchSolver_ConstraintDistance.h
     SketchSolver_ConstraintEqual.h
     SketchSolver_ConstraintLength.h
+    SketchSolver_ConstraintMiddle.h
     SketchSolver_ConstraintMirror.h
     SketchSolver_ConstraintFixed.h
     SketchSolver_ConstraintFixedArcRadius.h
@@ -38,6 +39,7 @@ SET(PROJECT_SOURCES
     SketchSolver_ConstraintDistance.cpp
     SketchSolver_ConstraintEqual.cpp
     SketchSolver_ConstraintLength.cpp
+    SketchSolver_ConstraintMiddle.cpp
     SketchSolver_ConstraintMirror.cpp
     SketchSolver_ConstraintFixed.cpp
     SketchSolver_ConstraintFixedArcRadius.cpp
index db2972db1b4e3da837947fd2da7564470bed7e00..ebf65ea657852ec52b2db754b28f020f6f030fde 100644 (file)
@@ -28,6 +28,9 @@ public:
   /// \brief Return list of constraints
   const std::list<GCSConstraintPtr>& constraints() const
   { return myGCSConstraints; }
+  /// \brief Change list of constraints
+  void setConstraints(const std::list<GCSConstraintPtr>& theConstraints)
+  { myGCSConstraints = theConstraints; }
 
   /// \brief Return ID of current entity
   virtual ConstraintID id() const
index b79fd0dc8f031435bfd698ecdaa92802fb24e852..3e9b00b7588fbdb3fee5610dc6a964e1ba0fa721 100644 (file)
@@ -67,9 +67,45 @@ bool PlaneGCSSolver_Storage::update(ConstraintWrapperPtr theConstraint)
   for (; anIt != anEntities.end(); ++anIt)
     isUpdated = update(*anIt) || isUpdated;
 
-  // Change ID of constraints
-  if (aConstraint->id() == CID_UNKNOWN)
+  if (aConstraint->id() == CID_UNKNOWN) {
+    const std::list<EntityWrapperPtr>& aSubs = aConstraint->entities();
+    // check middle-point constraint conflicts with point-on-line
+    if (aConstraint->type() == CONSTRAINT_MIDDLE_POINT) {
+      std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
+          anIt = myConstraintMap.begin();
+      for (; anIt != myConstraintMap.end(); ++anIt) {
+        EntityWrapperPtr aPoint, aLine;
+        ConstraintWrapperPtr aCurrentConstr = anIt->second.front();
+        if (aCurrentConstr->type() != CONSTRAINT_PT_ON_LINE)
+          continue;
+        const std::list<EntityWrapperPtr>& aCurSubs = aCurrentConstr->entities();
+        std::list<EntityWrapperPtr>::const_iterator aSIt1, aSIt2;
+        for (aSIt1 = aSubs.begin(); aSIt1 != aSubs.end(); ++aSIt1) {
+          if ((*aSIt1)->type() == ENTITY_POINT)
+            aPoint = *aSIt1;
+          else if((*aSIt1)->type() == ENTITY_LINE)
+            aLine = *aSIt1;
+          else
+            continue;
+          for (aSIt2 = aCurSubs.begin(); aSIt2 != aCurSubs.end(); ++aSIt2)
+            if ((*aSIt1)->id() == (*aSIt2)->id())
+              break;
+          if (aSIt2 == aCurSubs.end())
+            break;
+        }
+        // point-on-line found, change it to bisector
+        if (aSIt1 == aSubs.end()) {
+          std::list<GCSConstraintPtr> aConstrList = aConstraint->constraints();
+          aConstrList.pop_front();
+          aConstraint->setConstraints(aConstrList);
+          break;
+        }
+      }
+    }
+
+    // Change ID of constraints
     aConstraint->setId(++myConstraintLastID);
+  }
 
   return isUpdated;
 }
index 4709e683388b2b7acb4c035ef31ce48c683a71be..ba7074e50c5447f3f292ef5b604a128de2c56f51 100644 (file)
@@ -14,6 +14,7 @@
 #include <SketchSolver_ConstraintFixed.h>
 #include <SketchSolver_ConstraintFixedArcRadius.h>
 #include <SketchSolver_ConstraintLength.h>
+#include <SketchSolver_ConstraintMiddle.h>
 #include <SketchSolver_ConstraintMirror.h>
 #include <SketchSolver_ConstraintTangent.h>
 #include <SketchSolver_ConstraintMultiRotation.h>
@@ -33,6 +34,7 @@
 #include <SketchPlugin_ConstraintDistance.h>
 #include <SketchPlugin_ConstraintEqual.h>
 #include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintMiddle.h>
 #include <SketchPlugin_ConstraintMirror.h>
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_ConstraintTangent.h>
@@ -87,6 +89,8 @@ SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theCons
     return SolverConstraintPtr(new SketchSolver_ConstraintEqual(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintLength(theConstraint));
+  } else if (theConstraint->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
+    return SolverConstraintPtr(new SketchSolver_ConstraintMiddle(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintMirror(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID()) {
diff --git a/src/SketchSolver/SketchSolver_ConstraintMiddle.cpp b/src/SketchSolver/SketchSolver_ConstraintMiddle.cpp
new file mode 100644 (file)
index 0000000..826a429
--- /dev/null
@@ -0,0 +1,41 @@
+#include <SketchSolver_ConstraintMiddle.h>
+
+SketchSolver_ConstraintMiddle::SketchSolver_ConstraintMiddle(ConstraintPtr theConstraint)
+  : SketchSolver_Constraint(theConstraint)
+{
+}
+
+void SketchSolver_ConstraintMiddle::notifyCoincidenceChanged(
+    EntityWrapperPtr theCoincAttr1,
+    EntityWrapperPtr theCoincAttr2)
+{
+  // Check the coincidence between point and line has been changed
+  AttributePtr aPoint;
+  FeaturePtr aLine;
+  EntityWrapperPtr anEntities[2] = {theCoincAttr1, theCoincAttr2};
+  for (int i = 0; i < 2; ++i) {
+    if (anEntities[i]->type() == ENTITY_POINT)
+      aPoint = anEntities[i]->baseAttribute();
+    else if (anEntities[i]->type() == ENTITY_LINE)
+      aLine = anEntities[i]->baseFeature();
+  }
+  if (!aPoint || !aLine)
+    return;
+
+  // Check the attributes of middle-point constraint are the same point and line
+  bool isSameAttr = true;
+  for (int i = 0; i < 2 && isSameAttr; ++i) {
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(i)));
+    if (aRefAttr->isObject()) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+      isSameAttr = (aFeature == aLine);
+    } else
+      isSameAttr = (aRefAttr->attr() == aPoint);
+  }
+
+  if (isSameAttr) {
+    remove();
+    process();
+  }
+}
diff --git a/src/SketchSolver/SketchSolver_ConstraintMiddle.h b/src/SketchSolver/SketchSolver_ConstraintMiddle.h
new file mode 100644 (file)
index 0000000..b86e714
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:    SketchSolver_ConstraintMiddle.h
+// Created: 03 March 2016
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchSolver_ConstraintMiddle_H_
+#define SketchSolver_ConstraintMiddle_H_
+
+#include <SketchSolver_Constraint.h>
+
+/** \class   SketchSolver_ConstraintMiddle
+ *  \ingroup Plugins
+ *  \brief   Converts middle-point constraint to the constraint applicable for solver
+ */
+class SketchSolver_ConstraintMiddle : public SketchSolver_Constraint
+{
+public:
+  /// Constructor based on SketchPlugin constraint
+  SKETCHSOLVER_EXPORT SketchSolver_ConstraintMiddle(ConstraintPtr theConstraint);
+
+  virtual ~SketchSolver_ConstraintMiddle() {}
+
+  /// \brief Notify constraint, that coincidence appears or removed
+  virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2);
+};
+
+#endif
index c1bd90b6eacd17034dc756cf8325dc70701cfc7e..d796f7964206c4a6598a9f7dab289f2ac8724ad1 100644 (file)
@@ -798,6 +798,29 @@ Slvs_hConstraint SolveSpaceSolver_Storage::updateConstraint(const Slvs_Constrain
   // Constraint is not found, add new one
   Slvs_Constraint aConstraint = theConstraint;
   aConstraint.h = 0;
+
+  // Firstly, check middle-point constraint conflicts with point-on-line
+  if (aConstraint.type == SLVS_C_AT_MIDPOINT) {
+    std::vector<Slvs_Constraint>::const_iterator anIt = myConstraints.begin();
+    for (; anIt != myConstraints.end(); ++anIt)
+      if (anIt->type == SLVS_C_PT_ON_LINE &&
+          anIt->ptA == aConstraint.ptA &&
+          anIt->entityA == aConstraint.entityA)
+        break;
+    if (anIt != myConstraints.end()) {
+      // change the constraint to the lengths equality to avoid conflicts
+      Slvs_Entity aLine = getEntity(aConstraint.entityA);
+      Slvs_Entity aNewLine1 = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroupID,
+          myWorkplaneID, aLine.point[0], aConstraint.ptA);
+      aNewLine1.h = addEntity(aNewLine1);
+      Slvs_Entity aNewLine2 = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, myGroupID,
+          myWorkplaneID, aLine.point[1], aConstraint.ptA);
+      aNewLine2.h = addEntity(aNewLine2);
+      aConstraint = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroupID, SLVS_C_EQUAL_LENGTH_LINES,
+          myWorkplaneID, 0.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, aNewLine1.h, aNewLine2.h);
+    }
+  }
+
   return addConstraint(aConstraint);
 }