From: azv Date: Tue, 4 Jun 2019 13:13:32 +0000 (+0300) Subject: Change behavior of the point-line distance constraint (in solver connector) X-Git-Tag: VEDF2019Lot4~114^2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e77c787fceea6450212f99bcf2028313ba72fd34;p=modules%2Fshaper.git Change behavior of the point-line distance constraint (in solver connector) --- diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 16527cefe..2f51ae2da 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -402,7 +402,8 @@ bool SketchPlugin_Sketch::removeLinksToExternal() aRemove.push_back(aFeature); } else { - AttributeSelectionPtr anExtAttr = aFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); + AttributeSelectionPtr anExtAttr = + aFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); ResultPtr anExternal = anExtAttr ? anExtAttr->context() : ResultPtr(); if (anExternal) { FeaturePtr anExtFeature = ModelAPI_Feature::feature(anExternal); @@ -421,6 +422,7 @@ bool SketchPlugin_Sketch::removeLinksToExternal() SketchPlugin_IntersectionPoint::INCLUDE_INTO_RESULT())->value(); } + aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID())->setValue(false); aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue( !isIncludedToSketchResult); } @@ -428,6 +430,6 @@ bool SketchPlugin_Sketch::removeLinksToExternal() } } for (std::list::iterator anIt = aRemove.begin(); anIt != aRemove.end(); ++anIt) - removeFeature(*anIt); + document()->removeFeature(*anIt); return true; } diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp index c3828b794..0850933a0 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp @@ -95,6 +95,8 @@ void SketchSolver_ConstraintDistance::getAttributes( theAttributes.clear(); myPrevValue = 0.0; + + myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateFeature::GROUP()); } void SketchSolver_ConstraintDistance::adjustConstraint() @@ -209,3 +211,15 @@ void SketchSolver_ConstraintDistance::removeConstraintsKeepingSign() myIsSigned = false; } + +void SketchSolver_ConstraintDistance::notify(const FeaturePtr& theFeature, + PlaneGCSSolver_Update*) +{ + if (getType() == CONSTRAINT_PT_LINE_DISTANCE && myIsSigned && + theFeature->getKind() == SketchPlugin_Sketch::ID()) { + // the sketch plane was updated, recalculate auxiliary constraints + removeConstraintsKeepingSign(); + addConstraintsToKeepSign(); + myIsSigned = true; // reset it, due to changing by removeConstraintsKeepingSign() + } +} diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.h b/src/SketchSolver/SketchSolver_ConstraintDistance.h index 7ea85d213..be316f89d 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.h +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.h @@ -42,6 +42,9 @@ public: /// \brief Remove constraint virtual bool remove(); + /// \brief Notify this object about the feature is changed somewhere + virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update*); + protected: /// \brief Generate list of attributes of constraint in order useful for constraints /// \param[out] theValue numerical characteristic of constraint (e.g. distance) diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 6e2e4ed6e..637719d26 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -73,14 +73,14 @@ static void sendMessage(const char* theMessageName, // ======================================================== SketchSolver_Group::SketchSolver_Group(const CompositeFeaturePtr& theWorkplane) - : mySketch(theWorkplane), - myPrevResult(PlaneGCSSolver_Solver::STATUS_UNKNOWN), + : myPrevResult(PlaneGCSSolver_Solver::STATUS_UNKNOWN), myDOF(-1), myIsEventsBlocked(false), myMultiConstraintUpdateStack(0) { mySketchSolver = SolverPtr(new PlaneGCSSolver_Solver); myStorage = StoragePtr(new PlaneGCSSolver_Storage(mySketchSolver)); + updateSketch(theWorkplane); } SketchSolver_Group::~SketchSolver_Group() @@ -123,6 +123,34 @@ bool SketchSolver_Group::changeConstraint( return true; } +bool SketchSolver_Group::updateSketch(CompositeFeaturePtr theSketch) +{ + static const double THE_TOLERANCE = 1.e-7; + bool isChanged = theSketch != mySketch; + + AttributePointPtr anOrigin = std::dynamic_pointer_cast( + theSketch->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + AttributeDirPtr aNorm = std::dynamic_pointer_cast( + theSketch->attribute(SketchPlugin_Sketch::NORM_ID())); + AttributeDirPtr aDirX = std::dynamic_pointer_cast( + theSketch->attribute(SketchPlugin_Sketch::DIRX_ID())); + + isChanged = isChanged + || (mySketchOrigin && anOrigin->pnt()->distance(mySketchOrigin) > THE_TOLERANCE) + || (mySketchNormal && aNorm->xyz()->distance(mySketchNormal->xyz()) > THE_TOLERANCE) + || (mySketchXDir && aDirX->xyz()->distance(mySketchXDir->xyz()) > THE_TOLERANCE); + + if (isChanged) { + mySketch = theSketch; + mySketchOrigin = anOrigin->pnt(); + mySketchNormal = aNorm->dir(); + mySketchXDir = aDirX->dir(); + + myStorage->notify(theSketch); + } + return true; +} + bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) { return myStorage->update(theFeature); diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 69ea919dc..ed938f5d0 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -30,6 +30,8 @@ #include #include +class GeomAPI_Dir; +class GeomAPI_Pnt; class GeomAPI_Pnt2d; typedef std::map ConstraintConstraintMap; @@ -67,6 +69,10 @@ class SketchSolver_Group */ bool changeConstraint(std::shared_ptr theConstraint); + /** \brief Updates the sketch feature + */ + bool updateSketch(CompositeFeaturePtr theSketch); + /** \brief Updates the data corresponding the specified feature * \param[in] theFeature the feature to be updated */ @@ -132,6 +138,10 @@ private: private: CompositeFeaturePtr mySketch; ///< Sketch for this group + std::shared_ptr mySketchOrigin; + std::shared_ptr mySketchNormal; + std::shared_ptr mySketchXDir; + ConstraintConstraintMap myConstraints; ///< List of constraints std::set myTempConstraints; ///< List of temporary constraints diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index f1347a622..b4c6765d5 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -58,7 +58,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,13 +68,21 @@ 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 { + std::shared_ptr aSketch = + std::dynamic_pointer_cast(*aFeatIter); + if (aSketch) + theSketch = aSketch; } } } @@ -151,17 +160,19 @@ 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 = @@ -228,6 +239,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 diff --git a/src/SketchSolver/SketchSolver_Manager.h b/src/SketchSolver/SketchSolver_Manager.h index c80f0fc7f..ce83c3d9b 100644 --- a/src/SketchSolver/SketchSolver_Manager.h +++ b/src/SketchSolver/SketchSolver_Manager.h @@ -29,6 +29,7 @@ class GeomAPI_Pnt2d; class GeomDataAPI_Point2D; +class ModelAPI_CompositeFeature; class SketchPlugin_Constraint; /** \class SketchSolver_Manager @@ -67,6 +68,12 @@ protected: */ bool updateFeature(const std::shared_ptr& theFeature); + /** \brief Updates the sketch and related constraints, if the sketch plane is changed + * \param[in] theSketch sketch to be updated + * \return \c true if the sketch plane is changed + */ + bool updateSketch(const std::shared_ptr& theSketch); + /** \brief Move feature * \param[in] theMovedFeature dragged sketch feature * \param[in] theFromPoint original position of the feature