From ddc80873ea4e76738f4e0c8f85264af7e37b1cd8 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 25 Aug 2016 10:23:44 +0300 Subject: [PATCH] Issue #1664 In the Sketcher, add the function Split a segment - moving tangency constraint to nearest feature. Case: create line, arc(tangency) and point on the line. Start Split, select middle segment, Apply. Result: tangency is moved to the created line --- .../SketchPlugin_ConstraintSplit.cpp | 59 ++++++++++++++++++- .../SketchPlugin_ConstraintSplit.h | 10 +++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 6d9024796..bab340c85 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -118,7 +118,24 @@ void SketchPlugin_ConstraintSplit::execute() } } + if (!aTangentFeatures.empty()) { + std::cout << std::endl; + std::cout << "Tangencies to base feature[" << aTangentFeatures.size() << "]: " << std::endl; + std::map::const_iterator anIt = aTangentFeatures.begin(), + aLast = aTangentFeatures.end(); + for (int i = 1; anIt != aLast; anIt++, i++) { + FeaturePtr aFeature = (*anIt).first; + std::string anAttributeId = (*anIt).second.first; + std::shared_ptr aPointAttr = (*anIt).second.second; + + std::cout << i << "-" << getFeatureInfo(aFeature) << std::endl; + std::cout << " -Attribute to correct:" << anAttributeId << std::endl; + std::cout << " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl; + } + } + if (!aCoincidenceToPoint.empty()) { + std::cout << std::endl; std::cout << "Coincidences to points on base feature[" << aCoincidenceToPoint.size() << "]: " << std::endl; std::map::const_iterator anIt = aCoincidenceToPoint.begin(), aLast = aCoincidenceToPoint.end(); @@ -192,9 +209,8 @@ void SketchPlugin_ConstraintSplit::execute() // coincidence to points updateCoincidenceConstraintsToFeature(aCoincidenceToPoint, aFurtherCoincidences, std::set()); - // TODO // tangency - // TODO + updateTangentConstraintsToFeature(aTangentFeatures, aFurtherCoincidences); // delete constraints #ifdef DEBUG_SPLIT @@ -312,7 +328,7 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set& theFeatu if (aTangentPoint.get()) { FeaturePtr aFeature1 = ModelAPI_Feature::feature(aResult1); std::string anAttributeToBeModified = aFeature1 == aBaseFeature - ? SketchPlugin_Constraint::ENTITY_B() : SketchPlugin_Constraint::ENTITY_A(); + ? SketchPlugin_Constraint::ENTITY_A() : SketchPlugin_Constraint::ENTITY_B(); theTangentFeatures[aRefFeature] = std::make_pair(anAttributeToBeModified, aTangentPoint); } else @@ -432,6 +448,43 @@ void SketchPlugin_ConstraintSplit::updateCoincidenceConstraintsToFeature( } } +void SketchPlugin_ConstraintSplit::updateTangentConstraintsToFeature( + const std::map, IdToPointPair>& theTangentFeatures, + const std::set >& theFurtherCoincidences) +{ + if (theTangentFeatures.empty()) + return; + + std::map::const_iterator aTIt = theTangentFeatures.begin(), + aTLast = theTangentFeatures.end(); +#ifdef DEBUG_SPLIT + std::cout << std::endl; + std::cout << "Tangencies to feature(modified):"<< std::endl; +#endif + for (; aTIt != aTLast; aTIt++) { + FeaturePtr aTangentFeature = aTIt->first; + std::string anAttributeId = aTIt->second.first; + AttributePoint2DPtr aTangentPoint = aTIt->second.second; + std::set::const_iterator aFCIt = theFurtherCoincidences.begin(), + aFCLast = theFurtherCoincidences.end(); + std::shared_ptr aCoincPnt = aTangentPoint->pnt(); + AttributePoint2DPtr aFeaturePointAttribute; + /// here we rely on created coincidence between further coincidence point and tangent result + for (; aFCIt != aFCLast && !aFeaturePointAttribute.get(); aFCIt++) { + AttributePoint2DPtr aFCAttribute = *aFCIt; + if (aCoincPnt->isEqual(aFCAttribute->pnt())) + aFeaturePointAttribute = aFCAttribute; + } + if (aFeaturePointAttribute.get()) { + FeaturePtr aFeature = std::dynamic_pointer_cast(aFeaturePointAttribute->owner()); + aTangentFeature->refattr(anAttributeId)->setObject(getFeatureResult(aFeature)); + } +#ifdef DEBUG_SPLIT + std::cout << " -" << getFeatureInfo(aTangentFeature) << std::endl; +#endif + } +} + void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, FeaturePtr& theBaseFeatureModified, FeaturePtr& theAfterFeature, diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h index adbc3c81e..d06c7d548 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h @@ -107,13 +107,21 @@ private: std::map, IdToPointPair>& theCoincidenceToPoint); /// Move coincidence constraint from feature to point if it is found - /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature + /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature /// \param theFurtherCoincidences a list of points where coincidences will be build + /// \paramv theFeatureResults created results after split where constaint might be connected void updateCoincidenceConstraintsToFeature( const std::map, IdToPointPair>& theCoincidenceToFeature, const std::set >& theFurtherCoincidences, const std::set& theFeatureResults); + /// Move tangency constraint to the nearest split feature that has a coincidence to the tangent + /// \param theTangentFeatures tangencies to feature to be connected to nearest feature + /// \param theFurtherCoincidences a list of points where coincidences is built + void updateTangentConstraintsToFeature( + const std::map, IdToPointPair>& theTangentFeatures, + const std::set >& theFurtherCoincidences); + /// Make the base object is splitted by the point attributes /// \param theSplitFeature a result split feature /// \param theBeforeFeature a feature between start point and the 1st point of split feature -- 2.39.2