theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[i])
);
if (!aCAttrRef) continue;
- if (myEntityMap.find(aCAttrRef->attr()) != myEntityMap.end())
+ if (!aCAttrRef->isFeature() &&
+ myEntityAttrMap.find(aCAttrRef->attr()) != myEntityAttrMap.end())
+ return true;
+ if (aCAttrRef->isFeature() &&
+ myEntityFeatMap.find(aCAttrRef->feature()) != myEntityFeatMap.end())
return true;
}
myNeedToSolve = true;
aConstrIter->valA = aDistance;
}
+ // SketchPlugin circle defined by its radius, but SolveSpace uses constraint for diameter
+ if (aConstrType == SLVS_C_DIAMETER)
+ aDistance *= 2.0;
}
Slvs_hEntity aConstrEnt[CONSTRAINT_ATTR_SIZE]; // parameters of the constraint
theConstraint->data()->attribute(aConstraintAttributes[indAttr])
);
if (!aConstrAttr) continue;
- aConstrEnt[indAttr] = changeEntity(aConstrAttr->attr());
+
+ // For the length constraint the start and end points of the line should be added to the entities list instead of line
+ if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare("SketchConstraintLength") == 0)
+ {
+ boost::shared_ptr<ModelAPI_Data> aData = aConstrAttr->feature()->data();
+ aConstrEnt[indAttr] = changeEntity(aData->attribute(LINE_ATTR_START));
+ aConstrEnt[indAttr+1] = changeEntity(aData->attribute(LINE_ATTR_END));
+ break; // there should be no other entities
+ }
+ else if (aConstrAttr->isFeature())
+ aConstrEnt[indAttr] = changeEntity(aConstrAttr->feature());
+ else
+ aConstrEnt[indAttr] = changeEntity(aConstrAttr->attr());
}
if (aConstrMapIter == myConstraintMap.end())
{
// If the entity is already in the group, try to find it
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
- aEntIter = myEntityMap.find(theEntity);
+ aEntIter = myEntityAttrMap.find(theEntity);
std::vector<Slvs_Param>::const_iterator aParamIter; // looks at first parameter of already existent entity or at the end of vector otherwise
- if (aEntIter == myEntityMap.end()) // no such entity => should be created
+ if (aEntIter == myEntityAttrMap.end()) // no such entity => should be created
aParamIter = myParams.end();
else
{ // the entity already exists
int aParamPos = Search(myEntities[aEntPos].param[0], myParams);
aParamIter = myParams.begin() + aParamPos;
}
+ const bool isEntExists = (aEntIter != myEntityAttrMap.end()); // defines that the entity already exists
// Look over supported types of entities
Slvs_hParam aY = changeParameter(aPoint->y(), aParamIter);
Slvs_hParam aZ = changeParameter(aPoint->z(), aParamIter);
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (isEntExists)
return aEntIter->second;
// New entity
Slvs_Entity aPtEntity = Slvs_MakePoint3d(++myEntityMaxID, myID, aX, aY, aZ);
myEntities.push_back(aPtEntity);
- myEntityMap[theEntity] = aPtEntity.h;
+ myEntityAttrMap[theEntity] = aPtEntity.h;
return aPtEntity.h;
}
Slvs_hParam aU = changeParameter(aPoint2D->x(), aParamIter);
Slvs_hParam aV = changeParameter(aPoint2D->y(), aParamIter);
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (isEntExists)
return aEntIter->second;
// New entity
Slvs_Entity aPt2DEntity = Slvs_MakePoint2d(++myEntityMaxID, myID, myWorkplane.h, aU, aV);
myEntities.push_back(aPt2DEntity);
- myEntityMap[theEntity] = aPt2DEntity.h;
+ myEntityAttrMap[theEntity] = aPt2DEntity.h;
return aPt2DEntity.h;
}
{
Slvs_hParam aValue = changeParameter(aScalar->value(), aParamIter);
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (isEntExists)
return aEntIter->second;
// New entity
Slvs_Entity aDistance = Slvs_MakeDistance(++myEntityMaxID, myID, myWorkplane.h, aValue);
myEntities.push_back(aDistance);
- myEntityMap[theEntity] = aDistance.h;
+ myEntityAttrMap[theEntity] = aDistance.h;
return aDistance.h;
}
+ /// \todo Other types of entities
+
+ // Unsupported or wrong entity type
+ return SLVS_E_UNKNOWN;
+}
+
+
+// ============================================================================
+// Function: changeEntity
+// Class: SketchSolver_ConstraintGroup
+// Purpose: create/update the element defined by the feature affected by any constraint
+// ============================================================================
+Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
+ boost::shared_ptr<ModelAPI_Feature> theEntity)
+{
+ // If the entity is already in the group, try to find it
+ std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::const_iterator
+ aEntIter = myEntityFeatMap.find(theEntity);
+ // defines that the entity already exists
+ const bool isEntExists = (myEntityFeatMap.find(theEntity) != myEntityFeatMap.end());
+
// SketchPlugin features
- boost::shared_ptr<SketchPlugin_Feature> aFeature =
+ boost::shared_ptr<SketchPlugin_Feature> aFeature;
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theEntity);
if (aFeature)
{ // Verify the feature by its kind
Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(LINE_ATTR_START));
Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(LINE_ATTR_END));
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (isEntExists)
return aEntIter->second;
// New entity
Slvs_Entity aLineEntity = Slvs_MakeLineSegment(++myEntityMaxID, myID, myWorkplane.h, aStart, aEnd);
myEntities.push_back(aLineEntity);
- myEntityMap[theEntity] = aLineEntity.h;
+ myEntityFeatMap[theEntity] = aLineEntity.h;
return aLineEntity.h;
}
// Circle
Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_CENTER));
Slvs_hEntity aRadius = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_RADIUS));
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (isEntExists)
return aEntIter->second;
// New entity
Slvs_Entity aCircleEntity =
Slvs_MakeCircle(++myEntityMaxID, myID, myWorkplane.h, aCenter, myWorkplane.normal, aRadius);
myEntities.push_back(aCircleEntity);
- myEntityMap[theEntity] = aCircleEntity.h;
+ myEntityFeatMap[theEntity] = aCircleEntity.h;
return aCircleEntity.h;
}
// Arc
Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(ARC_ATTR_START));
Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(ARC_ATTR_END));
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (isEntExists)
return aEntIter->second;
Slvs_Entity anArcEntity = Slvs_MakeArcOfCircle(++myEntityMaxID, myID,
myWorkplane.h, myWorkplane.normal, aCenter, aStart, aEnd);
myEntities.push_back(anArcEntity);
- myEntityMap[theEntity] = anArcEntity.h;
+ myEntityFeatMap[theEntity] = anArcEntity.h;
return anArcEntity.h;
}
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
{
Slvs_hEntity aPoint = changeEntity(aFeature->data()->attribute(POINT_ATTR_COORD));
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (isEntExists)
return aEntIter->second;
// Both the sketch point and its attribute (coordinates) link to the same SolveSpace point identifier
- myEntityMap[theEntity] = aPoint;
+ myEntityFeatMap[theEntity] = aPoint;
return aPoint;
}
}
- /// \todo Other types of entities
+ /// \todo Other types of features
// Unsupported or wrong entity type
return SLVS_E_UNKNOWN;
// Try to find existent normal
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
- aEntIter = myEntityMap.find(theNorm);
+ aEntIter = myEntityAttrMap.find(theNorm);
std::vector<Slvs_Param>::const_iterator aParamIter; // looks to the first parameter of already existent entity or to the end of vector otherwise
- if (aEntIter == myEntityMap.end()) // no such entity => should be created
+ if (aEntIter == myEntityAttrMap.end()) // no such entity => should be created
aParamIter = myParams.end();
else
{ // the entity already exists, update it
for (int i = 0; i < 4; i++)
aNormParams[i] = changeParameter(aNormCoord[i], aParamIter);
- if (aEntIter != myEntityMap.end()) // the entity already exists
+ if (aEntIter != myEntityAttrMap.end()) // the entity already exists
return aEntIter->second;
// Create a normal
Slvs_Entity aNormal = Slvs_MakeNormal3d(++myEntityMaxID, myID,
aNormParams[0], aNormParams[1], aNormParams[2], aNormParams[3]);
myEntities.push_back(aNormal);
- myEntityMap[theNorm] = aNormal.h;
+ myEntityAttrMap[theNorm] = aNormal.h;
return aNormal.h;
}
if (!myConstrSolver.getResult(myParams))
return;
+ // We should go through the attributes map, because only attributes have valued parameters
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::iterator
- anEntIter = myEntityMap.begin();
- for ( ; anEntIter != myEntityMap.end(); anEntIter++)
+ anEntIter = myEntityAttrMap.begin();
+ for ( ; anEntIter != myEntityAttrMap.end(); anEntIter++)
updateAttribute(anEntIter->first, anEntIter->second);
}
/// \todo Implement error handling
else if (!theGroup.myTempPointWhereDragged.empty())
{ // Need to create additional transient constraint
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
- aFeatureIter = theGroup.myEntityMap.begin();
- for (; aFeatureIter != theGroup.myEntityMap.end(); aFeatureIter++)
+ aFeatureIter = theGroup.myEntityAttrMap.begin();
+ for (; aFeatureIter != theGroup.myEntityAttrMap.end(); aFeatureIter++)
if (aFeatureIter->second == myTempPointWDrgdID)
{
addTemporaryConstraintWhereDragged(aFeatureIter->first);
void SketchSolver_ConstraintGroup::updateEntityIfPossible(
boost::shared_ptr<ModelAPI_Attribute> theEntity)
{
- if (myEntityMap.find(theEntity) != myEntityMap.end())
+ if (myEntityAttrMap.find(theEntity) != myEntityAttrMap.end())
{
// If the attribute is a point and it is changed (the group needs to rebuild),
// probably user has dragged this point into this position,
{
// Find identifier of the entity
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator
- anEntIter = myEntityMap.find(theEntity);
- if (anEntIter == myEntityMap.end())
+ anEntIter = myEntityAttrMap.find(theEntity);
+ if (anEntIter == myEntityAttrMap.end())
return ;
// If this is a first dragged point, its parameters should be placed
// Remove unused entities
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::iterator
- anEntMapIter = myEntityMap.begin();
- while (anEntMapIter != myEntityMap.end())
+ anEntAttrIter = myEntityAttrMap.begin();
+ while (anEntAttrIter != myEntityAttrMap.end())
{
- if (anEntToRemove.find(anEntMapIter->second) != anEntToRemove.end())
+ if (anEntToRemove.find(anEntAttrIter->second) != anEntToRemove.end())
{
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::iterator
- aRemovedIter = anEntMapIter;
- anEntMapIter++;
- myEntityMap.erase(aRemovedIter);
+ aRemovedIter = anEntAttrIter;
+ anEntAttrIter++;
+ myEntityAttrMap.erase(aRemovedIter);
+ }
+ else anEntAttrIter++;
+ }
+ std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::iterator
+ anEntFeatIter = myEntityFeatMap.begin();
+ while (anEntFeatIter != myEntityFeatMap.end())
+ {
+ if (anEntToRemove.find(anEntFeatIter->second) != anEntToRemove.end())
+ {
+ std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::iterator
+ aRemovedIter = anEntFeatIter;
+ anEntFeatIter++;
+ myEntityFeatMap.erase(aRemovedIter);
}
- else anEntMapIter++;
+ else anEntFeatIter++;
}
std::set<Slvs_hEntity>::const_reverse_iterator aRemIter = anEntToRemove.rbegin();
for ( ; aRemIter != anEntToRemove.rend(); aRemIter++)