Salome HOME
Fix for import/export features
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.cpp
index 7b7fb78d0e1608a9afbbf4ab8c677feccadb3508..1b97f5634a0bd4a3c1db14989ac38030bc4f80cb 100644 (file)
@@ -228,8 +228,8 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
         aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
         std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
         // X axis is preferable to be dirX on the sketch
-        static const double tol = 1.e-7;
-        bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
+        static const double tol = 0.1; // here can not be very small value to avoid very close to X normal axis (issue 595)
+        bool isX = fabs(anA) - 1.0 < tol && fabs(aB) < tol && fabs(aC) < tol;
         std::shared_ptr<GeomAPI_Dir> aTempDir(
           isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
         std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
@@ -280,3 +280,17 @@ void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature,
 
   theFeature->setResult(aResult, theIndex);
 }
+
+FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeature,
+                                                            SketchPlugin_Sketch* theSketch)
+{
+  FeaturePtr aNewFeature = theSketch->addFeature(theFeature->getKind());
+  // addFeature generates a unique name for the feature, it caches the name
+  std::string aUniqueFeatureName = aNewFeature->data()->name();
+  // all attribute values are copied\pasted to the new feature, name is not an exception
+  theFeature->data()->copyTo(aNewFeature->data());
+  // as a name for the feature, the generated unique name is set
+  aNewFeature->data()->setName(aUniqueFeatureName);
+
+  return aNewFeature;
+}