X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintManager.cpp;h=4034c0b7e0558355b0f2f976e6ea753d8b8aa13b;hb=d3883990177d27a12b8a2278cdbb82250ff19b79;hp=1e80079c96c2406ff039fb43bd82f1306ebdd3a2;hpb=bc06873747d5ea9bc0e8d6bd56641eebe33ac08d;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 1e80079c9..4034c0b7e 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -17,6 +17,9 @@ #include #include +#include +#include +#include #include #include @@ -79,6 +82,9 @@ void SketchSolver_ConstraintManager::processEvent( std::dynamic_pointer_cast(theMessage); std::set 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); if (isMovedEvt) { @@ -86,8 +92,10 @@ void SketchSolver_ConstraintManager::processEvent( for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { std::shared_ptr aSFeature = std::dynamic_pointer_cast(*aFeatIter); - if (aSFeature) + if (aSFeature) { moveEntity(aSFeature); + hasProperFeature = true; + } } } else { std::set::iterator aFeatIter; @@ -100,30 +108,39 @@ void SketchSolver_ConstraintManager::processEvent( if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) { std::shared_ptr aSketch = std::dynamic_pointer_cast< ModelAPI_CompositeFeature>(aFeature); - changeWorkplane(aSketch); + hasProperFeature = changeWorkplane(aSketch) || hasProperFeature; } } // then get anything but not the sketch - // at first, add coincidence constraints, because they may be used by other constraints + std::set aComplexConstraints; + // fillet and mirror an tangency constraints will be processed later for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { std::shared_ptr aFeature = std::dynamic_pointer_cast(*aFeatIter); - if (!aFeature || aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID()) + if (!aFeature) + continue; + if (aFeature->getKind() == SketchPlugin_ConstraintFillet::ID()) + continue; // skip Fillet features + if (SketchSolver_Group::isComplexConstraint(aFeature)) { + aComplexConstraints.insert(aFeature); continue; - changeConstraintOrEntity(aFeature); + } + hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature; } - // after that, add all features except coincidence - for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { + // processing remain constraints + aFeatIter = aComplexConstraints.begin(); + for (; aFeatIter != aComplexConstraints.end(); aFeatIter++) { std::shared_ptr aFeature = std::dynamic_pointer_cast(*aFeatIter); - if (!aFeature /*|| aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()*/) + 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 aDeleteMsg = std::dynamic_pointer_cast(theMessage); @@ -224,8 +241,8 @@ bool SketchSolver_ConstraintManager::changeConstraintOrEntity( 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 @@ -261,7 +278,7 @@ bool SketchSolver_ConstraintManager::changeConstraintOrEntity( if (aConstraint) return (*aFirstGroupIter)->changeConstraint(aConstraint); -//// return (*aFirstGroupIter)->changeEntityFeature(theFeature) != SLVS_E_UNKNOWN; + return (*aFirstGroupIter)->updateFeature(theFeature); } // Something goes wrong @@ -280,48 +297,6 @@ void SketchSolver_ConstraintManager::moveEntity( 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 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::const_iterator anAttrIter; -//// for (anAttrIter = anAttrList.begin(); anAttrIter != anAttrList.end(); anAttrIter++) { -//// std::vector::iterator aGroupIter; -//// for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) { -//// if ((*aGroupIter)->isEmpty()) -//// continue; -//// std::shared_ptr anAttribute = std::dynamic_pointer_cast< -//// ModelAPI_Attribute>(theFeature->data()->attribute(*anAttrIter)); -//// (*aGroupIter)->updateEntityIfPossible(anAttribute); -//// } -//// } -//// -//// std::vector::iterator aGroupIter; -//// for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) -//// if (!(*aGroupIter)->isEmpty()) -//// (*aGroupIter)->updateRelatedConstraintsFeature(theFeature); } // ============================================================================ @@ -368,7 +343,7 @@ std::shared_ptr SketchSolver_ConstraintManager continue; DataPtr aData = aWP->data(); - if (aData) { + if (aData->isValid()) { std::shared_ptr aWPFeatures = std::dynamic_pointer_cast< ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID())); std::list aFeaturesList = aWPFeatures->list();