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;
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
}
myPointsJustUpdated.clear();
+ myAdjusted = true;
}
SketchSolver_ConstraintMulti(ConstraintPtr theConstraint) :
SketchSolver_Constraint(theConstraint),
myNumberOfObjects(0),
- myNumberOfCopies(0)
+ myNumberOfCopies(0),
+ myAdjusted(false)
{}
virtual int getType() const
/// \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()
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
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()
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;
}
}
+ 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
}
+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))
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() ||
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;
}
// ============================================================================
bool SketchSolver_Group::resolveConstraints()
{
+ if (!myChangedConstraints.empty())
+ updateConstraints();
+
bool aResolved = false;
if (myStorage->isNeedToResolve() && !isEmpty()) {
myConstrSolver.setGroupID(myID);
/// \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