-
- // Entity is not found, add new one
- Slvs_Entity aEntity = theEntity;
- aEntity.h = 0;
- return addEntity(aEntity);
-}
-
-bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
-{
- bool aResult = true;
- int aPos = Search(theEntityID, myEntities);
- if (aPos >= 0 && aPos < (int)myEntities.size()) {
- // Firstly, check the entity and its attributes is not used elsewhere
- std::set<Slvs_hEntity> anEntAndSubs;
- anEntAndSubs.insert(theEntityID);
- for (int i = 0; i < 4; i++)
- if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
- anEntAndSubs.insert(myEntities[aPos].point[i]);
-
- std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
- for (; anEntIter != myEntities.end(); anEntIter++) {
- for (int i = 0; i < 4; i++)
- if (anEntAndSubs.find(anEntIter->point[i]) != anEntAndSubs.end())
- return false;
- if (anEntAndSubs.find(anEntIter->distance) != anEntAndSubs.end())
- return false;
+ else if (theSolverConstraints.front()->type() != CONSTRAINT_PT_PT_COINCIDENT) {
+ // Do not add point-point coincidence, because it is already made by setting
+ // the same parameters for both points
+ std::list<ConstraintWrapperPtr>::iterator aCIt = theSolverConstraints.begin();
+ for (; aCIt != theSolverConstraints.end(); ++aCIt)
+ update(*aCIt);
+ }
+
+ if (!theSolverConstraints.empty() || aFound == myConstraintMap.end())
+ myConstraintMap[theConstraint] = theSolverConstraints;
+ // block events if necessary
+ if (myEventsBlocked && theConstraint && theConstraint->data() && theConstraint->data()->isValid())
+ theConstraint->data()->blockSendAttributeUpdated(myEventsBlocked);
+}
+
+static std::list<AttributePtr> pointAttributes(FeaturePtr theFeature)
+{
+ std::list<AttributePtr> aPoints;
+ if (theFeature->getKind() == SketchPlugin_Arc::ID()) {
+ aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
+ aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::START_ID()));
+ aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::END_ID()));
+ }
+ else if (theFeature->getKind() == SketchPlugin_Circle::ID())
+ aPoints.push_back(theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
+ else if (theFeature->getKind() == SketchPlugin_Line::ID()) {
+ aPoints.push_back(theFeature->attribute(SketchPlugin_Line::START_ID()));
+ aPoints.push_back(theFeature->attribute(SketchPlugin_Line::END_ID()));
+ }
+ else if (theFeature->getKind() == SketchPlugin_Point::ID() ||
+ theFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
+ aPoints.push_back(theFeature->attribute(SketchPlugin_Point::COORD_ID()));
+ return aPoints;
+}
+
+void SketchSolver_Storage::addEntity(FeaturePtr theFeature,
+ EntityWrapperPtr theSolverEntity)
+{
+ std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
+ if (aFound == myFeatureMap.end() || !aFound->second ||
+ (theSolverEntity && !aFound->second->isEqual(theSolverEntity)))
+ setNeedToResolve(true); // the entity is new or modified
+
+ if (!theSolverEntity) {
+ // feature links to the empty entity, add its attributes
+ std::list<AttributePtr> aPntAttrs = pointAttributes(theFeature);
+ std::list<AttributePtr>::const_iterator anAttrIt = aPntAttrs.begin();
+ for (; anAttrIt != aPntAttrs.end(); ++anAttrIt)
+ addEntity(*anAttrIt, EntityWrapperPtr());
+ if (aFound == myFeatureMap.end())
+ myFeatureMap[theFeature] = theSolverEntity;
+ } else
+ myFeatureMap[theFeature] = theSolverEntity;
+
+ // block events if necessary
+ if (myEventsBlocked && theFeature->data() && theFeature->data()->isValid())
+ theFeature->data()->blockSendAttributeUpdated(myEventsBlocked);
+}
+
+void SketchSolver_Storage::addEntity(AttributePtr theAttribute,
+ EntityWrapperPtr theSolverEntity)
+{
+ std::map<AttributePtr, EntityWrapperPtr>::const_iterator aFound = myAttributeMap.find(theAttribute);
+ if (aFound == myAttributeMap.end() || !aFound->second ||
+ (theSolverEntity && !aFound->second->isEqual(theSolverEntity)))
+ setNeedToResolve(true); // the entity is new or modified
+
+ if (theSolverEntity || aFound == myAttributeMap.end())
+ myAttributeMap[theAttribute] = theSolverEntity;
+ // block events if necessary
+ if (myEventsBlocked && theAttribute->owner() &&
+ theAttribute->owner()->data() && theAttribute->owner()->data()->isValid())
+ theAttribute->owner()->data()->blockSendAttributeUpdated(myEventsBlocked);
+}
+
+
+bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup)
+{
+ bool isUpdated = false;
+ EntityWrapperPtr aRelated = entity(theFeature);
+ if (!aRelated) { // Feature is not exist, create it
+ std::list<EntityWrapperPtr> aSubs;
+ // Reserve the feature in the map of features (do not want to add several copies of it)
+ myFeatureMap[theFeature] = aRelated;
+ // Firstly, create/update its attributes
+ std::list<AttributePtr> anAttrs = pointAttributes(theFeature);
+ std::list<AttributePtr>::const_iterator anIt = anAttrs.begin();
+ for (; anIt != anAttrs.end(); ++anIt) {
+ isUpdated = update(*anIt, theGroup) || isUpdated;
+ aSubs.push_back(entity(*anIt));