Salome HOME
Updated copyright comment
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
index 8f8a45342add6858992f4cf20ad8d0b20f0ca786..2f44c5081d1d22075f255fe22f4878e27000ed3c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ConstructionAPI_Point.h"
 
+#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Shape.h>
+#include <GeomAPI_Vertex.h>
 
+#include <ModelHighAPI_Double.h>
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
@@ -107,13 +109,46 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feat
 //==================================================================================================
 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                              const ModelHighAPI_Selection& theObject,
-                                             const bool theIsCircularEdge)
+                                             const bool theIsCircularEdge,
+                                             const bool theIsXYZSelection)
 : ModelHighAPI_Interface(theFeature)
 {
   if (initialize())
   {
     if (theIsCircularEdge) {
       setByCenterOfCircle(theObject);
+    } else if (theObject.shapeType() == "VERTEX" && theIsXYZSelection) {
+      // This is tricky way to get vertex shape.
+      fillAttribute(theObject, mypointToProject);
+      GeomShapePtr aShape = mypointToProject->value();
+      if (!aShape.get()) {
+        ResultPtr aContext = mypointToProject->context();
+        if (!aContext.get()) {
+          fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+          return;
+        }
+        aShape = aContext->shape();
+      }
+
+      if (!aShape.get()) {
+        fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+        return;
+      }
+
+      GeomVertexPtr aVertex = aShape->vertex();
+      if (!aVertex.get()) {
+        fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+        return;
+      }
+
+      GeomPointPtr aPnt = aVertex->point();
+      if (!aPnt.get()) {
+        fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+        return;
+      }
+
+      fillAttribute(ModelHighAPI_Selection(), mypointToProject);
+      setByXYZ(aPnt->x(), aPnt->y(), aPnt->z());
     } else {
       setByCenterOfGravity(theObject);
     }
@@ -131,11 +166,8 @@ void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
                                      const ModelHighAPI_Double& theY,
                                      const ModelHighAPI_Double& theZ)
 {
-  //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
-  fillAttribute(theX, myx);
-  fillAttribute(theY, myy);
-  fillAttribute(theZ, myz);
   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
+  fillAttribute(theX, theY, theZ, mypoint);
 
   execute(false);
 }
@@ -169,7 +201,7 @@ void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection&
                 mycreationMethod);
   fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(),
                 myprojectionType);
-  fillAttribute(theVertex, mypoinToProject);
+  fillAttribute(theVertex, mypointToProject);
   fillAttribute(theEdge, myedgeForPointProjection);
 
   execute();
@@ -183,7 +215,7 @@ void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection&
                 mycreationMethod);
   fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(),
                 myprojectionType);
-  fillAttribute(theVertex, mypoinToProject);
+  fillAttribute(theVertex, mypointToProject);
   fillAttribute(theFace, myfaceForPointProjection);
 
   execute();
@@ -238,6 +270,8 @@ void ConstructionAPI_Point::setByCenterOfGravity(const ModelHighAPI_Selection& t
   fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY(),
                 mygeometricalPropertyType);
   fillAttribute(theObject, myobjectForCenterOfGravity);
+
+  execute();
 }
 
 //==================================================================================================
@@ -248,6 +282,8 @@ void ConstructionAPI_Point::setByCenterOfCircle(const ModelHighAPI_Selection& th
   fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_CIRCLE(),
                 mygeometricalPropertyType);
   fillAttribute(theObject, myobjectForCenterOfCircle);
+
+  execute();
 }
 
 //==================================================================================================
@@ -262,7 +298,7 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
 
   if (aMeth == "" || // default is XYZ
       aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
-    theDumper << x() << ", " << y() << ", " << z();
+    theDumper << point();
   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) {
     const std::string anIntersectionType = intersectionType()->value();
     if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES())
@@ -292,7 +328,7 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
     }
     theDumper << ", " << reverse()->value();
   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) {
-    theDumper << poinToProject() << ", ";
+    theDumper << pointToProject() << ", ";
     if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) {
       theDumper << edgeForPointProjection();
     } else {
@@ -378,3 +414,11 @@ PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
   return PointPtr(new ConstructionAPI_Point(aFeature, theObject, theIsCircularEdge));
 }
+
+//==================================================================================================
+PointPtr addPointXYZ(const std::shared_ptr<ModelAPI_Document> & thePart,
+                     const ModelHighAPI_Selection& theObject)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
+  return PointPtr(new ConstructionAPI_Point(aFeature, theObject, false, true));
+}