#include <SketchSolver_Error.h>
#include <SketchSolver_Group.h>
+#include <SketchPlugin_Point.h>
+#include <GeomDataAPI_Point2D.h>
+
#include <map>
void SketchSolver_ConstraintCoincidence::getAttributes(
if (!myErrorMsg.empty() || theAttributes[0] == SLVS_E_UNKNOWN)
return;
- if (theAttributes[1] != SLVS_E_UNKNOWN)
+ if (theAttributes[1] != SLVS_E_UNKNOWN) {
myType = SLVS_C_POINTS_COINCIDENT;
+
+ // set coordinates of slave (second) point equal to the master (first) point
+ Slvs_Entity aFirst = myStorage->getEntity(theAttributes[0]);
+ Slvs_Entity aSecond = myStorage->getEntity(theAttributes[1]);
+ for (int i = 0; i < 4; i++)
+ if (aFirst.param[i] != SLVS_E_UNKNOWN && aSecond.param[i] != SLVS_E_UNKNOWN) {
+ Slvs_Param aPar1 = myStorage->getParameter(aFirst.param[i]);
+ Slvs_Param aPar2 = myStorage->getParameter(aSecond.param[i]);
+ aPar2.val = aPar1.val;
+ myStorage->updateParameter(aPar2);
+ }
+ }
else if (theAttributes[2] != SLVS_E_UNKNOWN) {
// check the type of entity (line or circle)
Slvs_Entity anEnt = myStorage->getEntity(theAttributes[2]);
Slvs_hEntity anEntity = SLVS_E_UNKNOWN;
int anEntType;
for (; anIter != anAttrList.end(); anIter++) {
+ Slvs_hEntity aPointID = SLVS_E_UNKNOWN;
AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
if (!aRefAttr)
continue;
+
+ AttributePtr aPointAttr;
if (aRefAttr->isObject()) {
FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
std::map<FeaturePtr, Slvs_hEntity>::const_iterator aFeatFound =
anEntity = myGroup->getFeatureId(aFeature);
if (anEntity == SLVS_E_UNKNOWN)
anEntity = changeEntity(aFeature, anEntType);
- else
+ else {
myFeatureMap[aFeature] = anEntity;
+ // Obtain relations between attributes of the feature and SolveSpace entities
+ std::list<AttributePtr> anAttrList =
+ aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::iterator anIt = anAttrList.begin();
+ for (; anIt != anAttrList.end(); ++anIt) {
+ Slvs_hEntity anAttrID = myGroup->getAttributeId(*anIt);
+ if (anAttrID != SLVS_E_UNKNOWN)
+ myAttributeMap[*anIt] = anAttrID;
+ }
+ }
+ }
+ // If the feature is a point, add it to the list of coincident points
+ if (aFeature->getKind() == SketchPlugin_Point::ID()) {
+ aPointID = anEntity;
+ anEntity = SLVS_E_UNKNOWN;
+ aPointAttr = aFeature->attribute(SketchPlugin_Point::COORD_ID());
}
} else {
- Slvs_hEntity anEntID = SLVS_E_UNKNOWN;
+ aPointAttr = aRefAttr->attr();
std::map<AttributePtr, Slvs_hEntity>::const_iterator anAttrFound =
- myAttributeMap.find(aRefAttr->attr());
+ myAttributeMap.find(aPointAttr);
if (anAttrFound != myAttributeMap.end())
- anEntID = anAttrFound->second;
+ aPointID = anAttrFound->second;
else {
- anEntID = myGroup->getAttributeId(aRefAttr->attr());
- if (anEntID == SLVS_E_UNKNOWN)
- anEntID = changeEntity(aRefAttr->attr(), anEntType);
- else
- myAttributeMap[aRefAttr->attr()] = anEntID;
+ aPointID = myGroup->getAttributeId(aPointAttr);
+ if (aPointID == SLVS_E_UNKNOWN)
+ aPointID = changeEntity(aPointAttr, anEntType);
}
- aPoints.push_back(anEntID);
- myCoincidentPoints.insert(aRefAttr->attr());
+ }
+
+ if (aPointAttr) { // the point is found
+ aPoints.push_back(aPointID);
+ myCoincidentPoints.insert(aPointAttr);
+ myAttributeMap[aPointAttr] = aPointID;
}
}