Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Tools.cpp
index 874d05e8ef46e92ec58231e2e048102cca14220c..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
 
 #include <SketcherPrs_Tools.h>
 
+#include <Locale_Convert.h>
+
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Tools.h>
 
 #include <ModelGeomAlgo_Point2D.h>
 #include <ModelGeomAlgo_Shape.h>
@@ -62,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)
@@ -151,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(),
@@ -228,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:
@@ -260,14 +276,15 @@ private:
       std::set<FeaturePtr> aCoincToRes =
           SketchPlugin_Tools::findCoincidentConstraints(theFeature->lastResult());
       aCoincidences.insert(aCoincToRes.begin(), aCoincToRes.end());
-    }\r    std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
+    }
+    std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
     for (; aCIt != aCoincidences.end(); ++aCIt)
     {
       if (theCoincidences.find(*aCIt) != theCoincidences.end())
         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;
@@ -340,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();
   }
 
@@ -348,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);
 }
 
 
@@ -525,7 +548,8 @@ void createAuxiliaryPointOnEllipse(const FeaturePtr& theEllipseFeature,
   aCoord->setValue(anElPoint->x(), anElPoint->y());
 
   aPointFeature->execute();
-  std::string aName = theEllipseFeature->name() + "_" + theEllipsePoint;
+  std::wstring aName = theEllipseFeature->name() + L"_" +
+    Locale::Convert::toWString(theEllipsePoint);
   aPointFeature->data()->setName(aName);
   aPointFeature->lastResult()->data()->setName(aName);
 
@@ -558,8 +582,8 @@ void createAuxiliaryAxisOfEllipse(const FeaturePtr& theEllipseFeature,
   aLineEnd->setValue(aEndPoint->x(), aEndPoint->y());
 
   aLineFeature->execute();
-  std::string aName = theEllipseFeature->name() + "_" +
-    (theStartPoint == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? "major_axis" : "minor_axis");
+  std::wstring aName = theEllipseFeature->name() + L"_" +
+    (theStartPoint == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? L"major_axis" : L"minor_axis");
   aLineFeature->data()->setName(aName);
   aLineFeature->lastResult()->data()->setName(aName);
 
@@ -626,13 +650,13 @@ void setDimensionColor(const AISObjectPtr& theDimPrs)
     theDimPrs->setColor(aColor[0], aColor[1], aColor[2]);
 }
 
-void replaceInName(ObjectPtr theObject, const std::string& theSource, const std::string& theDest)
+void replaceInName(ObjectPtr theObject, const std::wstring& theSource, const std::wstring& theDest)
 {
-  std::string aName = theObject->data()->name();
+  std::wstring aName = theObject->data()->name();
   size_t aPos = aName.find(theSource);
-  if (aPos != std::string::npos) {
-    std::string aNewName = aName.substr(0, aPos) + theDest
-                         + aName.substr(aPos + theSource.size());
+  if (aPos != std::wstring::npos) {
+    std::wstring aNewName = aName.substr(0, aPos) + theDest
+                          + aName.substr(aPos + theSource.size());
     theObject->data()->setName(aNewName);
   }
 }
@@ -827,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);
     }