#include <ModelAPI_Attribute.h>
#include <SketchPlugin_Constraint.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_ConstraintFillet.h>
-#include <SketchPlugin_ConstraintMirror.h>
-#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_Circle.h>
/// Global constraint manager object
SketchSolver_ConstraintManager* myManager = SketchSolver_ConstraintManager::Instance();
+
// ========================================================
// ========= SketchSolver_ConstraintManager ===============
// ========================================================
if (myIsComputed)
return;
if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)
- || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)
- || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) {
- std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
+ || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)
+ || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) {
+ std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
- std::set<ObjectPtr> aFeatures = anUpdateMsg->objects();
+ std::set<ObjectPtr> aFeatures = anUpdateMsg->objects();
- // Shows the message has at least one feature applicable for solver
- bool hasProperFeature = false;
+ // 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);
- if (isMovedEvt) {
- std::set<ObjectPtr>::iterator aFeatIter;
- for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
- std::shared_ptr<SketchPlugin_Feature> aSFeature =
+ bool isMovedEvt = theMessage->eventID()
+ == 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) {
- 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)
- 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);
- hasProperFeature = changeWorkplane(aSketch) || hasProperFeature;
- }
+ if (aSFeature) {
+ moveEntity(aSFeature);
+ hasProperFeature = true;
}
- // then get anything but not the sketch
- std::set<ObjectPtr> aComplexConstraints;
- // fillet and mirror an tangency constraints will be processed later
- for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
- std::shared_ptr<SketchPlugin_Feature> aFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
- if (!aFeature)
- continue;
- if (aFeature->getKind() == SketchPlugin_ConstraintFillet::ID())
- continue; // skip Fillet features
- if (SketchSolver_Group::isComplexConstraint(aFeature)) {
- aComplexConstraints.insert(aFeature);
- continue;
- }
- hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
+ }
+ } else {
+ 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;
}
- // processing remain constraints
- aFeatIter = aComplexConstraints.begin();
- for (; aFeatIter != aComplexConstraints.end(); aFeatIter++) {
- std::shared_ptr<SketchPlugin_Feature> aFeature =
+ std::shared_ptr<SketchPlugin_Feature> aFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
- if (!aFeature)
- continue;
- hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
- }
+ if (!aFeature)
+ continue;
+ hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
}
+ }
- // Solve the set of constraints
- if (hasProperFeature)
- resolveConstraints(isMovedEvt); // send update for movement in any case
+ // Solve the set of constraints
+ 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);
if (needToUpdate || theForceUpdate)
Events_Loop::loop()->flush(anUpdateEvent);
}
+