]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve performance of calculation of multi-translation constraint (issue #893)
authorazv <azv@opencascade.com>
Mon, 7 Sep 2015 12:22:37 +0000 (15:22 +0300)
committerazv <azv@opencascade.com>
Mon, 7 Sep 2015 12:23:19 +0000 (15:23 +0300)
src/SketchSolver/SketchSolver_Constraint.h
src/SketchSolver/SketchSolver_ConstraintMulti.cpp
src/SketchSolver/SketchSolver_ConstraintMulti.h
src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp
src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Group.h

index 8589dc19bb7d5b3d2e23e48a71950db084f71e5b..084e174103b7d69deb788e52b8c2742df9eda1e7 100644 (file)
@@ -46,7 +46,7 @@ public:
   virtual bool remove(ConstraintPtr theConstraint = ConstraintPtr());
 
   /// \brief Update SketchPlugin attributes using the data obtained from SolveSpace entities
-  void refresh();
+  virtual void refresh();
 
   /// \brief Returns the type of constraint
   virtual int getType() const = 0;
index 92a79eb04c890d02af02a02cd5771b435b306d36..e68a881be5b246c69e731d8dba9914e1746280d2 100644 (file)
@@ -136,6 +136,9 @@ void SketchSolver_ConstraintMulti::addFeature(FeaturePtr theFeature)
 
 void SketchSolver_ConstraintMulti::adjustConstraint()
 {
+  if (myAdjusted)
+    return; // constraint already adjusted, don't do it once again
+
   double aRelCoord[2]  = {0.0, 0.0}; // relative coordinates of point
   double anAbsCoord[2] = {0.0, 0.0}; // absolute coordinates of point
 
@@ -232,4 +235,5 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
   }
 
   myPointsJustUpdated.clear();
+  myAdjusted = true;
 }
index cf2f16d94ba0bc3c9f36b3fdf9182638ab3104a7..bbc4992be5e72193360b6648280e4b72133264e6 100644 (file)
@@ -22,7 +22,8 @@ public:
   SketchSolver_ConstraintMulti(ConstraintPtr theConstraint) :
       SketchSolver_Constraint(theConstraint),
       myNumberOfObjects(0),
-      myNumberOfCopies(0)
+      myNumberOfCopies(0),
+      myAdjusted(false)
   {}
 
   virtual int getType() const
@@ -38,6 +39,14 @@ public:
   /// \brief Adds a feature to constraint and create its analogue in SolveSpace
   virtual void addFeature(FeaturePtr theFeature);
 
+  /// \brief Update SketchPlugin attributes using the data obtained from SolveSpace entities
+  virtual void refresh()
+  {
+    myAdjusted = false;
+    SketchSolver_Constraint::refresh();
+  }
+
+
 protected:
   /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
   virtual void process()
@@ -78,6 +87,8 @@ protected:
 
   std::set<Slvs_hEntity> myPointsJustUpdated; ///< list of points touched by user
   std::set<Slvs_hEntity> myInitialPoints;     ///< list of points containing initial objects
+
+  bool myAdjusted; ///< the constraint is already adjusted (to not do it several times)
 };
 
 #endif
index da083caf78ce6f5f10ee05f58dab11c30d44fbef..ed1550d41e10ba1c740b3678f8e4956467aa3d11 100644 (file)
@@ -126,15 +126,19 @@ void SketchSolver_ConstraintMultiRotation::process()
     mySlvsConstraints.push_back(aConstraint.h);
   }
 
+  myAdjusted = false;
   processEntities(anEntitiesAndCopies);
   adjustConstraint();
 }
 
 void SketchSolver_ConstraintMultiRotation::updateLocal()
 {
-  // update angle value
-  myAngle = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+  double aValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
       myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID()))->value();
+  if (fabs(myAngle - aValue) > tolerance)
+    myAdjusted = false;
+  // update angle value
+  myAngle = aValue;
 }
 
 void SketchSolver_ConstraintMultiRotation::adjustConstraint()
@@ -143,6 +147,8 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint()
     myStorage->setNeedToResolve(false);
     return;
   }
+  if (myAdjusted)
+    return;
 
   std::list<Slvs_Constraint> aCoincident = myStorage->getConstraintsByType(SLVS_C_POINTS_COINCIDENT);
   std::list<Slvs_Constraint>::const_iterator aCoIt;
index 816aa8fccb6610cf125e4f7e895c903d79afe89c..381c8641b71770392680a17696b53140416e1c85 100644 (file)
@@ -138,12 +138,16 @@ void SketchSolver_ConstraintMultiTranslation::process()
     }
   }
 
