// parameter already used, rewrite it
int aPos = Search(theParam.h, myParameters);
if (aPos >= 0 && aPos < (int)myParameters.size()) {
- myNeedToResolve = myNeedToResolve || IsNotEqual(myParameters[aPos], theParam);
+ if (IsNotEqual(myParameters[aPos], theParam))
+ myUpdatedParameters.insert(theParam.h);
myParameters[aPos] = theParam;
return theParam.h;
}
myNeedToResolve = true;
}
+bool SketchSolver_Storage::isUsedByConstraints(const Slvs_hEntity& theEntityID) const
+{
+ std::vector<Slvs_Constraint>::const_iterator aCIt = myConstraints.begin();
+ for (; aCIt != myConstraints.end(); ++aCIt) {
+ Slvs_hEntity aSubs[6] = {
+ aCIt->entityA, aCIt->entityB,
+ aCIt->entityC, aCIt->entityD,
+ aCIt->ptA, aCIt->ptB};
+ for (int i = 0; i < 6; i++)
+ if (aSubs[i] != SLVS_E_UNKNOWN && aSubs[i] == theEntityID)
+ return true;
+ }
+ return false;
+}
+
const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntityID) const
{
int aPos = Search(theEntityID, myEntities);
return false;
}
+bool SketchSolver_Storage::isNeedToResolve()
+{
+ if (myConstraints.empty())
+ return false;
+
+ if (!myNeedToResolve) {
+ // Verify the updated parameters are used in constraints
+ std::set<Slvs_hEntity> aPoints;
+ std::vector<Slvs_Entity>::const_iterator anEntIt = myEntities.begin();
+ for (; anEntIt != myEntities.end(); ++anEntIt) {
+ for (int i = 0; i < 4 && anEntIt->param[i] != SLVS_E_UNKNOWN; ++i)
+ if (myUpdatedParameters.find(anEntIt->param[i]) != myUpdatedParameters.end()) {
+ aPoints.insert(anEntIt->h);
+ break;
+ }
+ }
+ std::set<Slvs_hEntity> anEntities = aPoints;
+ for (anEntIt = myEntities.begin(); anEntIt != myEntities.end(); ++anEntIt) {
+ for (int i = 0; i < 4 && anEntIt->point[i] != SLVS_E_UNKNOWN; ++i)
+ if (aPoints.find(anEntIt->point[i]) != aPoints.end()) {
+ anEntities.insert(anEntIt->h);
+ break;
+ }
+ }
+
+ std::vector<Slvs_Constraint>::const_iterator aCIt = myConstraints.begin();
+ for (; aCIt != myConstraints.end() && !myNeedToResolve; ++aCIt) {
+ Slvs_hEntity anAttrs[6] =
+ {aCIt->ptA, aCIt->ptB, aCIt->entityA, aCIt->entityB, aCIt->entityC, aCIt->entityD};
+ for (int i = 0; i < 6; i++)
+ if (anAttrs[i] != SLVS_E_UNKNOWN && anEntities.find(anAttrs[i]) != anEntities.end()) {
+ myNeedToResolve = true;
+ break;
+ }
+ }
+ }
+
+ myUpdatedParameters.clear();
+ return myNeedToResolve;
+}
+
+
Slvs_hEntity copyEntity(const Slvs_hEntity& theCopied);
/// \brief Copy one entity to another
void copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo);
+ /// \brief Check the entity is used in constraints
+ bool isUsedByConstraints(const Slvs_hEntity& theEntityID) const;
/// \brief Verifies the current point or another coincident one is fixed
/// \param[in] thePointID entity to be checked fixed
{ return (int)myTemporaryConstraints.size(); }
/// \brief Shows the sketch should be resolved
- bool isNeedToResolve() const
- { return myNeedToResolve && !myConstraints.empty(); }
+ bool isNeedToResolve();
/// \brief Shows the storage has the same constraint twice
bool hasDuplicatedConstraint() const
std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
+ std::set<Slvs_hParam> myUpdatedParameters; ///< list of just updated parameters (cleared when isNeedToResolve() called)
};
typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;