#include <ModelAPI_Attribute.h>
#include <SketchPlugin_Constraint.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_Circle.h>
/// Global constraint manager object
SketchSolver_ConstraintManager* myManager = SketchSolver_ConstraintManager::Instance();
+
// ========================================================
// ========= SketchSolver_ConstraintManager ===============
// ========================================================
std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
std::set<ObjectPtr> aFeatures = anUpdateMsg->objects();
+ // Shows the message has at least one feature applicable for solver
+ bool hasProperFeature = false;
+
bool isMovedEvt = theMessage->eventID()
- == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
+ == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
if (isMovedEvt) {
std::set<ObjectPtr>::iterator aFeatIter;
for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
std::shared_ptr<SketchPlugin_Feature> aSFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
- if (aSFeature)
+ if (aSFeature) {
moveEntity(aSFeature);
+ hasProperFeature = true;
+ }
}
} else {
- std::set<ObjectPtr>::iterator aFeatIter;
- // iterate sketchers fisrt to create all sketches before (on load may exist several sketches)
- for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aFeatIter);
- if (!aFeature)
+ std::list<FeaturePtr> aSketchFeatures = SketchSolver_Group::selectApplicableFeatures(aFeatures);
+ std::list<FeaturePtr>::iterator aFeatIter = aSketchFeatures.begin();
+ for (; aFeatIter != aSketchFeatures.end(); ++aFeatIter) {
+ if ((*aFeatIter)->getKind() == SketchPlugin_Sketch::ID()) {
+ std::shared_ptr<ModelAPI_CompositeFeature> aSketch =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFeatIter);
+ hasProperFeature = changeWorkplane(aSketch) || hasProperFeature;
continue;
- const std::string& aFeatureKind = aFeature->getKind();
- if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) {
- std::shared_ptr<ModelAPI_CompositeFeature> aSketch = std::dynamic_pointer_cast<
- ModelAPI_CompositeFeature>(aFeature);
- changeWorkplane(aSketch);
}
- }
- // then get anything but not the sketch
- // at first, add coincidence constraints, because they may be used by other constraints
- for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
std::shared_ptr<SketchPlugin_Feature> aFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
- if (!aFeature || aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
- continue;
- changeConstraintOrEntity(aFeature);
- }
- // after that, add all features except coincidence
- for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
- std::shared_ptr<SketchPlugin_Feature> aFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
- if (!aFeature /*|| aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()*/)
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+ if (!aFeature)
continue;
- changeConstraintOrEntity(aFeature);
+ hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
}
}
// Solve the set of constraints
- resolveConstraints(isMovedEvt); // send update for movement in any case
+ if (hasProperFeature)
+ resolveConstraints(isMovedEvt); // send update for movement in any case
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleteMsg =
- std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
+ std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
const std::set<std::string>& aFeatureGroups = aDeleteMsg->groups();
// Find SketchPlugin_Sketch::ID() in groups. The constraint groups should be updated when an object removed from Sketch
std::set<std::string>::const_iterator aFGrIter;
for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++)
if (aFGrIter->compare(ModelAPI_ResultConstruction::group()) == 0 ||
- aFGrIter->compare(ModelAPI_Feature::group()) == 0)
+ aFGrIter->compare(ModelAPI_Feature::group()) == 0)
break;
if (aFGrIter != aFeatureGroups.end()) {
for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
if ((*aGroupIter)->getId() == aGroupId) {
// If the group is empty, the feature is not added (the constraint only)
-//// if (!aConstraint && !(*aGroupIter)->isEmpty())
-//// return (*aGroupIter)->changeEntityFeature(theFeature) != SLVS_E_UNKNOWN;
+ if (!aConstraint && !(*aGroupIter)->isEmpty())
+ return (*aGroupIter)->updateFeature(theFeature);
return (*aGroupIter)->changeConstraint(aConstraint);
}
} else if (aGroups.size() > 1) { // Several groups applicable for this feature => need to merge them
if (aConstraint)
return (*aFirstGroupIter)->changeConstraint(aConstraint);
-//// return (*aFirstGroupIter)->changeEntityFeature(theFeature) != SLVS_E_UNKNOWN;
+ return (*aFirstGroupIter)->updateFeature(theFeature);
}
// Something goes wrong
for (; aGroupIt != myGroups.end(); aGroupIt++)
if (!(*aGroupIt)->isEmpty() && (*aGroupIt)->isInteract(theFeature))
(*aGroupIt)->moveFeature(theFeature);
-
-//// // Create list of attributes depending on type of the feature
-//// std::vector<std::string> anAttrList;
-//// const std::string& aFeatureKind = theFeature->getKind();
-//// // Point
-//// if (aFeatureKind.compare(SketchPlugin_Point::ID()) == 0)
-//// anAttrList.push_back(SketchPlugin_Point::COORD_ID());
-//// // Line
-//// else if (aFeatureKind.compare(SketchPlugin_Line::ID()) == 0) {
-//// anAttrList.push_back(SketchPlugin_Line::START_ID());
-//// anAttrList.push_back(SketchPlugin_Line::END_ID());
-//// }
-//// // Circle
-//// else if (aFeatureKind.compare(SketchPlugin_Circle::ID()) == 0) {
-//// anAttrList.push_back(SketchPlugin_Circle::CENTER_ID());
-//// anAttrList.push_back(SketchPlugin_Circle::RADIUS_ID());
-//// }
-//// // Arc
-//// else if (aFeatureKind.compare(SketchPlugin_Arc::ID()) == 0) {
-//// anAttrList.push_back(SketchPlugin_Arc::CENTER_ID());
-//// anAttrList.push_back(SketchPlugin_Arc::START_ID());
-//// anAttrList.push_back(SketchPlugin_Arc::END_ID());
-//// }
-//// /// \todo Other types of features should be implemented
-////
-//// // Check changing of feature's attributes (go through the groups and search usage of the attributes)
-//// std::vector<std::string>::const_iterator anAttrIter;
-//// for (anAttrIter = anAttrList.begin(); anAttrIter != anAttrList.end(); anAttrIter++) {
-//// std::vector<SketchSolver_Group*>::iterator aGroupIter;
-//// for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) {
-//// if ((*aGroupIter)->isEmpty())
-//// continue;
-//// std::shared_ptr<ModelAPI_Attribute> anAttribute = std::dynamic_pointer_cast<
-//// ModelAPI_Attribute>(theFeature->data()->attribute(*anAttrIter));
-//// (*aGroupIter)->updateEntityIfPossible(anAttribute);
-//// }
-//// }
-////
-//// std::vector<SketchSolver_Group*>::iterator aGroupIter;
-//// for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++)
-//// if (!(*aGroupIter)->isEmpty())
-//// (*aGroupIter)->updateRelatedConstraintsFeature(theFeature);
}
// ============================================================================
continue;
DataPtr aData = aWP->data();
- if (aData) {
+ if (aData->isValid()) {
std::shared_ptr<ModelAPI_AttributeRefList> aWPFeatures = std::dynamic_pointer_cast<
ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
std::list<ObjectPtr> aFeaturesList = aWPFeatures->list();
if (needToUpdate || theForceUpdate)
Events_Loop::loop()->flush(anUpdateEvent);
}
+