X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Manager.cpp;h=8bebc53c4247037984ef7b9c14fb112e7c6903f4;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=f1347a622b1a2c799d1cea45fc284713ad17d856;hpb=97917d3698f5a2f7fc9596e7c755ff8f6751e373;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index f1347a622..8bebc53c4 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2024 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -58,7 +59,8 @@ static void featuresOrderedByCreation(const std::set& theOriginalFeat } static void featuresOrderedByType(const std::set& theOriginalFeatures, - IndexedFeatureMap& theOrderedFeatures) + IndexedFeatureMap& theOrderedFeatures, + CompositeFeaturePtr& theSketch) { int aFeatureIndex = 0; int aConstraintIndex = (int)theOriginalFeatures.size(); @@ -67,17 +69,38 @@ static void featuresOrderedByType(const std::set& theOriginalFeatures for (; aFeatIter != theOriginalFeatures.end(); aFeatIter++) { std::shared_ptr aFeature = std::dynamic_pointer_cast(*aFeatIter); - if (aFeature && !aFeature->isMacro() && aFeature->data() && aFeature->data()->isValid()) { - std::shared_ptr aConstraint = - std::dynamic_pointer_cast(aFeature); - if (aConstraint) - theOrderedFeatures[++aConstraintIndex] = aFeature; - else - theOrderedFeatures[++aFeatureIndex] = aFeature; + if (aFeature) { + if (!aFeature->isMacro() && aFeature->data() && aFeature->data()->isValid()) { + std::shared_ptr aConstraint = + std::dynamic_pointer_cast(aFeature); + if (aConstraint) + theOrderedFeatures[++aConstraintIndex] = aFeature; + else + theOrderedFeatures[++aFeatureIndex] = aFeature; + } + } + else { + CompositeFeaturePtr aSketch = + std::dynamic_pointer_cast(*aFeatIter); + if (aSketch && aSketch->getKind() == SketchPlugin_Sketch::ID()) + theSketch = aSketch; } } } +static void setPoint(AttributePtr theAttribute, + const int thePointIndex, + const std::shared_ptr theValue) +{ + AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast(theAttribute); + AttributePoint2DArrayPtr aPointArrayAttr = + std::dynamic_pointer_cast(theAttribute); + if (aPointAttr) + aPointAttr->setValue(theValue); + else if (aPointArrayAttr && thePointIndex >= 0) + aPointArrayAttr->setPnt(thePointIndex, theValue); +} + // ======================================================== @@ -105,6 +128,7 @@ SketchSolver_Manager::SketchSolver_Manager() ////Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); ////Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)); Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_PREPARED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_GET_DOF_OBJECTS)); } SketchSolver_Manager::~SketchSolver_Manager() @@ -151,25 +175,27 @@ void SketchSolver_Manager::processEvent( // update sketch features only const std::set& aFeatures = anUpdateMsg->objects(); IndexedFeatureMap anOrderedFeatures; + CompositeFeaturePtr aSketchFeature; // try to keep order as features were created if there are several created features: #2229 if (theMessage->eventID() == aCreatedEvent && aFeatures.size() > 1) { featuresOrderedByCreation(aFeatures, anOrderedFeatures); } else { // order is not important, just process features before constraints - featuresOrderedByType(aFeatures, anOrderedFeatures); + featuresOrderedByType(aFeatures, anOrderedFeatures, aSketchFeature); } IndexedFeatureMap::iterator aFeat; for (aFeat = anOrderedFeatures.begin(); aFeat != anOrderedFeatures.end(); aFeat++) { updateFeature(aFeat->second); } + updateSketch(aSketchFeature); } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) { std::shared_ptr aMoveMsg = std::dynamic_pointer_cast(theMessage); ObjectPtr aMovedObject = aMoveMsg->movedObject(); - std::shared_ptr aMovedPoint = - std::dynamic_pointer_cast(aMoveMsg->movedAttribute()); + AttributePtr aMovedAttribute = aMoveMsg->movedAttribute(); + int aMovedPoint = aMoveMsg->movedPointIndex(); const std::shared_ptr& aFrom = aMoveMsg->originalPosition(); const std::shared_ptr& aTo = aMoveMsg->currentPosition(); @@ -180,8 +206,8 @@ void SketchSolver_Manager::processEvent( std::dynamic_pointer_cast(aMovedFeature); if (aSketchFeature && !aSketchFeature->isMacro()) needToResolve = moveFeature(aSketchFeature, aFrom, aTo); - } else if (aMovedPoint) - needToResolve = moveAttribute(aMovedPoint, aFrom, aTo); + } else if (aMovedAttribute) + needToResolve = moveAttribute(aMovedAttribute, aMovedPoint, aFrom, aTo); } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aDeleteMsg = @@ -212,6 +238,35 @@ void SketchSolver_Manager::processEvent( } myIsComputed = false; } + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_GET_DOF_OBJECTS)) { + std::shared_ptr anUpdateMsg = + std::dynamic_pointer_cast(theMessage); + std::set aObjects = anUpdateMsg->objects(); + if (aObjects.size() == 1) { + std::set::const_iterator aIt; + for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) { + CompositeFeaturePtr aFeature = + std::dynamic_pointer_cast(*aIt); + if (aFeature) { + SketchGroupPtr aGroup = findGroup(aFeature); + + std::set aFreeFeatures; + aGroup->underconstrainedFeatures(aFreeFeatures); + + std::list aFeatures; + std::set::const_iterator aIt; + for (aIt = aFreeFeatures.cbegin(); aIt != aFreeFeatures.cend(); ++aIt) { + aFeatures.push_back(*aIt); + } + + // send features to GUI + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_DOF_OBJECTS); + ModelAPI_EventCreator::get()->sendUpdated(aFeatures, anEvent); + Events_Loop::loop()->flush(anEvent); + } + } + } + } // resolve constraints if needed bool needToUpdate = needToResolve && resolveConstraints(); @@ -228,6 +283,25 @@ void SketchSolver_Manager::processEvent( Events_Loop::loop()->flush(anUpdateEvent); } +// ============================================================================ +// Function: updateSketch +// Purpose: update sketch plane in appropriate group +// ============================================================================ +bool SketchSolver_Manager::updateSketch(const CompositeFeaturePtr& theSketch) +{ + if (!theSketch) + return true; + + bool isOk = true; + std::list::const_iterator aGroupIt; + for (aGroupIt = myGroups.begin(); aGroupIt != myGroups.end(); ++aGroupIt) + if ((*aGroupIt)->getWorkplane() == theSketch) { + (*aGroupIt)->updateSketch(theSketch); + break; + } + return isOk; +} + // ============================================================================ // Function: updateFeature // Purpose: create/update constraint or feature in appropriate group @@ -289,7 +363,8 @@ bool SketchSolver_Manager::moveFeature( // Purpose: move given attribute in appropriate group // ============================================================================ bool SketchSolver_Manager::moveAttribute( - const std::shared_ptr& theMovedAttribute, + const std::shared_ptr& theMovedAttribute, + const int theMovedPointIndex, const std::shared_ptr& theFrom, const std::shared_ptr& theTo) { @@ -298,7 +373,7 @@ bool SketchSolver_Manager::moveAttribute( std::dynamic_pointer_cast(anOwner); if (aConstraint) { - theMovedAttribute->setValue(theTo); + setPoint(theMovedAttribute, theMovedPointIndex, theTo); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); return true; } @@ -309,12 +384,12 @@ bool SketchSolver_Manager::moveAttribute( if (aSketchFeature) aGroup = findGroup(aSketchFeature); if (!aGroup) { - theMovedAttribute->setValue(theTo); + setPoint(theMovedAttribute, theMovedPointIndex, theTo); return false; } aGroup->blockEvents(true); - return aGroup->movePoint(theMovedAttribute, theFrom, theTo); + return aGroup->movePoint(theMovedAttribute, theMovedPointIndex, theFrom, theTo); } // ============================================================================ @@ -322,7 +397,7 @@ bool SketchSolver_Manager::moveAttribute( // Purpose: search groups of entities interacting with given feature // ============================================================================ SketchGroupPtr SketchSolver_Manager::findGroup( - std::shared_ptr theFeature) + std::shared_ptr theFeature) { if (!isFeatureValid(theFeature)) return SketchGroupPtr(); // do not process wrong features @@ -338,17 +413,21 @@ SketchGroupPtr SketchSolver_Manager::findGroup( break; } } + return findGroup(aSketch); +} - if (!aSketch) +SketchGroupPtr SketchSolver_Manager::findGroup(CompositeFeaturePtr theSketch) +{ + if (!theSketch) return SketchGroupPtr(); // not a sketch's feature std::list::const_iterator aGroupIt; for (aGroupIt = myGroups.begin(); aGroupIt != myGroups.end(); ++aGroupIt) - if ((*aGroupIt)->getWorkplane() == aSketch) + if ((*aGroupIt)->getWorkplane() == theSketch) return *aGroupIt; // group for the sketch does not created yet - SketchGroupPtr aNewGroup = SketchGroupPtr(new SketchSolver_Group(aSketch)); + SketchGroupPtr aNewGroup = SketchGroupPtr(new SketchSolver_Group(theSketch)); myGroups.push_back(aNewGroup); return aNewGroup; }