]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1664 In the Sketcher, add the function Split a segment - moving tangency const...
authornds <nds@opencascade.com>
Thu, 25 Aug 2016 07:23:44 +0000 (10:23 +0300)
committernds <nds@opencascade.com>
Thu, 25 Aug 2016 07:23:44 +0000 (10:23 +0300)
Case: create line, arc(tangency) and point on the line. Start Split, select middle segment, Apply. Result: tangency is moved to the created line

src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h

index 6d90247961b8b17cbab37e6dfa336266271ca9db..bab340c85013bae1d499eafdd761c3b20630000f 100755 (executable)
@@ -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<FeaturePtr, IdToPointPair>::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<GeomDataAPI_Point2D> 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<FeaturePtr, IdToPointPair>::const_iterator anIt = aCoincidenceToPoint.begin(),
                                                         aLast = aCoincidenceToPoint.end();
@@ -192,9 +209,8 @@ void SketchPlugin_ConstraintSplit::execute()
   // coincidence to points
   updateCoincidenceConstraintsToFeature(aCoincidenceToPoint, aFurtherCoincidences,
                                         std::set<ResultPtr>());
-  // TODO
   // tangency
-  // TODO
+  updateTangentConstraintsToFeature(aTangentFeatures, aFurtherCoincidences);
 
   // delete constraints
 #ifdef DEBUG_SPLIT
@@ -312,7 +328,7 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set<FeaturePtr>& 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<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
+      const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences)
+{
+  if (theTangentFeatures.empty())
+    return;
+
+  std::map<FeaturePtr, IdToPointPair>::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<AttributePoint2DPtr>::const_iterator aFCIt = theFurtherCoincidences.begin(),
+                                                  aFCLast = theFurtherCoincidences.end();
+    std::shared_ptr<GeomAPI_Pnt2d> 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<ModelAPI_Feature>(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,
index adbc3c81eb63ba91a89fd40283cf524f032919d6..d06c7d548a610a07fce5bd43bbb4928ca8869821 100755 (executable)
@@ -107,13 +107,21 @@ private:
               std::map<std::shared_ptr<ModelAPI_Feature>, 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<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
               const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
               const std::set<ResultPtr>& 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<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
+              const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& 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