Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Tools.cpp
index fd1475aca007fa4337207f0003accc4b7143d286..710c6fd18d3a6ceedf4b9a5153fabec1b1f9fc5f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -37,6 +37,8 @@
 
 #include <SketcherPrs_Tools.h>
 
+#include <Locale_Convert.h>
+
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Tools.h>
@@ -63,17 +65,17 @@ namespace SketchPlugin_Tools {
 
 void clearExpressions(AttributeDoublePtr theAttribute)
 {
-  theAttribute->setText(std::string());
+  theAttribute->setText(std::wstring());
 }
 
 void clearExpressions(AttributePointPtr theAttribute)
 {
-  theAttribute->setText(std::string(), std::string(), std::string());
+  theAttribute->setText(std::wstring(), std::wstring(), std::wstring());
 }
 
 void clearExpressions(AttributePoint2DPtr theAttribute)
 {
-  theAttribute->setText(std::string(), std::string());
+  theAttribute->setText(std::wstring(), std::wstring());
 }
 
 void clearExpressions(AttributePtr theAttribute)
@@ -152,8 +154,8 @@ void findCoincidences(const FeaturePtr theStartCoin,
     std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
     for (; aCIt != aCoincidences.end(); ++aCIt) {
       FeaturePtr aConstrFeature = *aCIt;
-      std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(aConstrFeature);
-      if(aPnt.get() && aOrig->isEqual(aPnt)) {
+      std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = getCoincidencePoint(aConstrFeature);
+      if(aPnt2d.get() && aOrig->isEqual(aPnt2d)) {
         findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(),
                          theList, theIsAttrOnly);
         findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(),
@@ -229,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:
@@ -269,7 +284,7 @@ private:
         continue; // already processed
       theCoincidences.insert(*aCIt);
       // iterate on coincident attributes
-      for (int i = 0, aPtInd = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
+      for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
         AttributeRefAttrPtr aRefAttr = (*aCIt)->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
         if (!aRefAttr)
           continue;
@@ -342,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();
   }
 
@@ -350,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);
 }
 
 
@@ -528,7 +549,7 @@ void createAuxiliaryPointOnEllipse(const FeaturePtr& theEllipseFeature,
 
   aPointFeature->execute();
   std::wstring aName = theEllipseFeature->name() + L"_" +
-    ModelAPI_Tools::toWString(theEllipsePoint);
+    Locale::Convert::toWString(theEllipsePoint);
   aPointFeature->data()->setName(aName);
   aPointFeature->lastResult()->data()->setName(aName);
 
@@ -633,9 +654,9 @@ void replaceInName(ObjectPtr theObject, const std::wstring& theSource, const std
 {
   std::wstring aName = theObject->data()->name();
   size_t aPos = aName.find(theSource);
-  if (aPos != std::string::npos) {
+  if (aPos != std::wstring::npos) {
     std::wstring aNewName = aName.substr(0, aPos) + theDest
-                            + aName.substr(aPos + theSource.size());
+                          + aName.substr(aPos + theSource.size());
     theObject->data()->setName(aNewName);
   }
 }
@@ -830,9 +851,9 @@ void SketchPlugin_SegmentationTools::fillObjectShapes(
       // collect all intersection points with other edges for Trim operation only
       std::list<FeaturePtr> aFeatures;
       for (int i = 0; i < aSketch->numberOfSubs(); i++) {
-        FeaturePtr aFeature = aSketch->subFeature(i);
-        if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
-          aFeatures.push_back(aFeature);
+        FeaturePtr aSubFeature = aSketch->subFeature(i);
+        if (aSubFeature.get() && aSubFeature->getKind() != SketchPlugin_Projection::ID())
+          aFeatures.push_back(aSubFeature);
       }
       ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPoints);
     }