adjustConstraint();
}
-void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
+bool SketchSolver_Constraint::checkAttributesChanged(ConstraintPtr theConstraint)
{
- cleanErrorMsg();
- bool needToRebuild = (theConstraint && theConstraint != myBaseConstraint);
- if (!needToRebuild) {
- // Check the attrbutes of constraint are changed
- ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
- std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
- std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
- for (; anAttrIter != anAttrList.end(); anAttrIter++) {
- AttributeRefAttrPtr aRefAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
- if (aRefAttr) {
- if (aRefAttr->isObject()) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
- if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
- needToRebuild = true;
- break;
- }
- } else if (aRefAttr->attr() &&
- myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end()) {
- needToRebuild = true;
- break;
- }
- }
- AttributeRefListPtr aRefList =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
- if (aRefList) {
- std::list<ObjectPtr> anItems = aRefList->list();
- std::list<ObjectPtr>::iterator anIt = anItems.begin();
- for (; anIt != anItems.end(); anIt++) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
- if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
- needToRebuild = true;
- break;
- }
- }
- if (needToRebuild)
- break;
+ // Check the attrbutes of constraint are changed
+ ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
+ std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
+ std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
+ for (; anAttrIter != anAttrList.end(); anAttrIter++) {
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+ if (aRefAttr) {
+ if (aRefAttr->isObject()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end())
+ return true;
+ } else if (aRefAttr->attr() &&
+ myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end())
+ return true;
+ }
+ AttributeRefListPtr aRefList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
+ if (aRefList) {
+ std::list<ObjectPtr> anItems = aRefList->list();
+ std::list<ObjectPtr>::iterator anIt = anItems.begin();
+ for (; anIt != anItems.end(); anIt++) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end())
+ return true;
}
}
}
+ return false;
+}
+
+void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
+{
+ cleanErrorMsg();
+ bool needToRebuild = (theConstraint && theConstraint != myBaseConstraint);
+ if (!needToRebuild)
+ needToRebuild = checkAttributesChanged(theConstraint);
if (needToRebuild) {
if (theConstraint && theConstraint->getKind() != myBaseConstraint->getKind())
return;
/// \param[out] theAttributes list of attributes to be filled
virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes);
+ /// \brief Verify the attributes of constraint are changed (and constraint need to rebuild)
+ /// \param[in] theConstraint constraint, which attributes should be checked (if NULL, the myBaseConstraint is used)
+ /// \return \c true if some attributes are changed
+ virtual bool checkAttributesChanged(ConstraintPtr theConstraint);
+
/// \brief This method is used in derived objects to check consistence of constraint.
/// E.g. the distance between line and point may be signed.
virtual void adjustConstraint()
return true;
}
+bool SketchSolver_ConstraintMirror::checkAttributesChanged(ConstraintPtr theConstraint)
+{
+ // First of all, check the mirror line is changed.
+ // It may be changed to one of mirrored lines, which is already in this constraint
+ // (this case is not marked as attribute changing)
+ ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (!aRefAttr || !aRefAttr->isObject() || !aRefAttr->object())
+ return true;
+ FeaturePtr aMirrorLine = ModelAPI_Feature::feature(aRefAttr->object());
+ if (!aMirrorLine)
+ return true;
+
+ std::map<FeaturePtr, Slvs_hEntity>::iterator aMirrorIter = myFeatureMap.find(aMirrorLine);
+ if (aMirrorIter == myFeatureMap.end())
+ return true;
+
+ // Check the entity is not used as mirror line
+ std::vector<Slvs_hConstraint>::iterator aCIter = mySlvsConstraints.begin();
+ for (; aCIter != mySlvsConstraints.end(); aCIter++) {
+ Slvs_Constraint aMirrorConstr = myStorage->getConstraint(*aCIter);
+ if (aMirrorConstr.type != SLVS_C_SYMMETRIC_LINE)
+ continue;
+ if (aMirrorConstr.entityA != aMirrorIter->second)
+ return true;
+ else break; // check just one symmetric constraint
+ }
+
+ // Base verification
+ return SketchSolver_Constraint::checkAttributesChanged(theConstraint);
+}
+
void SketchSolver_ConstraintMirror::makeMirrorEntity(
const Slvs_Entity& theBase,
const Slvs_Entity& theMirror,
virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes)
{ /* do nothing here */ }
+ /// \brief Verify the attributes of constraint are changed (and constraint need to rebuild)
+ /// \param[in] theConstraint constraint, which attributes should be checked (if NULL, the myBaseConstraint is used)
+ /// \return \c true if some attributes are changed
+ virtual bool checkAttributesChanged(ConstraintPtr theConstraint);
+
/// \brief Generate list of entities of mirror constraint
/// \param[out] theMirrorLine entity corresponding to mirror line
/// \param[out] theBaseEntities list of entities to mirror