- myType = SLVS_C_UNKNOWN;
- if (!theConstraint)
- return getType();
-
- // Assign empty names of attributes
- myAttributesList.clear();
- for (int i = 0; i < CONSTRAINT_ATTR_SIZE; i++)
- myAttributesList.push_back(std::string());
-
- const std::string& aConstraintKind = theConstraint->getKind();
- // Constraint for coincidence of two points
- if (aConstraintKind.compare(SketchPlugin_ConstraintCoincidence::ID()) == 0) {
- int anAttrPos = 0;
- // Verify the constraint has only two attributes and they are points
- int aPt2d = 0; // bit-mapped field, each bit indicates whether the attribute is 2D point
- int aPt3d = 0; // bit-mapped field, the same information for 3D points
- for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
- boost::shared_ptr<ModelAPI_Attribute> anAttr = theConstraint->data()->attribute(
- SketchPlugin_Constraint::ATTRIBUTE(indAttr));
- if (!anAttr)
- continue;
- switch (typeOfAttribute(anAttr)) {
- case POINT2D: // the attribute is a 2D point
- aPt2d |= (1 << indAttr);
- myAttributesList[anAttrPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- break;
- case POINT3D: // the attribute is a 3D point
- aPt3d |= (1 << indAttr);
- myAttributesList[anAttrPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
- break;
- default:
- // Attribute neither 2D nor 3D point is not supported by this type of constraint
- return getType();
+ cleanErrorMsg();
+ std::list<ConstraintWrapperPtr> aWrapper = myStorage->constraint(myBaseConstraint);
+ std::list<ConstraintWrapperPtr>::iterator aWIt = aWrapper.begin();
+
+ // Check if attributes of constraint are changed, rebuild constraint
+ std::set<AttributePtr> anAttributes;
+ std::set<AttributePtr>::iterator aFoundAttr;
+ std::set<FeaturePtr> aFeatures;
+ std::set<FeaturePtr>::iterator aFoundFeat;
+ for (int anEntIndex = 0; anEntIndex < 4; ++anEntIndex) {
+ AttributePtr anAttr =
+ myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(anEntIndex));
+ if (!anAttr)
+ continue;
+
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
+ if (aRefAttr) {
+ if (aRefAttr->isObject()) {
+ FeaturePtr aFeat = ModelAPI_Feature::feature(aRefAttr->object());
+ if (myBaseConstraint->getKind() != SketchPlugin_ConstraintLength::ID())
+ aFeatures.insert(aFeat);
+ else {
+ // Workaround for the Length constraint: add points of line, not line itself
+ anAttributes.insert(aFeat->attribute(SketchPlugin_Line::START_ID()));
+ anAttributes.insert(aFeat->attribute(SketchPlugin_Line::END_ID()));
+ }
+ } else
+ anAttributes.insert(aRefAttr->attr());
+ } else
+ anAttributes.insert(anAttr);
+ }
+ bool hasNewAttr = !(anAttributes.empty() && aFeatures.empty());
+ for (; hasNewAttr && aWIt != aWrapper.end(); ++ aWIt) {
+ const std::list<EntityWrapperPtr>& aSubs = (*aWIt)->entities();
+ std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
+ for (; hasNewAttr && aSIt != aSubs.end(); ++aSIt) {
+ if ((*aSIt)->baseAttribute()) {
+ aFoundAttr = anAttributes.find((*aSIt)->baseAttribute());
+ if (aFoundAttr != anAttributes.end())
+ anAttributes.erase(aFoundAttr);
+ } else {
+ aFoundFeat = aFeatures.find((*aSIt)->baseFeature());
+ if (aFoundFeat != aFeatures.end())
+ aFeatures.erase(aFoundFeat);