+  myAdjusted = false;
   processEntities(anEntitiesAndCopies);
   adjustConstraint();
 }
 
 void SketchSolver_ConstraintMultiTranslation::adjustConstraint()
 {
+  if (myAdjusted)
+    return;
+
   Slvs_Entity aTranslationLine = myStorage->getEntity(myTranslationLine);
   Slvs_hConstraint aFixed; // temporary variable
   // Set the translation line unchanged during constraint recalculation
index 589b6a320385e25749b23f36cc8a0eed6f8110f9..9371607d2d6511b13336b394ea32ed078e7a237c 100644 (file)
@@ -285,6 +285,29 @@ bool SketchSolver_Group::changeConstraint(
 }
 
 
+void SketchSolver_Group::updateConstraints()
+{
+  std::set<SolverConstraintPtr> aPostponed; // postponed constraints Multi-Rotation and Multi-Translation
+
+  ConstraintConstraintMap::iterator anIt = myConstraints.begin();
+  for (; anIt != myConstraints.end(); ++anIt) {
+    if (myChangedConstraints.find(anIt->first) == myChangedConstraints.end())
+      continue;
+    if (anIt->first->getKind() == SketchPlugin_MultiRotation::ID() ||
+        anIt->first->getKind() == SketchPlugin_MultiTranslation::ID())
+      aPostponed.insert(anIt->second);
+    else
+      anIt->second->update();
+  }
+
+  // Update postponed constraints
+  std::set<SolverConstraintPtr>::iterator aSCIter = aPostponed.begin();
+  for (; aSCIter != aPostponed.end(); ++aSCIter)
+    (*aSCIter)->update();
+
+  myChangedConstraints.clear();
+}
+
 bool SketchSolver_Group::updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature)
 {
   if (!checkFeatureValidity(theFeature))
@@ -295,7 +318,6 @@ bool SketchSolver_Group::updateFeature(std::shared_ptr<SketchPlugin_Feature> the
   if (aConstraints.empty())
     return false;
   std::set<ConstraintPtr>::iterator aCIter = aConstraints.begin();
-  std::set<SolverConstraintPtr> aPostponed; // postponed constraints Multi-Rotation and Multi-Translation
   for (; aCIter != aConstraints.end(); aCIter++) {
     ConstraintConstraintMap::iterator aSolConIter = myConstraints.find(*aCIter);
     if (aSolConIter == myConstraints.end() || !aSolConIter->first->data() ||
@@ -303,20 +325,8 @@ bool SketchSolver_Group::updateFeature(std::shared_ptr<SketchPlugin_Feature> the
       continue;
     myFeatureStorage->changeFeature(theFeature, aSolConIter->first);
 
-    if (aSolConIter->first->getKind() == SketchPlugin_MultiRotation::ID() ||
-        aSolConIter->first->getKind() == SketchPlugin_MultiTranslation::ID()) {
-      aPostponed.insert(aSolConIter->second);
-      continue;
-    }
     aSolConIter->second->addFeature(theFeature);
-    aSolConIter->second->update();
-  }
-
-  // Update postponed constraints
-  std::set<SolverConstraintPtr>::iterator aSCIter = aPostponed.begin();
-  for (; aSCIter != aPostponed.end(); ++aSCIter) {
-    (*aSCIter)->addFeature(theFeature);
-    (*aSCIter)->update();
+    myChangedConstraints.insert(aSolConIter->first);
   }
   return true;
 }
@@ -454,6 +464,9 @@ bool SketchSolver_Group::updateWorkplane()
 // ============================================================================
 bool SketchSolver_Group::resolveConstraints()
 {
+  if (!myChangedConstraints.empty())
+    updateConstraints();
+
   bool aResolved = false;
   if (myStorage->isNeedToResolve() && !isEmpty()) {
     myConstrSolver.setGroupID(myID);
index e75accd08dd53a53b0c370b13ec4dd804c0e9ec2..3197bd6da5e4bba09f3ebfad981dabe71d5168a7 100644 (file)
@@ -160,12 +160,16 @@ private:
   /// \brief Verifies is the feature valid
   bool checkFeatureValidity(FeaturePtr theFeature);
 
+  /// \brief Update just changed constraints
+  void updateConstraints();
+
 private:
   Slvs_hGroup myID; ///< Index of the group
   Slvs_hEntity myWorkplaneID; ///< Index of workplane, the group is based on
   CompositeFeaturePtr mySketch; ///< Sketch is equivalent to workplane
   ConstraintConstraintMap myConstraints; ///< List of constraints
   std::set<SolverConstraintPtr> myTempConstraints; ///< List of temporary constraints
+  std::set<ConstraintPtr> myChangedConstraints; ///< List of just updated constraints
 
   StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities
   FeatureStoragePtr myFeatureStorage; ///< Container for the set of SketchPlugin features and their dependencies