]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
SketchSolver library refactoring
authorazv <azv@opencascade.com>
Tue, 31 Mar 2015 15:54:47 +0000 (18:54 +0300)
committerazv <azv@opencascade.com>
Fri, 3 Apr 2015 06:26:38 +0000 (09:26 +0300)
1. Implemented Radius constraint
2. Implemented Equal constraint
3. Implemented Tangent constraint

15 files changed:
src/SketchSolver/CMakeLists.txt
src/SketchSolver/SketchSolver_Builder.cpp
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_Constraint.h
src/SketchSolver/SketchSolver_ConstraintEqual.cpp [new file with mode: 0644]
src/SketchSolver/SketchSolver_ConstraintEqual.h [new file with mode: 0644]
src/SketchSolver/SketchSolver_ConstraintLength.h
src/SketchSolver/SketchSolver_ConstraintTangent.cpp [new file with mode: 0644]
src/SketchSolver/SketchSolver_ConstraintTangent.h [new file with mode: 0644]
src/SketchSolver/SketchSolver_Error.h
src/SketchSolver/SketchSolver_FeatureStorage.cpp
src/SketchSolver/SketchSolver_FeatureStorage.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp
src/SketchSolver/SketchSolver_Storage.h

index 334ee0451d2af19c1dc983d0c5a43e32627909f7..bc1b78af75a0a39d5ab2d766aded967c4181a16a 100644 (file)
@@ -10,8 +10,10 @@ SET(PROJECT_HEADERS
     SketchSolver_Constraint.h
     SketchSolver_ConstraintCoincidence.h
     SketchSolver_ConstraintDistance.h
+    SketchSolver_ConstraintEqual.h
     SketchSolver_ConstraintLength.h
     SketchSolver_ConstraintRigid.h
+    SketchSolver_ConstraintTangent.h
     SketchSolver_Builder.h
     SketchSolver_Group.h
     SketchSolver_ConstraintManager.h
@@ -24,8 +26,10 @@ SET(PROJECT_SOURCES
     SketchSolver_Constraint.cpp
     SketchSolver_ConstraintCoincidence.cpp
     SketchSolver_ConstraintDistance.cpp
+    SketchSolver_ConstraintEqual.cpp
     SketchSolver_ConstraintLength.cpp
     SketchSolver_ConstraintRigid.cpp
+    SketchSolver_ConstraintTangent.cpp
     SketchSolver_Builder.cpp
     SketchSolver_Group.cpp
     SketchSolver_ConstraintManager.cpp
index 4f0d05ab11b06196a0b7eafdba20453ce7248090..6bf3a61c080d5ec4df21cc309e17d897512e9fac 100644 (file)
@@ -7,8 +7,10 @@
 #include "SketchSolver_Builder.h"
 #include <SketchSolver_ConstraintCoincidence.h>
 #include <SketchSolver_ConstraintDistance.h>
+#include <SketchSolver_ConstraintEqual.h>
 #include <SketchSolver_ConstraintLength.h>
 #include <SketchSolver_ConstraintRigid.h>
+#include <SketchSolver_ConstraintTangent.h>
 
 #include <GeomAPI_Edge.h>
 #include <GeomDataAPI_Dir.h>
@@ -61,7 +63,7 @@ SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theCons
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintDistance(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintEqual::ID()) {
-////    return SolverConstraintPtr(new SketchSolver_ConstraintEqual(theConstraint));
+    return SolverConstraintPtr(new SketchSolver_ConstraintEqual(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) {
 ////    return SolverConstraintPtr(new SketchSolver_ConstraintFillet(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintHorizontal::ID()) {
@@ -75,9 +77,9 @@ SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theCons
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintPerpendicular::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintPerpendicular(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintRadius::ID()) {
-////    return SolverConstraintPtr(new SketchSolver_ConstraintRadius(theConstraint));
+    return SolverConstraintPtr(new SketchSolver_ConstraintRadius(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID()) {
-////    return SolverConstraintPtr(new SketchSolver_ConstraintTangent(theConstraint));
+    return SolverConstraintPtr(new SketchSolver_ConstraintTangent(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintVertical::ID()) {
     return SolverConstraintPtr(new SketchSolver_ConstraintVertical(theConstraint));
   } else if (theConstraint->getKind() == SketchPlugin_ConstraintRigid::ID()) {
index 2cdd24eb796e3840682658844ca98449624b604f..c382cdeb30e86ec4d051643104d75e95ec23aeec 100644 (file)
@@ -160,6 +160,8 @@ bool SketchSolver_Constraint::remove(ConstraintPtr theConstraint)
   cleanErrorMsg();
   if (theConstraint && theConstraint != myBaseConstraint)
     return false;
+  if (mySlvsConstraints.empty())
+    return true;
   bool isFullyRemoved = myStorage->removeConstraint(mySlvsConstraints.front());
   if (isFullyRemoved) {
     myFeatureMap.clear();
index 6a57f6b2182def8f4382a7d02a3a602f509bbc3f..3640d881dc89eb1d012caa6b278ba919f78cbbae 100644 (file)
@@ -177,4 +177,27 @@ public:
   { return SLVS_C_VERTICAL; }
 };
 
+
+/** \class   SketchSolver_ConstraintRadius
+ *  \ingroup Plugins
+ *  \brief   Convert Radius constraint to SolveSpace structure
+ */
+class SketchSolver_ConstraintRadius : public SketchSolver_Constraint
+{
+public:
+  SketchSolver_ConstraintRadius(ConstraintPtr theConstraint) :
+      SketchSolver_Constraint(theConstraint)
+  {}
+
+  virtual int getType() const
+  { return SLVS_C_DIAMETER; }
+
+  virtual void adjustConstraint()
+  {
+    Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
+    aConstraint.valA *= 2.0;
+    myStorage->updateConstraint(aConstraint);
+  }
+};
+
 #endif
diff --git a/src/SketchSolver/SketchSolver_ConstraintEqual.cpp b/src/SketchSolver/SketchSolver_ConstraintEqual.cpp
new file mode 100644 (file)
index 0000000..23ff404
--- /dev/null
@@ -0,0 +1,62 @@
+#include <SketchSolver_ConstraintEqual.h>
+#include <SketchSolver_Group.h>
+#include <SketchSolver_Error.h>
+
+
+void SketchSolver_ConstraintEqual::process()
+{
+  cleanErrorMsg();
+  if (!myBaseConstraint || !myStorage || myGroup == 0) {
+    /// TODO: Put error message here
+    return;
+  }
+  if (!mySlvsConstraints.empty()) // some data is changed, update constraint
+    update(myBaseConstraint);
+
+  double aValue;
+  std::vector<Slvs_hEntity> anEntities;
+  getAttributes(aValue, anEntities);
+  if (!myErrorMsg.empty())
+    return;
+
+  // Check the quantity of entities of each type
+  int aNbLines = 0;
+  int aNbArcs = 0;
+  int aNbCircs = 0;
+  std::vector<Slvs_hEntity>::iterator anEntIter = anEntities.begin();
+  for (; anEntIter != anEntities.end(); anEntIter++) {
+    Slvs_Entity anEnt = myStorage->getEntity(*anEntIter);
+    if (anEnt.type == SLVS_E_LINE_SEGMENT)
+      aNbLines++;
+    else if (anEnt.type == SLVS_E_CIRCLE)
+      aNbCircs++;
+    else if (anEnt.type == SLVS_E_ARC_OF_CIRCLE)
+      aNbArcs++;
+  }
+
+  if (aNbLines + aNbArcs + aNbCircs != 2 ||
+      (aNbLines == aNbCircs && aNbArcs == 0)) {
+    myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
+    return;
+  }
+
+  switch (aNbLines) {
+  case 0:
+    myType = SLVS_C_EQUAL_RADIUS;
+    break;
+  case 1:
+    myType = SLVS_C_EQUAL_LINE_ARC_LEN;
+    break;
+  default:
+    myType = SLVS_C_EQUAL_LENGTH_LINES;
+    break;
+  }
+
+  Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
+      getType(), myGroup->getWorkplaneId(), aValue,
+      anEntities[0], anEntities[1], anEntities[2], anEntities[3]);
+  aConstraint.h = myStorage->addConstraint(aConstraint);
+  mySlvsConstraints.push_back(aConstraint.h);
+  adjustConstraint();
+}
+
diff --git a/src/SketchSolver/SketchSolver_ConstraintEqual.h b/src/SketchSolver/SketchSolver_ConstraintEqual.h
new file mode 100644 (file)
index 0000000..c484779
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:    SketchSolver_ConstraintEqual.h
+// Created: 1 Apr 2015
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchSolver_ConstraintEqual_H_
+#define SketchSolver_ConstraintEqual_H_
+
+#include "SketchSolver.h"
+#include <SketchSolver_Constraint.h>
+
+/** \class   SketchSolver_ConstraintEqual
+ *  \ingroup Plugins
+ *  \brief   Convert equality constraint to SolveSpace structure
+ */
+class SketchSolver_ConstraintEqual : public SketchSolver_Constraint
+{
+public:
+  SketchSolver_ConstraintEqual(ConstraintPtr theConstraint) :
+      SketchSolver_Constraint(theConstraint)
+  {}
+
+  virtual int getType() const
+  { return myType; }
+
+protected:
+  /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
+  virtual void process();
+
+private:
+  int myType; ///< type of constraint (applicable: SLVS_C_EQUAL_LENGTH_LINES, SLVS_C_EQUAL_RADIUS, SLVS_C_EQUAL_LINE_ARC_LEN)
+};
+
+#endif
index 176c6948eaca97e02e8e45c5d68cc5e323082439..5d0583752c2dd4634de75fd37299732a3e992e66 100644 (file)
@@ -27,9 +27,6 @@ public:
 protected:
   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
   virtual void process();
-
-private:
-  int myType; ///< type of constraint (applicable: SLVS_C_PT_PT_DISTANCE, SLVS_C_PT_LINE_DISTANCE)
 };
 
 #endif
diff --git a/src/SketchSolver/SketchSolver_ConstraintTangent.cpp b/src/SketchSolver/SketchSolver_ConstraintTangent.cpp
new file mode 100644 (file)
index 0000000..37b59fa
--- /dev/null
@@ -0,0 +1,84 @@
+#include <SketchSolver_ConstraintTangent.h>
+#include <SketchSolver_Group.h>
+#include <SketchSolver_Error.h>
+
+
+void SketchSolver_ConstraintTangent::process()
+{
+  cleanErrorMsg();
+  if (!myBaseConstraint || !myStorage || myGroup == 0) {
+    /// TODO: Put error message here
+    return;
+  }
+  if (!mySlvsConstraints.empty()) // some data is changed, update constraint
+    update(myBaseConstraint);
+
+  double aValue;
+  std::vector<Slvs_hEntity> anEntID;
+  getAttributes(aValue, anEntID);
+  if (!myErrorMsg.empty())
+    return;
+  // Check the quantity of entities of each type and their order (arcs first)
+  int aNbLines = 0;
+  int aNbArcs = 0;
+  Slvs_Entity anEntities[2];
+  myType = SLVS_C_CURVE_CURVE_TANGENT;
+  std::vector<Slvs_hEntity>::iterator anEntIter = anEntID.begin();
+  for (; anEntIter != anEntID.end(); anEntIter++) {
+    Slvs_Entity anEnt = myStorage->getEntity(*anEntIter);
+    if (anEnt.type == SLVS_E_LINE_SEGMENT) {
+      if (aNbLines == 0)
+        anEntities[1 + aNbLines] = anEnt;
+      aNbLines++;
+      myType = SLVS_C_ARC_LINE_TANGENT;
+    }
+    else if (anEnt.type == SLVS_E_ARC_OF_CIRCLE) {
+      if (aNbArcs < 2)
+        anEntities[aNbArcs] = anEnt;
+      aNbArcs++;
+    }
+  }
+
+  if (aNbLines + aNbArcs != 2) {
+    myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
+    return;
+  } else if (aNbArcs < 1) {
+    myErrorMsg = SketchSolver_Error::INCORRECT_TANGENCY_ATTRIBUTE();
+    return;
+  }
+
+  // It is necessary to identify which points of entities are coincident
+  int aSlvsOtherFlag = 0;
+  int aSlvsOther2Flag = 0;
+  // Obtain start and end points of entities
+  Slvs_hEntity aPointsToFind[4];
+  for (int i = 0; i < 2; i++) {
+    int aShift = anEntities[i].type == SLVS_E_ARC_OF_CIRCLE ? 1 : 0;
+    aPointsToFind[2*i]  = anEntities[i].point[aShift];
+    aPointsToFind[2*i+1]= anEntities[i].point[aShift+1];
+  }
+  // Search coincident points
+  bool isPointFound = false;
+  for (int i = 0; i < 2 && !isPointFound; i++)
+    for (int j = 2; j < 4 && !isPointFound; j++)
+      if (myStorage->isCoincident(aPointsToFind[i], aPointsToFind[j])) {
+        aSlvsOtherFlag = i;
+        aSlvsOther2Flag = j - 2;
+        isPointFound = true;
+      }
+  if (!isPointFound) {
+    // There is no coincident points between tangential objects. Generate error message
+    myErrorMsg = SketchSolver_Error::NO_COINCIDENT_POINTS();
+    return;
+  }
+
+  Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, myGroup->getId(),
+      getType(), myGroup->getWorkplaneId(), aValue,
+      SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, anEntities[0].h, anEntities[1].h);
+  aConstraint.other = aSlvsOtherFlag;
+  aConstraint.other2 = aSlvsOther2Flag;
+  aConstraint.h = myStorage->addConstraint(aConstraint);
+  mySlvsConstraints.push_back(aConstraint.h);
+  adjustConstraint();
+}
+
diff --git a/src/SketchSolver/SketchSolver_ConstraintTangent.h b/src/SketchSolver/SketchSolver_ConstraintTangent.h
new file mode 100644 (file)
index 0000000..7f7e30d
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:    SketchSolver_ConstraintTangent.h
+// Created: 1 Apr 2015
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchSolver_ConstraintTangent_H_
+#define SketchSolver_ConstraintTangent_H_
+
+#include "SketchSolver.h"
+#include <SketchSolver_Constraint.h>
+
+/** \class   SketchSolver_ConstraintTangent
+ *  \ingroup Plugins
+ *  \brief   Convert tangency constraint to SolveSpace structure
+ */
+class SketchSolver_ConstraintTangent : public SketchSolver_Constraint
+{
+public:
+  SketchSolver_ConstraintTangent(ConstraintPtr theConstraint) :
+      SketchSolver_Constraint(theConstraint)
+  {}
+
+  virtual int getType() const
+  { return myType; }
+
+protected:
+  /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
+  virtual void process();
+
+private:
+  int myType; ///< type of constraint (applicable: SLVS_C_ARC_LINE_TANGENT, SLVS_C_CURVE_CURVE_TANGENT)
+};
+
+#endif
index dfae098bf8b1f14bda7fe20eac86ab4e8094deb3..b05cb554e79993a169246adacc891df6d4ab0136 100644 (file)
@@ -41,6 +41,12 @@ class SketchSolver_Error
     static const std::string MY_ERROR_VALUE("Incorrect attribute");
     return MY_ERROR_VALUE;
   }
+  /// Tangency constraint has wrong attributes
+  inline static const std::string& INCORRECT_TANGENCY_ATTRIBUTE()
+  {
+    static const std::string MY_ERROR_VALUE("An arc should be an attribute of tangency constraint");
+    return MY_ERROR_VALUE;
+  }
 };
 
 #endif
index 9b8f133f494c571cead0076659a4cfaba5ee486c..5e112078dc5162e54fc6ee49e41d521aaf0461ff 100644 (file)
@@ -313,11 +313,11 @@ bool SketchSolver_FeatureStorage::isConsistent() const
   for (; aFIter != myFeatures.end(); aFIter++)
     if (!aFIter->first->data() || !aFIter->first->data()->isValid())
       return false;
-  // Check the attributes are valid
-  MapAttributeFeature::const_iterator aTIter = myAttributes.begin();
-  for (; aTIter != myAttributes.end(); aTIter++)
-    if (!aTIter->first->isInitialized())
-      return false;
+////  // Check the attributes are valid
+////  MapAttributeFeature::const_iterator aTIter = myAttributes.begin();
+////  for (; aTIter != myAttributes.end(); aTIter++)
+////    if (!aTIter->first->isInitialized())
+////      return false;
   return true;
 }
 
@@ -370,3 +370,21 @@ std::set<ConstraintPtr> SketchSolver_FeatureStorage::getConstraints(AttributePtr
   return aResult;
 }
 
+void SketchSolver_FeatureStorage::blockEvents(bool isBlocked) const
+{
+  std::set<ConstraintPtr>::iterator aCIter = myConstraints.begin();
+  for (; aCIter != myConstraints.end(); aCIter++)
+    if ((*aCIter)->data() && (*aCIter)->data()->isValid())
+      (*aCIter)->data()->blockSendAttributeUpdated(isBlocked);
+
+  MapFeatureConstraint::const_iterator aFIter = myFeatures.begin();
+  for (; aFIter != myFeatures.end(); aFIter++)
+    if (aFIter->first->data() && aFIter->first->data()->isValid())
+      aFIter->first->data()->blockSendAttributeUpdated(isBlocked);
+
+  MapAttributeFeature::const_iterator anAtIter = myAttributes.begin();
+  for (; anAtIter != myAttributes.end(); anAtIter++)
+    if (anAtIter->first->owner() && anAtIter->first->owner()->data() &&
+        anAtIter->first->owner()->data()->isValid())
+      anAtIter->first->owner()->data()->blockSendAttributeUpdated(isBlocked);
+}
index 287be5a574a1474bc5def9a9d4aaf8a7af9b7a06..2cb36ba8130df4a583e783d4e70c58ac80738766 100644 (file)
@@ -64,6 +64,9 @@ public:
   /// \brief Prepares list of constraints, which using specified attribute
   std::set<ConstraintPtr> getConstraints(AttributePtr theAttribute) const;
 
+  /// \brief Block/unblock events of changing attributes of the features
+  void blockEvents(bool isBlocked) const;
+
 private:
   std::set<ConstraintPtr> myConstraints; ///< list of SketchPlugin constraints used in the current group
   MapFeatureConstraint myFeatures; ///< list of features used in the group and corresponding constraints which use the feature
index 493fdbf37f36250b74a1a5e0f5d21e1048083548..0a250d8c2d8dfea3340b93b3b473b37432526327 100644 (file)
@@ -1397,16 +1397,18 @@ bool SketchSolver_Group::resolveConstraints()
 
     int aResult = myConstrSolver.solve();
     if (aResult == SLVS_RESULT_OKAY) {  // solution succeeded, store results into correspondent attributes
+      myFeatureStorage->blockEvents(true);
       ConstraintConstraintMap::iterator aConstrIter = myConstraints.begin();
       for (; aConstrIter != myConstraints.end(); aConstrIter++)
         aConstrIter->second->refresh();
+      myFeatureStorage->blockEvents(false);
     } else if (!myConstraints.empty())
       Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
 
-    myStorage->setNeedToResolve(false);
     aResolved = true;
   }
   removeTemporaryConstraints();
+  myStorage->setNeedToResolve(false);
   return aResolved;
 }
 
index 687e6ea11854397a289c81333cc67af046c80152..eabf3a5fa05a4f44c493ef661f80db746f313e61 100644 (file)
@@ -381,6 +381,17 @@ void SketchSolver_Storage::removeCoincidentPoint(const Slvs_hEntity& thePoint)
     }
 }
 
+bool SketchSolver_Storage::isCoincident(
+    const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const
+{
+  std::vector< std::set<Slvs_hEntity> >::const_iterator aCIter = myCoincidentPoints.begin();
+  for (; aCIter != myCoincidentPoints.end(); aCIter++)
+    if (aCIter->find(thePoint1) != aCIter->end() && aCIter->find(thePoint2) != aCIter->end())
+      return true;
+  return false;
+}
+
+
 
 
 // ========================================================
index fe206107e219ed588e09696a772240680d4b0b40..70f2622b15190c591fad9b9c7d45d1e23c2a7bd8 100644 (file)
@@ -109,6 +109,10 @@ private:
   /// \brief Remove point from lists of coincidence
   void removeCoincidentPoint(const Slvs_hEntity& thePoint);
 
+public:
+  /// \brief Check two points are coincident
+  bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const;
+
 private:
   Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
   std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)