]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task #3231: Sketcher Offset of a curve
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 30 Jun 2020 21:21:26 +0000 (00:21 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 30 Jun 2020 21:23:02 +0000 (00:23 +0300)
Improve searching of coincidences in context of B-spline curve

src/SketchPlugin/SketchPlugin_Offset.cpp
src/SketchPlugin/SketchPlugin_Tools.cpp
src/SketchPlugin/SketchPlugin_Tools.h

index f7f7b75e8b3ed805588ee61e35420f94e2de987e..2f01c4a8ccf409816a12e3142b83737d3aaa2c9d 100644 (file)
@@ -215,19 +215,12 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge,
   FeaturePtr aNextEdgeFeature;
   int nbFound = 0;
 
-  std::set<AttributePoint2DPtr> aCoincPoints;
-  std::map<AttributePoint2DArrayPtr, int> aCoincPointsInArray;
-  SketchPlugin_Tools::findPointsCoincidentToPoint(theEndPoint, aCoincPoints, aCoincPointsInArray);
-
-  // store all found attributes to a single array
-  std::set<AttributePtr> anAllCoincPoints;
-  anAllCoincPoints.insert(aCoincPoints.begin(), aCoincPoints.end());
-  for (auto it = aCoincPointsInArray.begin(); it != aCoincPointsInArray.end(); ++it)
-    anAllCoincPoints.insert(it->first);
-
-  std::set<AttributePtr>::iterator aPointsIt = anAllCoincPoints.begin();
-  for (; aPointsIt != anAllCoincPoints.end(); aPointsIt++) {
-    AttributePtr aP = (*aPointsIt);
+  std::set<AttributePoint2DPtr> aCoincPoints =
+      SketchPlugin_Tools::findPointsCoincidentToPoint(theEndPoint);
+
+  std::set<AttributePoint2DPtr>::iterator aPointsIt = aCoincPoints.begin();
+  for (; aPointsIt != aCoincPoints.end(); aPointsIt++) {
+    AttributePoint2DPtr aP = (*aPointsIt);
     FeaturePtr aCoincFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aP->owner());
     bool isInSet = (theEdgesSet.find(aCoincFeature) != theEdgesSet.end());
 
index b5db72f77fa7407bbf3b4fd2ab51fc594b36f292..15222805bc54fd20e79d246c6d66ec8dffce85f8 100644 (file)
@@ -231,26 +231,39 @@ public:
     }
   }
 
-  void coincidentPoints(const AttributePoint2DPtr& thePoint,
-                        std::set<AttributePoint2DPtr>& thePoints,
-                        std::map<AttributePoint2DArrayPtr, int>& thePointsInArray)
+  std::set<AttributePoint2DPtr> coincidentPoints(const AttributePoint2DPtr& thePoint)
   {
     collectCoincidentPoints(thePoint);
 
+    std::set<AttributePoint2DPtr> aCoincPoints;
     auto aFound = find(thePoint, THE_DEFAULT_INDEX);
     if (aFound != myCoincidentPoints.end()) {
       for (auto it = aFound->begin(); it != aFound->end(); ++it) {
         AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(it->first);
         if (aPoint)
-          thePoints.insert(aPoint);
+          aCoincPoints.insert(aPoint);
         else {
           AttributePoint2DArrayPtr aPointArray =
               std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(it->first);
-          if (aPointArray)
-            thePointsInArray[aPointArray] = *it->second.begin();
+          if (aPointArray) {
+            // this is a B-spline feature, the connection is possible
+            // to the first or the last point
+            FeaturePtr anOwner = ModelAPI_Feature::feature(aPointArray->owner());
+            if (it->second.find(0) != it->second.end()) {
+              AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                  anOwner->attribute(SketchPlugin_BSpline::START_ID()));
+              aCoincPoints.insert(aFirstPoint);
+            }
+            if (it->second.find(aPointArray->size() - 1) != it->second.end()) {
+              AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                  anOwner->attribute(SketchPlugin_BSpline::END_ID()));
+              aCoincPoints.insert(aFirstPoint);
+            }
+          }
         }
       }
     }
+    return aCoincPoints;
   }
 
 private:
@@ -344,6 +357,22 @@ private:
       if (aFound != aSeek->end() && aFound->second.find(theIndex) != aFound->second.end())
         return aSeek;
     }
+    // nothing is found, but if the point is a B-spline boundary point, lets check it as poles array
+    FeaturePtr anOwner = ModelAPI_Feature::feature(thePoint->owner());
+    if (anOwner->getKind() == SketchPlugin_BSpline::ID()) {
+      AttributePtr aPointsArray;
+      int anIndex = -1;
+      if (thePoint->id() == SketchPlugin_BSpline::START_ID()) {
+        aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID());
+        anIndex = 0;
+      }
+      else if (thePoint->id() == SketchPlugin_BSpline::END_ID()) {
+        aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID());
+        anIndex = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(aPointsArray)->size() - 1;
+      }
+      if (aPointsArray)
+        return find(aPointsArray, anIndex);
+    }
     return myCoincidentPoints.end();
   }
 
@@ -352,19 +381,9 @@ private:
 };
 
 std::set<AttributePoint2DPtr> findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint)
-{
-  std::set<AttributePoint2DPtr> aPoints;
-  std::map<AttributePoint2DArrayPtr, int> aPointsInArray;
-  findPointsCoincidentToPoint(thePoint, aPoints, aPointsInArray);
-  return aPoints;
-}
-
-void findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint,
-                                 std::set<AttributePoint2DPtr>& thePoints,
-                                 std::map<AttributePoint2DArrayPtr, int>& thePointsInArray)
 {
   CoincidentPoints aCoincidentPoints;
-  aCoincidentPoints.coincidentPoints(thePoint, thePoints, thePointsInArray);
+  return aCoincidentPoints.coincidentPoints(thePoint);
 }
 
 
index d7550bd0bb803c6ecf00c52347280b9bc8b84692..b87dee111410558598e8a93f3cfa2eb251ee63e9 100644 (file)
@@ -68,13 +68,6 @@ std::set<FeaturePtr> findFeaturesCoincidentToPoint(const AttributePoint2DPtr& th
 /// Find all points the given point is coincident to.
 std::set<AttributePoint2DPtr> findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint);
 
-/// Find all points the given point is coincident to.
-/// Returns GeomDataAPI_Point2D attribute and
-/// GeomDataAPI_Point2DArray with the index of coincident point.
-void findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint,
-                                 std::set<AttributePoint2DPtr>& thePoints,
-                                 std::map<AttributePoint2DArrayPtr, int>& thePointsInArray);
-
 void resetAttribute(SketchPlugin_Feature* theFeature, const std::string& theId);
 
 /// Create new constraint between given attributes